【问题标题】:Access token for Azure Active Directory using azure-cli使用 azure-cli 访问 Azure Active Directory 的令牌
【发布时间】:2018-03-24 10:00:02
【问题描述】:

我在 Azure 应用服务上有一个需要 Azure Active Directory 身份验证的 Web 应用。我可以使用OAuth 2.0 flow for service-to-service communicationManaged Service Identity (MSI) 从其他应用程序中连接接收受保护应用程序的访问令牌。

对于 MSI,Microsoft 提供了一个库 Microsoft.Azure.Services.AppAuthentication 用于身份验证,该库还支持使用来自 azure-cli 工具的凭据。

但是,该库目前处于预览状态,它无法在我的系统上运行,但我设法找到了它的 source code on github

relevant part好像在打电话

$ az account get-access-token <resource>

但是,当我尝试使用我尝试访问的应用程序的资源名称时,我收到以下错误:

Get Token request returned http error: 400 and server response: {"error":"invalid_grant","error_description":"AADSTS65001: The user or administrator has not consented to use the application with ID <application id> named <application name>.

对于资源名称,我尝试了 App ID URI 和 Client ID。

有没有人设法在类似情况下使用azure-cli 获取访问令牌?

【问题讨论】:

标签: azure azure-active-directory


【解决方案1】:

该错误表明您需要同意该应用程序(CLI)访问该 API(范围/资源)。

执行此操作的最快方法是为 CLI 构建一个 URL 以供您同意 CLI 访问您的应用程序。 cli 应用程序 ID 为 04b07795-8ddb-461a-bbee-02f9e1bf7b46

类似的东西。

https://login.microsoftonline.com/<your-tenant-name-or-id>/oauth2/v2.0/authorize?response_type=code&client_id=04b07795-8ddb-461a-bbee-02f9e1bf7b46&scope=<the scope of the target app/api>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-02-17
    • 1970-01-01
    • 1970-01-01
    • 2020-05-25
    • 2020-09-26
    • 2019-08-25
    • 2017-10-12
    • 1970-01-01
    相关资源
    最近更新 更多