英文:
How to work with GO SDK while Azure AD user creation?
问题
我想使用GO SDK以编程方式创建Azure AD用户,但找不到任何相关文档。我对这个平台还不熟悉。
从Azure门户中,我知道如何创建用户,但要求是使用GO来完成。
有人尝试过并获得了结果吗?有人可以提供一些GO代码示例吗?
英文:
Would like to create Azure AD user from GO SDK programmatically but can't find any related docs. I am new to this platform.
From Azure Portal I know how to create user, but the requirement is do it from GO.
Anyone tried and got the results? Can someone help with sample GO code?
答案1
得分: 1
要使用GO SDK创建用户,您可以使用以下示例代码,如MsDoc中所述:
// GO SDK目前处于预览阶段,仅限非生产使用
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
requestBody := msgraphsdk.NewUser()
accountEnabled := true
requestBody.SetAccountEnabled(&accountEnabled)
displayName := "User1"
requestBody.SetDisplayName(&displayName)
mailNickname := "test"
requestBody.SetMailNickname(&mailNickname)
userPrincipalName := "user1@contoso.onmicrosoft.com"
requestBody.SetUserPrincipalName(&userPrincipalName)
passwordProfile := msgraphsdk.NewPasswordProfile()
requestBody.SetPasswordProfile(passwordProfile)
forceChangePasswordNextSignIn := true
passwordProfile.SetForceChangePasswordNextSignIn(&forceChangePasswordNextSignIn)
password := "*********"
passwordProfile.SetPassword(&password)
result, err := graphClient.Users().Post(requestBody)
要了解如何将GO SDK与Azure Ad集成,您可以参考以下链接:
安装Microsoft Graph SDK - Microsoft Graph | Microsoft Docs
英文:
> To create user from GO SDK, you can make use of below sample code as mentioned in this MsDoc:
//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
requestBody := msgraphsdk.NewUser()
accountEnabled := true
requestBody.SetAccountEnabled(&accountEnabled)
displayName := "User1"
requestBody.SetDisplayName(&displayName)
mailNickname := "test"
requestBody.SetMailNickname(&mailNickname)
userPrincipalName := "user1@contoso.onmicrosoft.com"
requestBody.SetUserPrincipalName(&userPrincipalName)
passwordProfile := msgraphsdk.NewPasswordProfile()
requestBody.SetPasswordProfile(passwordProfile)
forceChangePasswordNextSignIn := true
passwordProfile.SetForceChangePasswordNextSignIn(&forceChangePasswordNextSignIn)
password := "*********"
passwordProfile.SetPassword(&password)
result, err := graphClient.Users().Post(requestBody)
To know how to integrate GO SDK with Azure Ad you can refer below link:
Install a Microsoft Graph SDK - Microsoft Graph | Microsoft Docs
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论