I am currently developing a REST-API which is HTTP-Basic protected for the development environment. As the real authentication is done via a token, I'm still trying to figure out, how to send two authorization headers.
I have tried this one:
curl -i http://dev.myapp.com/api/users \
-H "Authorization: Basic Ym9zY236Ym9zY28=" \
-H "Authorization: Bearer mytoken123"
I could for example disable the HTTP-Authentication for my IP but as I usually work in different environments with dynamic IPs, this is not a good solution. So am I missing something?
Try this one to push basic authentication at url:
If above one doesn't work, then you have nothing to do with it. So try the following alternates.
You can pass the token under another name. Because you are handling the authorization from your Application. So you can easily use this flexibility for this special purpose.
Notice I have changed the header into
Application-Authorization
. So from your application catch the token under that header and process what you need to do.Another thing you can do is, to pass the
token
through thePOST
parameters and grab the parameter's value from the Server side. For example passing token with curl post parameter:I had a similar problem - authenticate device and user at device. I used a
Cookie
header alongside anAuthorization: Bearer...
header.If you are using a reverse proxy such as nginx in between, you could define a custom token, such as
X-API-Token
.In nginx you would rewrite it for the upstream proxy (your rest api) to be just auth:
... while nginx can use the original Authorization header to check HTTP AUth.
Standard (https://tools.ietf.org/html/rfc6750) says you can use:
So it's possible to pass many Bearer Token with URI, but doing this is discouraged (see section 5 in the standard).