我有一个长时间运行的 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
注意:由于不涉及用户交互,因此无法为客户端凭据流生成刷新令牌。请参阅 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
}
访问令牌现在的有效期为 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
参考资料: