Skip to content

Golang implementation of the Microsoft Graph API

License

Notifications You must be signed in to change notification settings

machship/go-msgraph

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Golang Microsoft Graph API implementation

Latest Release Github Actions godoc Go Report Card codebeat badge codecov MIT License

go-msgraph is a go lang implementation of the Microsoft Graph API. See Overview of Microsoft Graph

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
  • use $select, $search and $filter when querying data
  • context-aware API calls, can be cancelled.
  • loading huge data sets with paging, thanks to PR #20 - @Goorsky123

planned:

Example

To get your credentials to access the Microsoft Graph API visit: Register an application with Azure AD and create a service principal

More examples can be found at the docs. Here's a brief summary of some of the most common API-queries, ready to copy'n'paste:

// 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]")
// 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("[email protected]", startTime, endTime)

Versioning & backwards compatibility

This project uses Semantic versioning with all tags prefixed with a v. Altough currently the case, I cannot promise to really keep everything backwards compatible for the 0.x version. If a 1.x version of this repository is ever released with enough API-calls implemented, I will keep this promise for sure. Any Breaking changes will be marked as such in the release notes of each release.

Installation

I recommend to use go modules and always use the latest tagged release. You may directly download the source code there, but the preffered way to install and update is with go get:

# Initially install
go get github.com/open-networks/go-msgraph
# Update
go get -u github.com/open-networks/go-msgraph
go mod tidy

Documentation

There is some example code placed in the docs/ folder. The code itself is pretty well documented with comments, hence see http://godoc.org/github.com/open-networks/go-msgraph or run:

godoc github.com/open-networks/go-msgraph

License

MIT

About

Golang implementation of the Microsoft Graph API

Resources

License

Security policy

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 99.4%
  • Dockerfile 0.6%