使用 Graph beta 版为企业应用程序创建新的角色分配

Create a new role assignment for an enterprise application using Graph beta version

我正在尝试使用 Graph api 测试版为企业应用程序创建角色分配。

我正在按照 Microsoft 文档做同样的事情

https://docs.microsoft.com/en-us/graph/api/serviceprincipal-post-approleassignments?view=graph-rest-beta&tabs=http

错误:

这是我在检查时遇到的错误:

Write requests are only supported on contained entities

我也使用 Azure AD Graph 进行了同样的尝试(graph.windows.net),我能够实现以下目标。

{
  "error": {
    "code": "BadRequest",
    "message": "Write requests are only supported on contained entities",
    "innerError": {
      "request-id": "f8b80735-c516-4a65-9f42-2b3088f2951a",
      "date": "2019-07-30T09:23:13"
    }
  }
}

我可以通过 Microsoft Graph API 重现您的问题,但不确定是什么原因导致的。 还有,是Beta版本,不建议你在生产环境中使用

Azure AD Graph API 适合我,您可以参考下面的请求示例。

注意id是目标资源申请resourceId在其appRoles属性中声明的角色id。我的示例应用程序未声明任何权限,因此我指定了一个默认 ID(零 GUID 00000000-0000-0000-0000-000000000000)。

POST https://graph.windows.net/myorganization/servicePrincipals/<objetc id of the service principal>/appRoleAssignments?api-version=1.6 

{
    "id":"00000000-0000-0000-0000-000000000000",
    "principalId":"<object id of the user/group/service principal being granted the access>",
    "resourceId":"<objetc id of the service principal which the assignment was made>"

}