简体   繁体   中英

How do we validate the access token from azure AD in backend?

I have a accesToken from azure AD. I need to validate them in python. How can I do that?

One of the workaround is to use PyJWT and cryptography dependancies (Because it contains binary dependencies, it must be created and packaged for the target operating system) to support the RS256 algorithm.

pip install pyjwt cryptography requests
  • The public key of the key pair used to sign the token is required to validate it.
  • We'll also require the App ID you supplied in the Azure portal for further validation.

Then use the App ID to validate the token.

import jwt

app_id = 'd31a4d20-6c4a-1a40-b74d-1a3d461bb3d8'
access_token = 'XXXX'
token_header = jwt.get_unverified_header(access_token)

For more information you can refer

REFERENCES:

  1. AAD OAuth2 JWT Token Validation with Python
  2. How to verify JWT id_token produced by MS Azure AD?

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