DEV Community

Discussion on: Developing token authentication using ASP.NET Core

rosscotini profile image

Also ran the api/token with the username and password all worked well I got the toekn in return which I appened to a HTTP get call to the server but the authorization fails

samueleresca profile image
Samuele Resca Author

Errata corrige:

You need to pass the token in the HEADER of the request:

Authorization:Bearer <TOKEN>
Enter fullscreen mode Exit fullscreen mode
gustavosg profile image
Gustavo Souza Gonçalves

When i pass the Authorization Bearer in header, it gives me this error:
The header name format is invalid.

This is how i'm passing it:

client.DefaultRequestHeaders.Add("Authorization:Bearer", json.accessToken);

where client is a HttpClient variable and json.accessToken is the value of the token.

Thread Thread
xgabba profile image
Daniel E.

Another approach..
If you download the tool Postman you can easily check how this works.
After you revieced your token, you just have to put into Header:
Key: Authorization
Value: Bearer YOUR_TOKEN
including the whitespace between Baerer and your token!

Thread Thread
forestmarie profile image
Forest Marie

I get nothing but 401s using this very approach in Postman.