Skip to content
Library for communication with Microsoft Graph API. This library is NOT complete.
Go
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
README.md
client.go
entity_calendar.go
entity_contact.go
entity_contact_folder.go
entity_contact_test.go
entity_event.go
entity_event_test.go
entity_me.go
entity_properties.go
error.go
generic_result.go
requests.go

README.md

#msgraph-go Library for communication with Microsoft Graph API.

Library support

Currently supported are requests to:

  • basic user info
  • calendars

More request support may come soon. All exposed methods are subject to change.

Usage

To install the library into your project, add msgraph-go into your GOPATH:

$ go get github.com/jkrecek/msgraph-go

Then, in your go project, you can create graph client:

import "github.com/jkrecek/msgraph-go"

var exampleOAuthConfig = &oauth2.Config{
   ClientID: "YOUR_CLIENT_ID",
   RedirectURL: "https://localhost",
   Scopes: []string{
       "User.Read",
   },
   Endpoint: oauth2.Endpoint{
       AuthURL: "https://login.microsoftonline.com/common/oauth2/v2.0/authorize",
       TokenURL: "https://login.microsoftonline.com/common/oauth2/v2.0/token",
   },
}

exampleOAuthToken := &oauth2.Token{
   AccessToken: "YOUR_ACCESS_TOKEN",
   RefreshToken: "YOUR_REFRESH_TOKEN",
   Expiry: time.Now().Add(time.Hour), 
}


client := graph.NewClient(exampleOAuthConfig, exampleOAuthToken)

Both oauth2.Config and oauth2.Token are required to successfully authorize outgoing requests.

To make further requests, you can call method directly on client, for example:

...

client := graph.NewClient(exampleOAuthConfig, exampleOAuthToken)

me, err := client.GetMe()
if err != nil {
    log.Println(err)
}

_ = me.Id                   // Returns user id
_ = me.UserPrincipalName    // Returns user principal name, usually email address
You can’t perform that action at this time.