node.jsauthorizationbearer-tokenthunderclientauthorization-header

Error "Invalid token" when using Authorization header vs Bearer with same token


I am using Thunder Client for testing a JWT token.

After login, the token was generated successfully:

screenshot of thunder client with login request and response back with token

When putting this token into the Authorization header:

Headers:
Authorization: <generated token>

I got a 400 error message:

{
  "message": "Invalid token"
}

screenshot of thunder client with Authorization header in request and response with error

But when I instead use:

Auth:
Bearer:
Bearer Token: <generated token>

I successfully get a 200 response message

{
  "message": "I am a private route"
}

screenshot of thunder client with bearer token in request and response with a 200 OK

So what is the problem with the Authorization header vs Bearer token?


Solution

  • Because you are using bearer token. When using that, we have to prefix with the Bearer keyword in the Authorization header like below:

    screenshot of thunder client request with Authorization header with "Bearer {{token}}"

    That what automatically set when you use Auth->Bearer->Token