Validate OAuth 2 Access Token for Login

匿名 (未验证) 提交于 2019-12-03 09:14:57

问题:

Following this Browser Based OAuth when the request comes back to my site, https://oauth2client.com/cb#token=ACCESS_TOKEN, how do I validate that the access token is real to let them into the application?

Does the web application server do a request to the oauth2server to prove the user hasn't just faked an access token?

Using the System.IdentityModel.Services.WSFederationAuthenticationModule does it do a request to get the user Claims? I just need to know the Claims of the user are real, and don't need access resources from the OAuth server.

回答1:

The implicit grant OAuth flow is typically used by HTML5/JS Single Page Apps that make AJAX calls directly to WebAPIs, using the access token that they receive over the fragment.

The JavaScript app doesn't need to validate the token - the WebAPI that it calls must. The WebAPI (if written in .net) can use the JWT Token Handler, or the new OWIN framework (a sample is here: https://github.com/AzureADSamples/SinglePageApp-DotNet).

If your WebAPI technology doesn't have a JWT token handler available and you need to hand wiring the handling, make sure to validate:

  1. Audience of the token (the token has been issued for your API)
  2. Issuer of the token (the token has been issued by the trusted authority for the resource)
  3. Signature of the token (the token has indeed been signed by the issuer - validate using the public key of the token signing key published by the issuer)
  4. The token hasn't expired
  5. OAuth Scope (scp)
  6. then validate other claims that you base your authorization on


易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!