gpt4 book ai didi

azure - Microsoft Azure OAuth 客户端凭据 token 获得 "AuthorizationFailed"响应

转载 作者:行者123 更新时间:2023-12-03 02:10:51 25 4
gpt4 key购买 nike

我想通过 REST API 创建 APIM 订阅,并且能够按照此 Microsoft 文档 https://learn.microsoft.com/en-us/rest/api/apimanagement/current-ga/subscription 成功完成此操作。 .

对于身份验证,我使用 ROPC 授予类型(我的用户名和密码)生成不记名 token 。按照此流程,一切正常。

但我不想在应用程序中配置我的用户名和密码来获取不记名 token ,而是遵循客户端凭据授予类型(通过客户端 ID 和 secret 获取 token ),我能够生成 token ,但是当我使用该 token 在 APIM 中创建订阅,我遇到异常客户端“0--e”,对象 ID 为“0” --e' 无权执行操作“Microsoft.ApiManagement/service/subscriptions/write”

是否可以在 APIM AccessControl(IAM) 中添加 AAD 应用程序来授予权限。或者这是任何其他方式来做到这一点?或者ROPC是唯一的方法?

有人可以帮忙吗?

最佳答案

Yes, you can grant permission to AAD application (service principal) in APIM Access Control (IAM) by assigning it API Management Service Contributor role.

我尝试在我的环境中重现相同的结果并得到以下结果:

我使用客户端凭据授予类型生成了一个访问 token ,如下所示:

enter image description here

当我使用上述 token 通过以下查询创建 APIM 订阅时,我收到了相同的错误:

PUT https://management.azure.com/subscriptions/subid/resourceGroups/rg1/providers/Microsoft.ApiManagement/service/apimService1/subscriptions/testsub?api-version=2021-12-01

{
"properties": {
"ownerId": "/subscriptions/subid/resourceGroups/rgname/providers/Microsoft.ApiManagement/service/servicename/users/xxxxxxxxxxx",
"scope": "/subscriptions/subid/resourceGroups/rgname/providers/Microsoft.ApiManagement/service/servicename/products/xxxxxxxxxxx",
"displayName": "testsub"
}
}

回应:

enter image description here

要解决该错误,您需要为该应用程序授予 API Management Service Contributor 角色,如下所示:

转到 Azure 门户 -> APIM 服务 -> 您的 APIM -> 访问控制 (IAM) -> 添加角色分配

enter image description here

授予上述角色后,我再次生成访问 token 并运行如下相同的查询:

PUT https://management.azure.com/subscriptions/subid/resourceGroups/rg1/providers/Microsoft.ApiManagement/service/apimService1/subscriptions/testsub?api-version=2021-12-01

回应:

enter image description here

当我检查门户时,APIM 订阅已成功创建,如下所示:

enter image description here

引用:

How to use Role-Based Access Control in Azure API Management | Microsoft Docs

关于azure - Microsoft Azure OAuth 客户端凭据 token 获得 "AuthorizationFailed"响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73426165/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com