Skip to content

Commit

Permalink
doc: add example_user.md with DisableAccount and UpdateUser
Browse files Browse the repository at this point in the history
  • Loading branch information
TerraTalpi committed Aug 19, 2021
1 parent 3c740d8 commit 03542fe
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 4 deletions.
4 changes: 0 additions & 4 deletions docs/example_Context-awareness.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ ctx, cancel := context.WithCancel(context.Background())
user, err := graphClient.GetUser("[email protected]", msgraph.GetWithContext(ctx))
// example for List-func:
users, err := graphClient.ListUsers(msgraph.ListWithContext(ctx))
// example for Create-func:
user, err := graphClient.CreateUser(msgrpah.User: {DisplayName : "New User"}, msgraph.CreateWithContext(ctx))
// example for update-func:
err = := user.UpdateUser(msgraph.User{DisplayName: "Even newer User"}, msgraph.UpdateWithContext(ctx))
````

Note: the use of a context is optional. If no context is given, the context `context.Background()` will automatically be used for all API-calls.
48 changes: 48 additions & 0 deletions docs/example_User.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Example GraphClient initialization

## Getting, listing, filtering users

````go
// initialize GraphClient manually
graphClient, err := msgraph.NewGraphClient("<TenantID>", "<ApplicationID>", "<ClientSecret>")
if err != nil {
fmt.Println("Credentials are probably wrong or system time is not synced: ", err)
}

// List all users
users, err := graphClient.ListUsers()
// Gets all the detailled information about a user identified by it's ID or userPrincipalName
user, err := graphClient.GetUser("[email protected]")

````

## Create a user

````go
// 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

````go
// 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 acccount
err := user.DisableAccount()
````

0 comments on commit 03542fe

Please sign in to comment.