0

是否可以使用 Graph API 客户端在 Azure AD 中创建嵌套组:

在此处输入图像描述

4

1 回答 1

1

您可以AdditionalData在 C# 中创建组的步骤中使用添加成员。

示例创建一个具有指定所有者和成员的安全组。请注意,作为组创建的一部分,最多可以添加20 个关系,例如所有者和成员。

IConfidentialClientApplication confidentialClientApplication = ConfidentialClientApplicationBuilder
        .Create(clientId)
        .WithTenantId(tenantID)
        .WithClientSecret(clientSecret)
        .Build();

ClientCredentialProvider authProvider = new ClientCredentialProvider(confidentialClientApplication);
GraphServiceClient graphClient = new GraphServiceClient(authProvider);

// Create group B and add members(user-id1 and user-id2)
var additionalDataGroupB = new Dictionary<string, object>()
{
    {"members@odata.bind", new List<string>()}
};
(additionalData["members@odata.bind"] as List<string>).Add("https://graph.microsoft.com/v1.0/users/{id1}");
(additionalData["members@odata.bind"] as List<string>).Add("https://graph.microsoft.com/v1.0/users/{id2}");

var groupB = new Group
{
    Description = "Group B",
    DisplayName = "PamelaGroupB",
    GroupTypes = new List<String>()
    {
    },
    MailEnabled = false,
    MailNickname = "operations2019",
    SecurityEnabled = true,
    AdditionalData = additionalDataGroupB
};

Group groupBRequest = await graphClient.Groups.Request().AddAsync(groupB);
string groupB_id = groupBRequest.Id;

// Create group C
......
string groupC_id = groupCRequest.Id;


// Create group A and add members(groupB and groupC)
var additionalDataGroupA = new Dictionary<string, object>()
{
    {"members@odata.bind", new List<string>()}
};
(additionalData["members@odata.bind"] as List<string>).Add("https://graph.microsoft.com/v1.0/groups/" + groupB_id);
(additionalData["members@odata.bind"] as List<string>).Add("https://graph.microsoft.com/v1.0/groups/" + groupC_id);

var groupA = new Group
{
    Description = "Group A",
    DisplayName = "PamelaGroupA",
    GroupTypes = new List<String>()
    {
    },
    MailEnabled = false,
    MailNickname = "XXXXX",
    SecurityEnabled = true,
    AdditionalData = additionalDataGroupA
};

await graphClient.Groups.Request().AddAsync(groupA);
于 2020-12-09T07:05:13.090 回答