Skip to content
Microsoft Graph Client Library for Go
Go
Branch: master
Clone or download
Latest commit 9c0b953 Oct 14, 2019
Permalink
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
cmd
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
README.md Update README.md 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

README.md

msgraph.go

v1.0 beta
GoDoc GoDoc

Introduction

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 https://graph.microsoft.com/v1.0/$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.

Usage

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 https://graph.microsoft.com/v1.0/$metadata to metadata-v1.0.xml
2019/10/14 02:53:41 Downloading https://graph.microsoft.com/beta/$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 "github.com/yaegashi/msgraph.go/v1.0"
import msgraph "github.com/yaegashi/msgraph.go/beta"

Example

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 https://microsoft.com/devicelogin and enter the code H8AYAEUCS to authenticate.
2019/10/14 02:55:02 GET https://graph.microsoft.com/v1.0/me
{
  "id": "126871095554adb4",
  "displayName": "八重樫 剛史",
  "givenName": "剛史",
  "surname": "八重樫",
  "userPrincipalName": "yaegashi@live.jp"
}
2019/10/14 02:55:03 GET https://graph.microsoft.com/v1.0/me/drive/root/children?%24filter=file+ne+null&%24select=name%2Cfile%2Csize%2CwebUrl
[
  {
    "name": "文書.docx",
    "webUrl": "https://1drv.ms/w/s!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.

Todo

  • 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 godoc.org
  • Persist OAuth2 tokens in file
  • OAuth2 device auth grant
  • OAuth2 client credentials grant
  • OAuth2 authorization code grant

References

You can’t perform that action at this time.