首页 文章

Microsoft Graph API:403尝试检索租户上的策略时出现Forbidden错误

提问于
浏览
5

我正在尝试使用Microsoft Graph API检索在Azure AD门户上为我的租户创建的策略 . 据我从图API文档中了解,所有策略CRUD操作都需要Directory.AccessAsUser.All的范围 .

此范围转换为权限Access目录作为此处提到的已登录用户 - https://developer.microsoft.com/en-us/graph/docs/authorization/permission_scopes

我一直在尝试在新的Azure门户和具有不同故障点的旧门户上配置我的应用程序 .

On the new portal:

我按照https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-create-service-principal-portal上的说明在我的租户中创建了一个Web应用程序 .

配置访问控制时,我的租户的唯一订阅是访问Azure Active Directory,我无法在新门户中为此配置访问控制 . 从浏览器中,当我选择访问控制(IAM)时,我看到错误 - "Call to ARM failed with httpCode=BadRequest, errorCode=DisallowedOperation, message=The current subscription type is not permitted to perform operations on any provider namespace. Please use a different subscription., reason=Bad Request." "Add"角色按钮也被禁用 .

我是否可以在订阅Access Active Directory上配置Access控件?如果是这样,是否没有其他方法可以使用API检索我的租户的策略?

On the old portal:

对于我的应用,我配置了以下权限:

Microsoft Graph
Windows Azure Active Directory

我在门户网站上验证了两个API都使用权限Access目录配置为登录用户 . 即使在这种情况下,当我尝试访问https://graph.microsoft.com/beta/policies endpoints 以列出我的租户上的策略时,我仍然会收到403 Forbidden .

这是我获取的访问令牌上的有效负载(https://login.microsoftonline.com/ / oauth2 / token)

{
    "aud": "https://graph.microsoft.com",
    "iss": "https://sts.windows.net/8b49696d-462a-4a71-9c5c-f570b2222727/",
    "iat": 1491256764,
    "nbf": 1491256764,
    "exp": 1491260664,
    "aio": "Y2ZgYAi68q2XUTk0ykH7/TZzrhYbAA==",
    "app_displayname": "test-app",
    "appid": "951bb92d-5b68-45ae-bb8b-d768b2696ccc",
    "appidacr": "1",
    "idp": "https://sts.windows.net/8b49696d-462a-4a71-9c5c-f570b2222727/",
    "oid": "7ccea836-d389-4328-a155-67092e2805e9",
    "roles": [
        "Device.ReadWrite.All",
        "User.ReadWrite.All",
        "Directory.ReadWrite.All",
        "Group.ReadWrite.All",
        "IdentityRiskEvent.Read.All"
      ],
  "sub": "7ccea836-d389-4328-a155-67092e2805e9",
  "tid": "8b49696d-462a-4a71-9c5c-f570b2222727",
  "uti": "4fmUDNWWHkSoTn2-7gtTAA",
  "ver": "1.0"
}

显然,此令牌上缺少Directory.AccessAsUser.All角色,导致403错误 . 所以要么我在这里遗漏了一些东西,要么API中存在一个错误,即阻止正确配置所有权限 . 非常感谢任何帮助/指针!

请注意:

  • I 'm only using the beta APIs because I didn' t在v1.0 API上找到策略的相应 endpoints ,Azure Graph API文档建议使用Microsoft Graph API .

  • 使用相同的配置,使用Azure Graph API endpoints 还会为策略 endpoints 返回403 Forbidden错误(https://msdn.microsoft.com/zh-cn/library/azure/ad/graph/api/policy-operations #列表的策略)

1 回答

  • 6

    根据访问令牌中的声明,您使用 client credentials flow 获取访问令牌,该令牌用于委派应用程序 . 在这种令牌中没有用户的此类委托权限 .

    要获取用户的委派权限的访问令牌,您需要使用其他流程,如 Authorization code grant flow . 您可以参考此链接查看detail .

相关问题