AADSTS700016:使用 MSAL 对 Azure 进行身份验证时无法获取访问令牌

时间:2021-04-13 10:35:53

标签: azure azure-active-directory

我想使用 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 上使用该代码时,该代码运行良好。)

1 个答案:

答案 0 :(得分:1)

您的错误已解决。这是由于您的 client_id 中缺少字符造成的。您只需要输入正确的client_id

遇到类似问题,可以在浏览器中运行管理员同意url调试:

https://login.microsoftonline.com/{tenant-id}/adminconsent?client_id={client-id}