Azure Active Directory获取令牌请求http

2024-06-16 10:29:23 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用的python的activedirectory身份验证库位于documentation之后。早些时候,我设法通过Acquire Token with Client Credentials sample获得accessΒu令牌:

import adal

RESOURCE_URI = 'https://<mydomain>.crm.dynamics.com'
AUTHORITY_URL = "https://login.microsoftonline.com/<tenant_id>"
CLIENT_ID = 'xxxx'  #application_id
CLIENT_SECRET = 'xxxx'

context = adal.AuthenticationContext(AUTHORITY_URL)
token = context.acquire_token_with_client_credentials(
    RESOURCE_URI,
    CLIENT_ID,
    CLIENT_SECRET)
print token

但我在尝试Acquire token and Refresh token sample时收到一条错误消息

^{pr2}$

Tags: samplehttpscomclienttokenidurlwith
2条回答

adal.adal_error.AdalError: Get Token request returned http error: 401 and server response: {"error":"invalid_client","error_description":"AADSTS70002: The request body must contain the following parameter: 'client_secret or client_assertion'.........."correlation_id"......}

我们可以在Azure上注册两种应用程序,原生应用程序或web应用程序。根据错误消息,您似乎注册了一个自信的应用程序,该应用程序需要提供其客户端机密以获取访问令牌。在

对于此问题,请注册本机应用程序而不是web应用程序。此外,应谨慎使用资源所有者密码凭据流,因为这可能会泄漏凭据。请参阅以下链接的流程:

The OAuth 2.0 Authorization Framework - Authorization Grant

我也犯了同样的错误。 在azureactivedirectory中的应用内注册部分,我将应用程序注册为web主机/api。 当我把它改成原生应用程序时,一切都开始正常工作了。在

相关问题 更多 >