将用户添加到Azuread中的组中,作为小组所有者



是否有azuread的API,允许组所有者将用户添加到自己的组?

使用图形API的外观需要管理员同意(授予管理员权限(,因此比用户拥有的组提供了更多的访问权限。我不想授予这个。

我也不想使用委派访问 - 管理员不需要出席团体所有者(也许是服务校长?(将用户添加到自己的小组中?

我有一些有趣的发现。

a(如果您将服务主体设置为组的所有者,并希望使用服务主体管理组,则必须添加并授予Azure Ad Graph API的必要许可。

b(如果将用户设置为组的所有者,则可以使用公共客户端(1B730954-1685-4B74-9BFD-DAC224A7B894(和用户凭证获取令牌,然后将AAD Graph API称为AAD Graph API用户管理组。

在这里,我使用PowerShell提出HTTP请求。您可以使用其他程序语言。

# Get token for Azure AD Graph  
$uri = "https://login.microsoftonline.com/{tenant_name_or_id, for example: hanxia.onmicrosoft.com}/oauth2/token"
$body = @{grant_type='password';resource='https://graph.windows.net';client_id='1b730954-1685-4b74-9bfd-dac224a7b894';username='normaluser@hanxia.onmicrosoft.com';password='a*******7'}
$result = Invoke-RestMethod -Method Post -Uri $uri -Body $body
$accessToken = $result.access_token
# Azure AD Graph. Get group information
$tenantId = "e4c9ab4e-bd27-40d5-8459-230ba2a757fb"
$groupId = "f37d06f2-e26f-45f9-b9b1-da13d0b79ea7"
$apiVersion = "1.6"
$result = Invoke-WebRequest -Method Get `
                    -Uri ("https://graph.windows.net/" + $tenantId + "/groups/" + $groupId +"?api-version=" + $apiVersion) `
                    -Headers @{ "Authorization" = "Bearer " + $accessToken }
$result.Content | ConvertFrom-Json | ConvertTo-Json
# Azure AD Graph. Get users in group
$result = Invoke-WebRequest -Method Get `
                    -Uri ("https://graph.windows.net/" + $tenantId + "/groups/" + $groupId +"/`$links/members" +"?api-version=" + $apiVersion) `
                    -Headers @{ "Authorization" = "Bearer " + $accessToken }
$result.Content | ConvertFrom-Json | ConvertTo-Json
# Azure AD Graph. Add user to group
$userObject = @{"url" = "https://graph.windows.net/e4c9ab4e-bd27-40d5-8459-230ba2a757fb/directoryObjects/3f43b292-adac-48f9-a623-ee76ca9c7174"} | ConvertTo-Json
$result = Invoke-WebRequest -Method Post `
                            -Uri ("https://graph.windows.net/" + $tenantId + "/groups/" + $groupId +"/`$links/members" +"?api-version=" + $apiVersion) `
                            -Headers @{ "Authorization" = "Bearer " + $accessToken; "Content-Type" = "application/json" } `
                            -Body $userObject
if($result.StatusCode -eq 204){ Write-Host "User added" }

注意:

  1. 1B730954-1685-4B74-9BFD-DAC224A7B894 是Microsoft的常见应用程序。

  2. API参考:组对|AAD图API参考

需要同意的原因是,尽管组所有者有权将用户添加到组中,但默认情况下没有应用程序。授权的权限赋予了代表用户修改组的应用程序权利,具体取决于用户的权利。通常是更好的方法。应用程序权限允许应用程序本身在没有用户的情况下采取行动。通常太多了,但是有用例。

您至少需要授予该应用程序的委派权限,以便它可以代表用户进行修改。

相关内容

最新更新