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

re: 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 bu...

Errata corrige:

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

Authorization:Bearer <TOKEN>

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