Skip to content
Golang implementation of the Microsoft Graph API
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.
.gitignore initial commit Jul 9, 2018
.travis.yml .travis.yml: fixing coverprofile-path Aug 30, 2018
Attendee.go
Attendee_test.go Add Attendees struct and Equal-func to Attendee. Create test-cases fo… Jul 25, 2018
Attendees.go Add Attendees struct and Equal-func to Attendee. Create test-cases fo… Jul 25, 2018
Attendees_test.go Attendees_test: correct test-case for String Jul 25, 2018
CONTRIBUTORS initial commit Jul 9, 2018
Calendar.go
CalendarEvent.go CalendarEvent: fixing Equal func Jan 8, 2019
CalendarEvents.go
Calendar_test.go Calendar integration: enhance overall-integration and documentation Sep 3, 2018
Calendars.go
Calendars_test.go
EmailAddress.go Calendar integration: enhance overall-integration and documentation Sep 3, 2018
GraphClient.go GraphClient: Add GetGroup(groupID string) and testcase Aug 30, 2018
GraphClient_test.go
Group.go Group: add fields and attributes, write custom json.Unmarshal for the… Sep 3, 2018
Group_test.go Group: add fields and attributes, write custom json.Unmarshal for the… Sep 3, 2018
Groups.go Group(s) and User(s): enhance graphClient inheritance, prepare for fu… Sep 3, 2018
LICENSE
README.md
ResponseStatus.go
ResponseStatus_test.go ResponseStatus: Add Equal-func unit-tests and adapt String-func for R… Jul 25, 2018
Token.go initial commit Jul 9, 2018
User.go Group(s) and User(s): enhance graphClient inheritance, prepare for fu… Sep 3, 2018
User_test.go ListCalendarView(): move from GraphClient to User Aug 30, 2018
Users.go Group(s) and User(s): enhance graphClient inheritance, prepare for fu… Sep 3, 2018
Users_test.go Users: add unit-tests Jul 25, 2018
constants.go
supportedTimeZones.go Add timezone (UTC+05:00) Qyzylorda Apr 30, 2019

README.md

Golang Microsoft Graph API implementation

godoc Build Status Go Report Card Codacy Badge codebeat badge codecov

go-msgraph is a go lang implementation of the Microsoft Graph API. See https://developer.microsoft.com/en-us/graph/docs/concepts/overview

General

This implementation has been written to get various user, group and calendar details out of a Microsoft Azure Active Directory. Currently only READ-access is implemented, but you are welcome to add WRITE-support to it & backmerge it

Features

working & tested:

  • list users, groups, calendars, calendarevents
  • automatically grab & refresh token for API-access
  • json-load the GraphClient struct & initialize it
  • set timezone for full-day CalendarEvent

in progress:

  • implement paging to load huge data-sets, currently limitted to one page, 999 entries

planned:

Example

To get your credentials visit: https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-create-service-principal-portal

// 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)
}

// initialize the GraphClient via JSON-Load. Please do proper error-handling (!)
// Specify JSON-Fields TenantID, ApplicationID and ClientSecret 
fileContents, err := ioutil.ReadFile("./msgraph-credentials.json")
var graphClient msgraph.GraphClient
err = json.Unmarshal(fileContents, &graphClient)

// 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("humpty@contoso.com") 
// List all groups
groups, err := graphClient.ListGroups()
// List all members of a group.
groupMembers, err := groups[0].ListMembers()
// Lists all Calendars of a user
calendars, err := user.ListCalendars()

// Let all full-day calendar events that are loaded from ms graph be set to timezone Europe/Vienna:
// Standard is time.Local
msgraph.FullDayEventTimeZone, _ = time.LoadLocation("Europe/Vienna")

// Lists all CalendarEvents of the given userPrincipalName/ID that starts/ends within the the next 7 days
startTime := time.Now()
endTime := time.Now().Add(time.Hour * 24 * 7)
events, err := graphClient.ListCalendarView("alice@contoso.com", startTime, endTime)

Installation

Using go get

$ go get github.com/open-networks/go-msgraph

You can use go get -u to update the package.

Documentation

For docs, see http://godoc.org/github.com/open-networks/go-msgraph or run:

$ godoc github.com/open-networks/go-msgraph
You can’t perform that action at this time.