【问题标题】:How to create AD nested groups using GraphServiceClient c#?如何使用 GraphServiceClient c# 创建 AD 嵌套组?
【发布时间】:2021-03-19 23:09:02
【问题描述】:

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

【问题讨论】:

  • 希望对您有所帮助。 stackoverflow.com/questions/28200071/…@凯树
  • @Anshu 这意味着我们可以创建 A 的嵌套组 B 和 C 成员。但是仍然不清楚我们如何在创建 B 和 C 时引用/链接它们

标签: azure-active-directory microsoft-graph-api active-directory-group adgroup


【解决方案1】:

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

example 创建一个包含所有者和成员的安全组 指定的。请注意,最多 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);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-19
    • 2010-12-10
    • 1970-01-01
    • 1970-01-01
    • 2020-06-26
    • 2021-11-29
    相关资源
    最近更新 更多