无法获取自定义 AD 应用程序的访问令牌

And*_*rst 4 powershell azure azure-active-directory azure-cli

尝试使用 获取自定义 AD 应用程序的访问令牌时az account get-access-token --resource '<APP ID Uri>',我收到以下错误:

AADSTS65001: The user or administrator has not consented to use the application with ID '04b07795-8ddb-461a-bbee-02f9e1bf7b46' named 'Microsoft Azure CLI'. Send an interactive authorization request for this user and resource.

04b07795-8ddb-461a-bbee-02f9e1bf7b46不是我的应用程序 ID,并且我的应用程序已获得管理员同意。我尝试将此 ID 放入交互式登录请求中,而行为没有改变。

get-access-token当资源是一个定义的 MS 端点时工作正常,如https://database.windows.nethttps://vault.azure.net/

我的目标是让带有托管服务标识的 Azure 应用服务使用短期 AD 不记名令牌相互进行身份验证。每个服务都有一个与 AD 应用程序对应的配置受众。

Bar*_*kan 6

az account get-access-token --resource '<APP ID Uri>'从本地 CLI运行,您尝试'<APP ID Uri>'使用 Azure CLI获取令牌,客户端 ID 正是04b07795-8ddb-461a-bbee-02f9e1bf7b46.

要处理此问题,您可以访问: Azure Active Directory ? 应用注册 ? {你的应用}?公开 API ? 添加客户端应用程序

身份证:04b07795-8ddb-461a-bbee-02f9e1bf7b46

授权范围:检查'<APP ID Uri>'

为了确保您拥有正确的 ID,您可以运行az account get-access-tokenpaste token 到jwt.io并找到"appid".


Joy*_*ang 1

--resource '<APP ID Uri>'如果我使用用户帐户登录 cli,我可以使用 a 重现您的问题。

在此输入图像描述

如果我使用服务主体登录,它就可以正常工作。

在此输入图像描述

您可以尝试使用服务主体登录azure cli,请参阅此链接