-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from open-networks/develop
Add DisableAccount and DeleteUser functions, write unit tests for new user funcs, update documentation
- Loading branch information
Showing
8 changed files
with
231 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
```` |