azure - 如何使用 Go SDK 在 Azure AD 中创建新组?

标签 azure go azure-active-directory

我需要使用 Go SDK 以编程方式在 Azure Active Directory 中创建一个组,但不知何故,我很难找到执行此操作的学习资源。我可以获得示例或解释如何进行吗?

最佳答案

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

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

您可以引用这个Microsoft Doc 通过 Graph API 在 Azure AD 中创建组,其中还包含 Go 的代码片段。

在运行查询之前,请确保同意所需的权限。基于您指定的请求正文; 组类型将相应决定。

为了创建安全组,我给出了如下请求正文:

enter image description here

您可以通过选择code snippets来获取GO代码 :

//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)

运行上述查询后,安全组创建成功,如下所示:

enter image description here

关于azure - 如何使用 Go SDK 在 Azure AD 中创建新组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72719195/

相关文章:

python - Azure Batch 服务与用于 Python 作业的 Azure Databricks

mongodb - 确保 MongoDB 以动态时间间隔使数据过期并且调用是幂等的

go - 如何在 Perl 中编码的 Go 中对 Base64 进行 URL 安全解码?

Java阅读POST,奇怪的十六进制解释

c# - 在 ASP.NET MVC 和 Azure AD 中创建自定义用户角色

azure - Azure AD b2c 中的自定义策略 - 声明提供程序指南的问题

linux - 从 Azure Linux VM 上的脚本启动防病毒扫描

azure - 我需要在 web.config 中的 ApplicationInitialization 添加端口吗

reactjs - React Router 在 Azure Linux Web App 上抛出 404

angular - 使用 MSAL Angular 包装器在 Ionic 4 中处理来自 Azure AD 的回调