简体   繁体   English

如何使用 GraphServiceClient c# 创建 AD 嵌套组?

[英]How to create AD nested groups using GraphServiceClient c#?

Is it possible to create nested groups in Azure AD using Graph API client as:是否可以使用 Graph API 客户端在 Azure AD 中创建嵌套组:

在此处输入图像描述

You could use AdditionalData to add members in the step of creating groups in C#.您可以在 C# 中创建组的步骤中使用AdditionalData添加成员。

The example creates a Security group with an owner and members specified.示例创建一个具有指定所有者和成员的安全组。 Note that a maximum of 20 relationships, such as owners and members, can be added as part of group creation.请注意,作为组创建的一部分,最多可以添加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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何设置GraphServiceClient的资源URL以获取组? - How to set resource URL for GraphServiceClient to fetch Groups? 如何使用自动化在 Azure AD 中创建安全组? - How to create security groups in Azure AD using Automation? 无法通过 AccessToken 和 ClientCredentialProvider 创建 GraphServiceClient 使用 Graph API(C# 控制台)发送 Email - Unable to send Email using Graph API (C# Console) by creating GraphServiceClient through AccessToken as well as ClientCredentialProvider 使用 GraphServiceClient 检索 Azure 广告成员的组信息 - Using GraphServiceClient to retrieve group info of Azure Ad members 使用C#以编程方式创建Azure AD用户 - programmatically create Azure AD user using C# 如何在 C# ASP.NET Core 6.0 中从 Azure AD 检索用户拥有的所有组? - How to retrieve all the groups that a user has from Azure AD in C# ASP.NET Core 6.0? Azure AD GraphServiceClient扩展不起作用 - Azure AD GraphServiceClient Extensions not working 如何使用C#以编程方式将Azure AD组添加到SharePoint - How to add Azure AD group to SharePoint programmatically using c# MIM将扩展AD嵌套组并与所有成员一起创建新的AD组 - MIM to Expand AD Nested Groups and Create new AD group with all members C#如何在使用Azure AD进行身份验证的WebApp中进行自动身份验证? - C# How to AutomaticAuthentication in WebApp, which is using Azure AD for authentication?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM