简体   繁体   English

我们如何在后端验证来自 azure AD 的访问令牌?

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

I have a accesToken from azure AD.我有一个来自 azure AD 的 accesToken。 I need to validate them in python.我需要在 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.一种解决方法是使用 PyJWT 和加密依赖项(因为它包含二进制依赖项,所以必须为目标操作系统创建和打包)来支持 RS256 算法。

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.我们还需要您在 Azure 门户中提供的应用 ID 以进行进一步验证。

Then use the App ID to validate the token.然后使用 App ID 验证令牌。

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 使用 Python 进行 AAD OAuth2 JWT 令牌验证
  2. How to verify JWT id_token produced by MS Azure AD? 如何验证 MS Azure AD 生成的 JWT id_token?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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