首页 > 解决方案 > 无法获取自定义 AD 应用程序的访问令牌

问题描述

尝试使用 获取自定义 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 应用程序的已配置受众。

标签: azurepowershellazure-active-directoryazure-cli

解决方案


从本地 CLI运行az account get-access-token --resource '<APP ID Uri>',您尝试'<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-token令牌粘贴到jwt.io并找到"appid".


推荐阅读