Skip to content
Microsoft Graph Client Library for Go
Branch: master
Clone or download
Latest commit 9c0b953 Oct 14, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
auth Update auth package, support client credentials authentication Oct 14, 2019
beta Refactor generator again Oct 14, 2019
gen Refactor generator again Oct 14, 2019
ptr Add new helper packages: ptr, val Oct 14, 2019
v1.0 Refactor generator again Oct 14, 2019
val Add new helper packages: ptr, val Oct 14, 2019
.gitignore Update msgraph-me Oct 13, 2019 Update Oct 14, 2019
go.mod Implement Azure AD v2 device auth and purge go-autorest Sep 15, 2019
go.sum Implement Azure AD v2 device auth and purge go-autorest Sep 15, 2019


v1.0 beta
GoDoc GoDoc


Microsoft Graph client library for Go. Still in PoC or pre-alpha stage. Don't use in production.

The library code is auto-generated from the REST API specification available at$metadata.

The code generator is written in pure Go, in contrast to the official code generator heavily relying on C# and non-portable .NET Framework.


Use go generate to download the metadata and generate library code from it:

$ rm gen/*.xml
$ go generate ./gen
2019/10/14 02:53:40 Downloading$metadata to metadata-v1.0.xml
2019/10/14 02:53:41 Downloading$metadata to metadata-beta.xml
2019/10/14 02:53:42 Creating ../v1.0/msgraph.go
2019/10/14 02:53:43 Formatting ../v1.0/msgraph.go
2019/10/14 02:53:44 Creating ../beta/msgraph.go
2019/10/14 02:53:45 Formatting ../beta/msgraph.go

You can choose API version when importing msgraph package:

import msgraph ""
import msgraph ""


cmd/msgraph-me/main.go shows simple usage example. It contains Azure AD v2 device code flow for the user authentication. You can authenticate yourself with personal (Microsoft) account or organizational account.

$ go get ./cmd/msgraph-me
$ msgraph-me
To sign in, use a web browser to open the page and enter the code H8AYAEUCS to authenticate.
2019/10/14 02:55:02 GET
  "id": "126871095554adb4",
  "displayName": "八重樫 剛史",
  "givenName": "剛史",
  "surname": "八重樫",
  "userPrincipalName": ""
2019/10/14 02:55:03 GET
    "name": "文書.docx",
    "webUrl": "!ALStVFUJcWgSijU",
    "file": {
      "hashes": {
        "quickXorHash": "",
        "sha1Hash": "F1CFE569876E83122C54366F918500F6D778B777"
      "mimeType": "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
    "size": 11393

It saves auth tokens in token_store.json in the current directory. You won't be asked for authentication again until tokens in this file expires.


  • Save indented metadata.xml
  • Support Action elements in metadata
  • Support Function elements in metadata
  • Split output into multiple packages
  • Generate camel cases in golang manner (IpAddress -> IPAddress)
  • Improve API documentation in
  • Persist OAuth2 tokens in file
  • OAuth2 device auth grant
  • OAuth2 client credentials grant
  • OAuth2 authorization code grant


You can’t perform that action at this time.