gpt4 book ai didi

python - 使用 Python 进行 MSAL 身份验证显示未经授权的客户端?

转载 作者:行者123 更新时间:2023-12-02 14:48:02 27 4
gpt4 key购买 nike

我正在尝试对具有应用程序级权限的 Azure 应用程序进行身份验证。所有权限均已由管理员授予,并且应用程序具有客户端 ID 和客户端 key 。我正在根据 Microsoft graph 中的 Daemon-api 文档运行以下代码:

import msal

config = {
"authority": "https://login.microsoftonline.com/organizations",
"client_id": CLIENT_ID,
"scope": ["https://graph.microsoft.com/.default"],
"redirect_uri": REDIRECT_URI,
"client_secret": CLIENT_SECRET
}

app = msal.ConfidentialClientApplication(
config["client_id"], authority=config["authority"],
client_credential=config["client_secret"] )

result = app.acquire_token_silent(config["scope"], account=None)

import logging

if not result:
logging.info("No suitable token exists in cache. Let's get a new one from AAD.")
result = app.acquire_token_for_client(scopes=config["scope"])

如果我打印结果,它会显示以下内容:

{'error': 'unauthorized_client',
'error_description': "AADSTS700016: Application with identifier [IDENTIFIER] was not found in the directory 'microsoft.com'. This can happen if the application has not been installed by the administrator of the tenant or consented to by any user in the tenant. You may have sent your authentication request to the wrong tenant.\r\nTrace ID: [TRACE ID]\r\nCorrelation ID: [CORRELATION ID]\r\nTimestamp: 2019-08-28 17:14:39Z",
'error_codes': [700016],
'timestamp': '2019-08-28 17:14:39Z',
'trace_id': [TRACE ID],
'correlation_id': [CORRELATION ID],
'error_uri': 'https://login.microsoftonline.com/error?code=700016'}

该应用程序已经存在几天了,正如我所提到的,它的所有权限均已获得管理员授权。为什么我仍然收到“未经授权”的错误?我检查了我的 ID 和密码,它们是正确的。

我想知道这是否与错误消息显示它被发送到 microsoft.com 目录有关?但我提供的唯一微软信息是 API 表示需要的 authorityscope 。我没有看到任何地方可以提供目录 ID。这可能是问题所在吗?如果是这样,我该如何纠正?

最佳答案

配置中的权限字段应该是

https://login.microsoftonline.com/<directory_id>

关于python - 使用 Python 进行 MSAL 身份验证显示未经授权的客户端?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57697319/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com