首页 > 解决方案 > 如何通过 Graph API 将服务主体作为所有者添加到 Azure AD 组

问题描述

我的要求是在 Azure AD 中创建一个组,并通过 Graph API 添加一个服务主体作为该组的所有者 - 创建组时。

参考文档: https ://docs.microsoft.com/en-us/graph/api/group-post-groups?view=graph-rest-1.0&tabs=http

参考上述文档,我可以创建组,但显示的响应对象不允许将服务主体添加为所有者。

身体 :

{ "description": "测试 123", "displayName": "SG-test-ei",

“mailEnabled”:假,“mailNickname”:“SGP-test-ei”,“securityEnabled”:真,“owners@odata.bind”:[

    "https://graph.microsoft.com/v1.0/users/qwbhty-cdd0-4c42-b857-5b8ce0ae6a9e"
],
"members@odata.bind": [
    "https://graph.microsoft.com/v1.0/users/7f3f587a-c40a-4a63-82b1-202f35c828ee"
]

}

似乎,https: //graph.microsoft.com/v1.0/users 无法识别服务主体的 ObjectID。

我的问题是,我应该在正文中使用哪些 owner@odata.bind 或 API 将服务主体作为所有者添加到 Azure AD 中的安全组。

标签: azure-active-directorymicrosoft-graph-apiazure-ad-graph-api

解决方案


链接中的示例使用/users.

POST https://graph.microsoft.com/v1.0/groups
Content-Type: application/json

{
  "description": "Group with designated owner and members",
  "displayName": "Operations group",
  "groupTypes": [
    "Unified"
  ],
  "mailEnabled": true,
  "mailNickname": "operations2019",
  "securityEnabled": false,
  "owners@odata.bind": [
    "https://graph.microsoft.com/v1.0/users/26be1845-4119-4801-a799-aea79d09f1a2"
  ],
  "members@odata.bind": [
    "https://graph.microsoft.com/v1.0/users/ff7cb387-6688-423c-8188-3da9532a73cc",
    "https://graph.microsoft.com/v1.0/users/69456242-0067-49d3-ba96-9de6f2728e14"
  ]
}   

将其替换为/servicePrincipals如下所示:

"owners@odata.bind": [
    "https://graph.microsoft.com/v1.0/servicePrincipals/00964c82-a7c2-4675-bbed-54bcf16328b3"
  ]    

推荐阅读