[英]Django doesn't validate or see the JWT token from Azure
I used azure-ad-verify-token 0.2.1 on Django-rest
backend to validate a jwt token
from Microsoft Azure
, where the user is authenticated on the frontend with React
.我在
Django-rest
后端使用azure-ad-verify-token 0.2.1来验证来自Microsoft Azure
的jwt token
,用户在前端使用React
进行身份验证。
According to the documentation, this library should do everything on its own.根据文档,这个库应该自己做所有事情。
from azure_ad_verify_token import verify_jwt
azure_ad_app_id = 'my app id'
azure_ad_issuer = 'https://exampletenant.b2clogin.com/0867afa-24e7-40e9-9d27-74bb598zzzzc/v2.0/'
azure_ad_jwks_uri = 'https://exampletenant.b2clogin.com/exampletenant.onmicrosoft.com/B2C_1_app_sign_in/discovery/v2.0/keys'
payload = verify_jwt(
token='<AZURE_JWT_TO_VERIFY_HERE>',
valid_audiences=[azure_ad_app_id],
issuer=azure_ad_issuer,
jwks_uri=azure_ad_jwks_uri,
verify=True,
)
print(payload)
I don't understand the line token='<AZURE_JWT_TO_VERIFY_HERE>'
, how can I put the token there?我不明白
token='<AZURE_JWT_TO_VERIFY_HERE>'
行,我怎样才能把令牌放在那里?
Authorization from Azure on React
is successful, and I get a access jwt-token
that I can extract: Azure 对
React
的授权成功,我获得了一个可以提取的access jwt-token
:
token = request.headers['Authorization']
But I need to validate it and somehow insert it into a string token='<AZURE_JWT_TO_VERIFY_HERE>'
, but it doesn't recognize the request
here.但我需要验证它并以某种方式将其插入到字符串
token='<AZURE_JWT_TO_VERIFY_HERE>'
中,但它无法识别此处的request
。
How can I put a token=
from the header
?如何从
header
中放置token=
?
And in general, is this the right way?总的来说,这是正确的方法吗? Or am I missing something?
还是我错过了什么? Any help and hints would be very helpful and would be greatly appreciated.
任何帮助和提示都会非常有帮助,将不胜感激。 Or advise another library for
token validation
in Python
.或者建议另一个库在
Python
中进行token validation
。
azure-ad-verify-token
This is used to verify the tokens received from azure ad. azure-ad-verify-token
这用于验证从 azure ad 收到的令牌。
You have to get auth tokens from azure using MSAL python library and the azure-ad-verify-token will then verify the token.您必须使用 MSAL python 库从 azure 获取身份验证令牌,然后 azure-ad-verify-token 将验证令牌。
To retrieve the tokens, you will need MSAL python library, and it will also take clientid
and tenentd
as arguments.要检索令牌,您将需要 MSAL python 库,它还将
clientid
和tenentd
作为参数。
test_app=PublicClientApplication(client_id=client_id,authority="https://login.microsoftonline.com/"+tenant_id)
test_tokens=test_app.acquire_token_interactive(scopes=scopes)
azure-ad-verify-token
.azure-ad-verify-token
中使用它。 token=test_tokens['access_token']
Reference:参考:
Authenticate Python apps by using the Azure SDK for Python 使用 Azure SDK for Python 对 Python 应用进行身份验证
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.