是否可以通过客户端凭据流程获取 Azure 资源管理器 API 的刷新令牌?

问题描述 投票:0回答:1

我有一个长时间运行的 ADF 管道,它使用 management.azure.com 的令牌从 ADF API 查询数据。是否可以获得比正常访问令牌的+-1小时寿命长得多的刷新令牌?我在其他范围中看到过,您可以使用offline_access 来获取刷新令牌,但这对于management.azure.com 似乎无效。 目前,我正在使用以下请求正文向 https://login.microsoftonline.com/{TenantId}/oauth2/v2.0/token 发帖,并成功取回访问令牌。

grant_type=client_credentials

client_id=XXXXX

client_secret=XXXXX

scope=https://management.azure.com/.default

azure azure-resource-manager refresh-token
1个回答
0
投票

注意:由于不涉及用户交互,因此无法为客户端凭据流生成刷新令牌。请参阅 Shoaib Alam博客

相反,您可以尝试使用以下 Microsoft Graph API 查询来增加访问令牌生命周期

POST https://graph.microsoft.com/v1.0/policies/tokenLifetimePolicies
Content-type: application/json

{
    "definition": [
        "{\"TokenLifetimePolicy\":{\"Version\":1,\"AccessTokenLifetime\":\"23:59:59\"}}"
    ],
    "displayName": "Contoso token lifetime policy",
    "isOrganizationDefault": true
}

enter image description here

访问令牌现在的有效期为 24 小时:

https://login.microsoftonline.com/TenantID/oauth2/v2.0/token

client_id:ClientID
client_secret:ClientSecret
grant_type:client_credentials
scope:https://management.azure.com/.default

enter image description here

  • 您还可以将策略分配给 Microsoft Entra 应用程序。参考这个MsDoc
  • 访问令牌生命周期策略可设置为最短 5 分钟,最长 1,440 分钟(24 小时)。

参考资料:

使用 PowerShell 设置令牌的生命周期 - Microsoft 身份平台 |微软

创建 tokenLifetimePolicy - Microsoft Graph v1.0 |微软

© www.soinside.com 2019 - 2024. All rights reserved.