Difference between Authorization: Bearer <token> and Authorization: JWT <token>? - jwt

I've seen both Authorization: Bearer <token> and Authorization: JWT <token> when making HTTP requests using the Authorization header. What is the difference between Bearer and JWT?

As far as I know, there isn't really much of a difference between the two, or any other schema you might come across being used in the header.
Authorization: Bearer <token> is just a standard way of passing around JWT tokens between the client and the server.
if you've written server-side code, you'll notice that you're the one placing the logic to split and extract the token from the header.
So, if you're designing both the server and the client, you can send in any key-value pair you wish to, just that they should match both sides.
You can see JWT docs for more information. They mention using the Bearer schema as a standard way.

Related

How to make an axios request with JWT?

Hello I'm trying to figure out how to use JWT and axios. I was wondering if you could explain me what's the point to add "bearer" and if I should use "Authorization" or "x-access-token" name please ?
Axios.get(`http://localhost:3001/posts`, {
headers: { 'Authorization': `bearer ${token}` }
}).then((response) => {
console.log(response)
});
If I need to explain JWT Token in pretty simple words then I'll say something like this:
Access tokens are used in token-based authentication to allow access to an API. Access tokens are received after users successfully authenticate and authorize themselves.
And about the Authorization Token:
To set the authorization header, call it like this:
headers: { 'Authorization': `bearer ${token}`
Now the bearer token basically refers to the token type which in this case is a bearer type, read more here
The abstract of the provided link is something like this:
This specification describes how to use bearer tokens in HTTP
requests to access OAuth 2.0 protected resources. Any party in
possession of a bearer token (a "bearer") can use it to get access to
the associated resources (without demonstrating possession of a
cryptographic key). To prevent misuse, bearer tokens need to be
protected from disclosure in storage and in transport.
Now let's get to the Authorization vs x-access-token
Authorization:
The HTTP Authorization request header contains the credentials to authenticate a user agent with a server, usually, but not necessarily, after the server has responded with a 401 Unauthorized status and the WWW-Authenticate header.
Read more about Authorization here
X-Access-Token:
In case of 'x-auth-token' user has to supply username/password for the first time and server returns a access-token in header field 'x-auth-token'. For further sessions this token is exchanged, not the username/password.
Now the conclusion. You'll use whatever your project really requires example if your working on an application which has a lot of users might use you'll have to implement as much security as possible which means using JWT Token and other security steps.
On the other hand if your application only requires one admin login to input some data and you have a pretty small window then you might want to go with session based login.

Pass jwt refresh token on header or body

When access token is expired, it should re-issued refresh token.
At this point, I'm little hesitate which method is better.
For access token, it passed HTTP header per every request.
pass refresh token on HTTP header.
pass refresh token on HTTP POST body(payload).
Which one is recommended?
The jwt specification recommends (but does not require) sending the access tokens in an authorization header of type Bearer. But there is no mention of the refresh tokens.
Refresh tokens are an Oauth2 concept. If you read the Rfc6749 specification, to refresh an access token, the refresh token is sent using a form parameter in a POST request
6. Refreshing an Access Token
...
POST /token HTTP/1.1
Host: server.example.com
Authorization: Basic czZCaGRSa3F0MzpnWDFmQmF0M2JW
Content-Type: application/x-www-form-urlencoded
grant_type=refresh_token&refresh_token=tGzv3JOkF0XG5Qx2TlKWIA
You can use the example of oauth2 as reference (pass it in the body), although if you do not use oauth2, you have no obligation, so use the method to send that best suits your project.

Using Paw app with JWT

I have an API that I've built that uses JWT for authorization. How would I go about generating an appropriate JWT using Paw? I could just write a simple app to take in all my info and spit out a JWT, but I would rather be able to put the info in Paw somehow and have it generate the JWT and send it to the API.
The answer to this was staring me in the face since Paw is so powerful. I just used a dynamic value of my login call that produces the JWT. Now my JWT gets included in my headers automatically. More info can be found here: https://luckymarmot.com/paw/doc/Response_Parsed_Body_Dynamic_Value
You can add an header name Authorization and add the OAuth 2 Autorization in header value.
Then you need put your token at Token - Bearer field. (The selected field in the image bellow.)
Here's the solution that worked for me:
Creating an Authorization header and adding the string Bearer (with a space) before the token as follows:
Authorization: Bearer [YOUR_TOKEN]
P.S: There's a space between Bearer and your token.

how to form this REST request as a header, basic auth

This is how I would do this http request with curl
curl -v --basic --user USERNAME:PASSWORD
how would I set this as a header in a different REST client?
I can create curl commands in php, but in other GUI based rest clients I am unsure what part of the rest call "basic authentication" really falls in, is it in the body? in a header structured a certain way? thanks for the insight
Basic authentication in HTTP is achieved by setting the Authorization header equal to Basic token where the token is equal the base64 of username:password. Follow the link for more details.

Is there a standard for using SAML tokens with RESTful services?

I'm using SAML tokens to authenticate against a set of REST-ful services, by putting the SAML token in the Authorization header.
I can't find anything out there that would suggest that there's a standard way to do this. For example, do I use:
Authorization: Bearer <EncryptedAssertion ...
or:
Authorization: Bearer PEVuY3J5cHRlZEFzc2VydGlvbiAuLi4=
or:
Authorization: SAML PEVuY3J5cHRlZEFzc2VydGlvbiAuLi4=
or something else?
Note that the first one doesn't work if the certificate has multiple name components (because the comma messes up the header parsing).
The fact that I'm using 'Bearer' doesn't say anything about the format of the token.
Apache CXF appears to use the third variant.
Which one is standard? Is there a standard? If not, is there a de-facto standard?
The standard for custom auth schemes in HTTP is defined in the RFCs 2617 and 7235.
Authorization: scheme key="value", ...
I doubt there is a standard for your specific case, but I'd say this is acceptable:
Authorization: SAML bearer="PEVuY3J5cHRlZEFzc2VydGlvbiAuLi4="
After doing quite a lot of research on this topic, I could not find any standard defining how to use a SAML Token in the Authorization header.
However CXF which is a quite famous Web-Serviec stack supports SAML Token in the following manner:
Authorization: SAML eJydV1m....9fYTCPr=
OAuth2 also defines how to authenticate with SAML Token to receive a OAuth2 Access Token which can then be used to invoke another REST Service (https://www.rfc-editor.org/rfc/rfc7522)
POST /token.oauth2 HTTP/1.1
Host: as.example.com
Content-Type: application/x-www-form-urlencoded
grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Asaml2-bearer&
assertion=PHNhbWxwOl...[omitted for brevity]...ZT4