使用用户名和密码进行验证时如何获得ID令牌?

问题描述 投票:0回答:1

我正在使用Python ADAL库使用Azure Active Directory对用户进行身份验证。我成功收到访问令牌后身份验证。现在,我想验证访问令牌的有效性。在这种情况下,我需要ID_TOKEN。我如何获得?

import adal
auth_context = adal.AuthenticationContext("https://login.microsoftonline.com/{{tenant_id}}")
token_response = auth_context.acquire_token_with_username_password("https://management.core.windows.net/", username, password, client_id)        

在令牌响应中,我得到了access_token和refresh_token,但是没有收到id_token。遵循类似的问题,How to verify JWT id_token produced by MS Azure AD?我使用代码验证访问令牌,但我需要ID_TOKEN。

关于获得此功能的任何想法都会很棒。

python oauth oauth-2.0 azure-active-directory
1个回答
0
投票

不需要获​​取ID_TOKEN,请尝试如下代码。

import adal
import jwt

auth_context = adal.AuthenticationContext("https://login.microsoftonline.com/{{tenant_id}}")
token_response = auth_context.acquire_token_with_username_password("https://management.core.windows.net/", username, password, client_id)

token_header = jwt.get_unverified_header(token_response['accessToken'])

有关更多详细信息,您可以参考此相似的issue和此doc

© www.soinside.com 2019 - 2024. All rights reserved.