简体   繁体   中英

Access Protected Resource API gives “401 Unauthorized” error

I want to add authorization to my project based on this tutorial . I've got the part of retrieving an access token working. But when using the token to access a protected resource API I get a 401 unauthorized error.

The request has an authorization header with scheme Bearer and containing the access token. Like in the tutorial the API is protected with the [Authorize] attribute. During startup I setup Bearer Authentication with

UseOAuthBearerAuthentication(new Microsoft.Owin.Security.OAuth.OAuthBearerAuthenticationOptions())

It is not clear to me why the request is unauthorized. What can I check to find the cause of this problem?

After trying and checking many things, I noticed the authorization server and the resource server were using a different version of Owin and Owin.Security. After updating the older one, it worked. The tokens must have changed between the 2 versions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM