【发布时间】:2021-04-13 10:35:53
【问题描述】:
我想使用 MSAL 对 Azure 进行身份验证,我指定如下:
app = msal.ConfidentialClientApplication(
client_id=client_id,
client_credential=client_secret,
authority='https://login.microsoftonline.com/' + tenantname
)
result = app.acquire_token_for_client(scopes=scopes)
它失败了,因为它找不到我有权访问的公司租户名称,即使它已正确指定。
Error description was: AADSTS700016: Application with identifier '12341234123somethingtest-fje2434823412341234123somethingtest-4322134-213413212341234123somethingtest' was not found in the directory '213412312341234123somethingtest-1234-3241'. 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. Exception: Failed to obtain access token
我也尝试了 AAD 中的租户名称和租户 ID,但总是遇到相同的错误。 有没有办法解决这个问题? (当我在自己的 Azure 上使用该代码时,它运行良好。)
【问题讨论】:
-
您是否检查过
client_id指定的应用程序在您运行代码的租户中是否可用? -
@GauravMantri 注册的服务主体与 AAD 租户 ID 具有相同的(目录)租户 ID,因此它应该可用?
-
尝试为应用程序授予管理员同意:
https://login.microsoftonline.com/{tenant-id}/adminconsent?client_id={client-id},在浏览器中运行url并使用管理员帐户登录并同意。 -
我的 client_id 有问题(缺少最后一个字符),而 adminconsent URL 对调试有很大帮助。幼儿园误区。非常感谢您的帮助。固定。
-
太棒了!我将在答案中总结我们的讨论,以便它可以帮助更多的人,您可以将其标记为答案。谢谢!
标签: azure azure-active-directory