为什么 Azure REST API 不能为订阅分配用户角色?

时间:2021-02-16 07:05:56

标签: azure rest azure-resource-manager azure-rest-api

我正在尝试按照此 documentation 使用 REST API 将用户角色添加到 Azure 中的订阅。

  1. 我通过登录获得了一个不记名令牌,并将其作为标头授权参数传递。
  2. 提供文档中描述的所有值
  3. 我执行的 PFA REST API 调用。

API 响应如下;

{
"error": {
    "code": "AuthenticationFailed",
    "message": "Authentication failed."
}

}

请让我知道是否有人成功使用了此 API 并执行了操作。此操作是否还有 Azure .NET API?

REST API Postman request

1 个答案:

答案 0 :(得分:0)

该错误表示您的用户帐户没有创建角色分配的权限,特别是 Microsoft.Authorization/roleAssignments/write

要解决此问题,您需要询问您订阅的 OwnerUser Access Administrator(或具有 Microsoft.Authorization/roleAssignments/write 权限的 custom RBAC role)的管理员分配 { {1}} 或 Owner 或具有上述权限的自定义角色首先在订阅范围内为您提供,按照此link,然后获取新令牌,您将能够将该角色分配给其他人,例如管理员为您分配角色,即创建角色分配。

更新:

如果您想通过用户凭据获取访问令牌,可以使用 auth code flow,请按照以下步骤操作。

1.在您的应用注册中,添加 User Access Administrator API 的 user_impersonation 委托权限。

enter image description here

2.在浏览器中点击下面的网址,将Azure Service Managementtenant-idclient-id更改为您的,登录您的用户帐户。

redirect_uri

然后你会得到一个类似下面的代码,复制它。

enter image description here

不要忘记删除 state 和 session_state。

enter image description here

3.在邮递员中,使用下面的查询,就可以得到token了。

enter image description here