如何在创建 Azure AD 用户时使用 GO SDK?

huangapple go评论67阅读模式
英文:

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

huangapple
  • 本文由 发表于 2022年7月14日 16:27:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/72977493.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定