# README
gomsgraph
Gomsgraph is a Go client library for accessing the Microsoft Graph API v1.
Package documentation
For complete usage of the Gomsgraph client, see the full package documentation.
Installation
Installation of a specific version using go get
.
go get github.com/michaljirman/[email protected]
Authentication
The Gomsgraph library uses oauth2 library to implement the oauth2 authentication.
Simply pass http.Client
implementation which can handle authentication while creating a new MS Graph
client.
ctx := context.Background()
tc := msgraph.GetOAuth2Client(ctx, azureTenantID, azureClientID, azureClientSecret)
client := msgraph.NewClient(tc)
OAuth2 documentation is available on oauth2 docs.
Example usage
To create a new Gomsgraph client:
package main
import (
"context"
"log"
"github.com/google/uuid"
"github.com/michaljirman/gomsgraph/msgraph"
v1 "github.com/michaljirman/gomsgraph/msgraph/v1"
. "github.com/michaljirman/gomsgraph/msgraph/v1/models"
)
func main() {
ctx := context.Background()
client := v1.NewDefaultClient(ctx)
req := User{
Id: msgraph.String(uuid.NewString()),
AccountEnabled: msgraph.Bool(true),
DisplayName: msgraph.String("Test User"),
MailNickname: msgraph.String("TestU"),
UserPrincipalName: msgraph.String("[email protected]"),
PasswordProfile: &PasswordProfile{
Password: msgraph.String(uuid.NewString()),
ForceChangePasswordNextSignIn: msgraph.Bool(true),
ForceChangePasswordNextSignInWithMfa: msgraph.Bool(true),
},
}
userResp, err := client.Users.CreateUser(ctx, req)
if err != nil {
log.Fatalf("failed to create a new user %v", err)
}
usersResp, err := client.Users.ListAll(ctx, &ListOptions{})
if err != nil {
log.Fatalf("failed to list all users %v", err)
}
log.Printf("%d users found\n", len(usersResp.Users))
user, err := client.Users.GetUser(ctx, *userResp.Id, nil)
if err != nil {
log.Fatalf("failed to get user by ID %v", err)
}
log.Printf("user: %+v, %+v", user.Id, user.DisplayName)
}
Developing
Committed code must pass following checks:
To list all development commands:
$ make help
fmt : format go files
golangci-lint : run golangci-lint
gotest : run all golang tests
integration : run all integration tests
lint : run lint tools
staticcheck : run staticcheck
test : run all tests
To use a proxy, set the environment variable HTTP_PROXY
from a shell or withing the program:
$ export HTTP_PROXY=http://proxy_name:proxy_port
os.Setenv("HTTP_PROXY", "http://proxy_name:proxy_port")
Versioning
Versions of the client are tagged on github. For each tagged version a new release is automatically creating using a goreleaser and github actions.
Contributing
Please see the contribution guidelines.