如何使用GO SDK在Azure AD中创建一个新组?

发布于 2025-02-10 02:45:39 字数 87 浏览 1 评论 0 原文

我需要使用GO SDK在Azure Active Directory中创建一个组,我以某种方式难以找到学习资源来做到这一点。我可以得到一个例子或解释如何进行吗?

I need to create a group in Azure Active Directory programmatically using Go SDK, I somehow struggle to find the learning resources to do that. Can I get an example or explanation how to go about it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

软糯酥胸 2025-02-17 02:45:39

为了达到您的要求,您可以使用 通过将 Microsoft Graph API 集成到您的 go应用程序中,Microsoft Graph SDK

确保 安装和导入 所需库,并创建 authProvider 实例。

您可以参考此 Microsoft doc 通过Graph API在Azure AD中创建组,其中包括 的代码snippets Go 也是如此。

在运行查询之前,请确保同意需要权限。根据您指定的请求主体; 组类型 将相应地决定。

要创建安全组,我给出了请求主体,如下所示:

“在此处输入图像描述”

您可以获得 GO代码通过选择 代码snippets

//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)

requestBody := msgraphsdk.NewGroup()
description := "Example of Security Group"
requestBody.SetDescription(&description)
displayName := "Sri Security"
requestBody.SetDisplayName(&displayName)
requestBody.SetGroupTypes( []string {
}
mailEnabled := false
requestBody.SetMailEnabled(&mailEnabled)
mailNickname := "test"
requestBody.SetMailNickname(&mailNickname)
securityEnabled := true
requestBody.SetSecurityEnabled(&securityEnabled)
result, err := graphClient.Groups().Post(requestBody)

运行上述查询后,安全组成功创建了类似于下面的创建:

To achieve your requirement, you can make use of Microsoft Graph SDK for Go by integrating the Microsoft Graph API into your Go application.

Make sure to install and import required libraries and create authProvider instance.

You can refer this Microsoft Doc to create group in Azure AD via Graph API that includes code snippets for Go too.

Make sure to consent required permissions before running the query. Based on the request body you specify; group type will be decided accordingly.

To create Security group, I gave request body like below:

enter image description here

You can get GO code by selecting code snippets:

//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)

requestBody := msgraphsdk.NewGroup()
description := "Example of Security Group"
requestBody.SetDescription(&description)
displayName := "Sri Security"
requestBody.SetDisplayName(&displayName)
requestBody.SetGroupTypes( []string {
}
mailEnabled := false
requestBody.SetMailEnabled(&mailEnabled)
mailNickname := "test"
requestBody.SetMailNickname(&mailNickname)
securityEnabled := true
requestBody.SetSecurityEnabled(&securityEnabled)
result, err := graphClient.Groups().Post(requestBody)

After running the above query, Security Group created successfully like below:

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文