Panda6754
Panda6754

Reputation: 27

How to work with GO SDK while Azure AD user creation?

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?

Upvotes: 0

Views: 691

Answers (1)

Rukmini
Rukmini

Reputation: 16139

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 := "[email protected]"
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

Upvotes: 1

Related Questions