re: Developing token authentication using ASP.NET Core VIEW POST

VIEW PARENT COMMENT VIEW FULL DISCUSSION

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.

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!

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

Try This

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

code of conduct - report abuse