You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// initialize GraphClient manuallygraphClient, err:=msgraph.NewGraphClient("<TenantID>", "<ApplicationID>", "<ClientSecret>")
iferr!=nil {
fmt.Println("Credentials are probably wrong or system time is not synced: ", err)
}
// List all usersusers, err:=graphClient.ListUsers()
// Gets all the detailled information about a user identified by it's ID or userPrincipalNameuser, err:=graphClient.GetUser("[email protected]")
Create a user
// example for Create-func:user, err:=graphClient.CreateUser(
msgraph.User{
AccountEnabled: true,
DisplayName: "Rabbit",
MailNickname: "The rabbit",
UserPrincipalName: "[email protected]",
PasswordProfile: PasswordProfile{Password: "SecretCarrotBasedPassphrase"},
},
msgraph.CreateWithContext(ctx)
)
Update a user
// first, get the user:user, err:=graphClient.GetUser("[email protected]")
// then create a user object, only set the fields you want to change.err:=user.UpdateUser(msgraph.User{DisplayName: "Rabbit 2.0"}, msgraph.UpdateWithContext(ctx))
// Hint 1: UpdateWithContext is optional// Hint 2: you cannot disable a user that way, please user user.Disable// Hint 3: after updating the account, you have to use GetUser("...") again.// disable acccounterr:=user.DisableAccount()
// enable user account againerr:=user.UpdateUser(User{AccountEnabled: true})
// delete a user, use with caution!err:=user.DeleteUser()