如何解决Microsoft Azure 云服务管理 API 失败并显示 401:未授权错误?
我们正在集成来自 Microsoft Azure 云管理 API 的 Role Assignments - List
API,文档链接:https://docs.microsoft.com/en-us/rest/api/authorization/roleassignments/list#errordetail
我们已经完成了所有提到的配置:
- 使用
App Registrations
选项向 Azure Active Directory 注册了用于 OAuth 的多租户 Web 应用, - 还在 Azure 服务管理下启用了
https://management.azure.com/user_impersonation
范围 - 网络应用请求相同的范围
到目前为止,OAuth 成功,但在用于调用 API GET https://management.azure.com/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/roleAssignments?api-version=2015-07-01
时收到的访问令牌失败并显示 401 Unauthorized 错误。在进行实际调用时,我已将 subscriptionId
替换为适当的值。
我使用 https://jwt.io/
查看了访问令牌的详细信息,scp
元素似乎只有 "scp": "User.Read"
范围,缺少 user_impersonation
。尽管来自 Microsoft 登录服务的 AUTH 对话框清楚地显示了请求的 user_impersonation
授权。我用于 OAuth 的用户帐户可以访问给定的 azure 订阅。
可能是什么问题?
解决方法
在请求访问令牌时添加 scope
和 https://management.azure.com/user_impersonation
很重要。
在浏览器中使用 implicit grant flow 进行测试:
https://login.microsoftonline.com/<tenant-id>/oauth2/v2.0/authorize?
client_id=<your-app-id>
&response_type=token
&redirect_uri=<your-redirect_uri>
&scope=https://management.azure.com/user_impersonation
&response_mode=fragment
&state=12345
&nonce=678910
注意:如果您使用 client credentials flow,请将 scope
更改为 https://management.azure.com/.default
。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。