I have a frustrating problem with my API call (Asp.Net WebAPI and Angular). I use bearer token authorization to authorize the requests. When I make a request to the API from Postman it returns 200 Ok but when I try it from the browser (Angular) I get 401 Unauthorized.
I can get it working if I use [AllowAnonymous] attribute on top of the controller action but I'd like to keep the [Authorize] attribute for the security reasons.
I'm not sure what's causing this error. Here is the screenshot of the request headers from the browser. As you can see it includes the valid bearer token as well. The funny thing is that the Authorize attribute works for the other actions in my controller.
https://i.stack.imgur.com/K5OB1.png
Thank you in advance.
401basically means that the server is expecting an authorization field in the request header and is unable to see one or that the provided authorization details are incorrect. Verify on Postman if there is any authorization field that's being sent along with the request and accordingly correct it for the browser. - Sai Gummaluri