Microsoft Graph Client Library for Go

Related tags

Network golang msgraph
Overview

msgraph.go

v1.0 beta
pkg.go.dev pkg.go.dev

(The online references at pkg.go.dev above are not shown due to huge size of packages - #23)

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.

v0.x.x releases

See GitHub releases for all release tags and release notes, and pkg.go.dev for all Go module versions available for your applications.

Until v1.0.0, all types of changes might be included in every release: bug fixes, new features, even incompatible API updates.

Usage

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"

You could benefit from better IDE assisted coding experience because Graph API specs are completely translated to Go codes by msgraph.go.

Code examples in the repository:

Hacking

Run go generate ./gen to download the metadata and generate library code from it.

$ go generate ./gen
2020/08/02 19:46:20 Downloading https://graph.microsoft.com/v1.0/$metadata to metadata/v1.0.xml
2020/08/02 19:46:20 metadata/v1.0.xml already exists, skipping
2020/08/02 19:46:21 Downloading https://graph.microsoft.com/beta/$metadata to metadata/beta.xml
2020/08/02 19:46:21 metadata/beta.xml already exists, skipping
2020/08/02 19:46:21 Creating directory ../v1.0
2020/08/02 19:46:21 Removing ../v1.0/ModelAverage.go
2020/08/02 19:46:21 Removing ../v1.0/RequestSchema.go
2020/08/02 19:46:21 Removing ../v1.0/RequestAndroid.go.go
...
2020/08/02 19:47:06 Creating ../v1.0/extensions.go
2020/08/02 19:47:06 Creating ../v1.0/msgraph.go
2020/08/02 19:47:06 Creating ../v1.0/const.go
2020/08/02 19:47:06 Creating ../v1.0/EnumAction.gonEnum.go
...
2020/08/02 19:47:07 Formatting ../v1.0/ModelMedia.go
2020/08/02 19:47:07 Formatting ../v1.0/RequestWorkbookFunctionsN.go
2020/08/02 19:47:07 Formatting ../v1.0/EnumReject.go

(Currently code generation from the latest metadata is broken - #22)

Todo

  • Save indented metadata.xml
  • Support Action elements in metadata
  • Support Function elements in metadata
  • Support batch requests
  • Access to additional properties like @odata.type @odata.id
  • Split output into multiple files
  • Generate camel cases in golang manner (IpAddress -> IPAddress)
  • Provide easy way to generate pointers to literals
  • Provide easy way to generate pointers to constants
  • Provide easy way to add queries like $expand $select $filter
  • Every request method should take a ctx as the first arg for better control
  • Online API docs (the output is too big for pkg.go.dev to handle - #23)
  • Unit tests
  • CI
  • Persist OAuth2 tokens in file
  • Persist OAuth2 tokens in object storage like Azure Blob
  • OAuth2 device auth grant
  • OAuth2 client credentials grant
  • Use string for EnumType (pointed out in #6)
  • Reduce number of generated files (#11)
  • Provide easy way to add HTTP headers like Prefer: outlook.timezone="Tokyo Standard Time"
  • Support max number of pages to retrieve from a collection
  • Support Windows time zone names in DateTimeTimeZone (utilize wtz.go)

References

Applications

Comments
  • does not compile on macOS

    does not compile on macOS

    There are lots of files in the beta folder and macOS does not like it.

    ➜ go build
    go build github.com/yaegashi/msgraph.go/beta: /usr/local/Cellar/go/1.14/libexec/pkg/tool/darwin_amd64/compile: fork/exec /usr/local/Cellar/go/1.14/libexec/pkg/tool/darwin_amd64/compile: argument list too long
    

    The beta folder is auto-generated, so I would recommend folding files where related.

    For example:

    • ACLModel.go and ACLTypeEnum.go could be combined into one ACL.go
    • many AccessPackage*.go into AccessPackage.go
    • many more AndroidDeviceOwner*.go into AndroidDeviceOwner

    Also seen in:

    • https://github.com/42wim/matterbridge/commit/795a8705c3fdc5bf55e83d382e7d3ff233896a0b#r37693076
    • https://l0w.dev/posts/pkg.go.dev-limitation/
    opened by qaisjp 4
  • Top seems to be ignored

    Top seems to be ignored

    I'm trying to use Top() on a query and the query string part of the request seems to simply be ignored. When I check the URL to debug, the query string is present, but the reply seems to be ignoring it. Sample code:

    graphClient := msgraph.NewClient(...)
    ct := graphClient.Teams().ID(teamid).Channels().ID(channel).Messages().Request()
    ct.Top(20)
    fmt.Println("calling url: %s", ct.URL()) // calling url: https://graph.microsoft.com/beta/teams/.../channels/.../messages?%24top=20
    rct, err := ct.Get(ctx)
    fmt.Println("got %#v messages", len(rct)) // got 592 messages 
    
    opened by pmmaga 2
  • Unable to clear string attributes

    Unable to clear string attributes

    The correct way to clear a string attribute is to assign it null value, but in the model, struct attributes are marked as omitempty, which means null values won't be pass to the API.

    Is there any workaround?

    opened by nauxliu 2
  • Add resource owner password credentials grant support

    Add resource owner password credentials grant support

    Hello @yaegashi,

    Great project. It's very helpful.

    I added support for Resource Owner Password Credentials in a project I'm using. https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-oauth-ropc

    Please let me know if you'd like me to make any changes. Again, great work! よろしくお願いします。

    opened by charlesgreen 1
  • Code generator refactoring

    Code generator refactoring

    • Refactor code generator
    • Fix initialism table and add test
    • Avoid using defer in for loop
    • Parallelize formatting with chan
    • Run go generate
    • Update GitHub Actions workflows
    • Update README.md
    opened by yaegashi 0
  • msauth: improvement for token cache store handling

    msauth: improvement for token cache store handling

    • Fix bug that fails to save a refreshed token in DeviceAuthorizationGrant()
    • Token cache dirty state control, save cache to file only when it's updated
    • Network location support for token cache store (Azure Blob Storage URL with SAS assumed)
    opened by yaegashi 0
  • v0.1.2

    v0.1.2

    • Reduce number of generated files (#11)
    • EnumType should be string (#6)
    • Add support for Edm types: Date, TimeOfDay, Duration
    • Fix actions returning a collection
    • Add support for max number of pages to retrieve from a collection
    • Add support for modifying request headers
    opened by yaegashi 0
  • How to create Azure AD app using service principal credentials

    How to create Azure AD app using service principal credentials

    I have created an Azure AD app using " az ad sp create-for-rbac --sdk-auth --role Owner" command. Also i have given required api permission as mentioned below: api-permission

    I am getting 403 error with below code: error i am getting error": "graphrbac.ApplicationsClient#Create: Failure responding to request: StatusCode=403 -- Original Error: autorest/azure: Service returned an error. Status=403 Code=\"Unknown\" Message=\"Unknown service error\" Details=[{\"odata.error\":{\"code\":\"Authorization_RequestDenied\",\"date\":\"2021-12-23T11:41:23\",\"message\":{\"lang\":\"en\",\"value\":\"Insufficient privileges to complete the operation.\"},\"requestId\":\"f192ac37-8b05-4a81-a582-13f0f5ca3594\"}}]"

    Code i am using to initialize app client is :

    appClient := graphrbac.NewApplicationsClient(tenantID) credConfig := auth.NewClientCredentialsConfig(clientID, clientSecret, tenantID) //credConfig.Resource = azure.PublicCloud.ResourceIdentifiers.Graph credConfig.Resource = "https://graph.microsoft.com" authorizer, err := credConfig.Authorizer() if err != nil { return appClient, err } appClient.Authorizer = authorizer

    I am not sure how i can create an Azure AD app client for microsoft Graph API SDK, since there is no method i have found for the same.
    
    opened by akhilesh2410 0
  • Official Microsoft Graph Go SDK

    Official Microsoft Graph Go SDK

    Hello everyone 👋

    Vincent here from the Microsoft Graph SDKs team. I'm reaching out to announce we're working on an official Go SDK, we haven't announced the community preview yet as there are still a number of things we need to work through, but I though I'd reach out to give you an opportunity to provide feedback before anybody else!

    A few benefits from this new SDK:

    • Fluent style APIs to all endpoints of the API
    • Contains all the models of the API
    • Is updated weekly to always be in sync with the API
    • Supports v1 and beta
    • Relies on Azure identity to provide support for multiple authentication flows (you also can implement your own authentication provider)
    • Provides middleware for Retry handling and Redirect handling (more to come)
    • And many more features to come!

    As with every pre-previews, we have a list of known limitations we're working through.

    We'd love for you to pop by the repos under our org, give it a try, and give us feedback on your experience with this new SDK.

    opened by baywet 4
  • How to download the Photo of a user?

    How to download the Photo of a user?

    I would like to obtain the Photo for a given user. I just find the metadata like height

    			photo, err := graphClient.Users().ID( *user.ID ).Photo().Request().Get(ctx)
    			var height = photo.Height
    

    The documentation states that there should be a "$value" added to the path. How do I construct it?

    opened by dkrizic 0
  • WIP: Add namespace support to generator

    WIP: Add namespace support to generator

    A work in progress attempt at a fix for #22 .

    This seems to work okay for v1.0 but currently is broken when generating for beta.

    The generator runs for beta but I think that it has perhaps conflicts in the names of types? I'm not sure the best way to approach this, should the different namespaces be under their own structure, for example github.com/yaegashi/msgraph.go/beta/callRecords for the microsoft.graph.callRecords namespace?

    opened by rikkuness 2
  • Cannot sendMail with attachments

    Cannot sendMail with attachments

    Currently the way that SendMail is defined, it is not obvious how to send a message with attachments.

    Message is defined with Attachments: []Attachment; but when you pass an Attachment object to the API, you must provide either a FileAttachment or an ItemAttachment. In my case I wanted to provide a FileAttachment, which requires setting the ContentBytes field, which is not present on the Attachment struct.

    I realize this is somewhat of a problem with representing the graph data-types (which make use of subclassing) in Go (which doesn't); and wondered if you'd given this some thought already – it's definitely not clear what the right solution is. Maybe an AddFileAttachment(file *FileAttachment) method on SendMailRequestBuilder?

    opened by ConradIrwin 1
Releases(v0.1.4)
  • v0.1.4(Aug 2, 2020)

  • v0.1.3(Jun 27, 2020)

    • Add resource owner password credentials grant support (#13)
    • msauth: improvement for token cache store handling (#20)
    • Integrate wtz.go in cmd/msgraph-me (#21)
    Source code(tar.gz)
    Source code(zip)
  • v0.1.2(Mar 14, 2020)

    • Reduce number of generated files (#11)
    • EnumType should be string (#6)
    • Add support for Edm types: Date, TimeOfDay, Duration
    • Fix actions returning a collection
    • Add support for max number of pages to retrieve from a collection
    • Add support for modifying request headers
    Source code(tar.gz)
    Source code(zip)
  • v0.1.1(Feb 21, 2020)

Owner
YAEGASHI Takeshi
YAEGASHI Takeshi
connect to microsoft flight simulator 2020 using golang

msfs2020-go simconnect package msfs2020-go/simconnect connects to microsoft flight simulator 2020 using golang. cross-compiles from macos/linux, no ot

lian 365 Nov 23, 2022
User enumeration with Microsoft Teams API

UserEnumTeams Description Sometimes user enumeration could be sometimes useful during the reconnaissance of an assessment. This tool will determine if

immunIT 155 Jan 2, 2023
Bridge between mattermost, IRC, gitter, xmpp, slack, discord, telegram, rocketchat, twitch, ssh-chat, zulip, whatsapp, keybase, matrix, microsoft teams, nextcloud, mumble, vk and more with REST API

bridge between mattermost, IRC, gitter, xmpp, slack, discord, telegram, rocketchat, twitch, ssh-chat, zulip, whatsapp, keybase, matrix, microsoft teams, nextcloud, mumble, vk and more with REST API (mattermost not required!)

Wim 5.4k Jan 4, 2023
Downloads the Windows 10 wallpapers provided by Microsoft.

microsoft-wallpapers Preparation Prepare an input file that contains a list of links from the Microsoft website that lead to wallpapers. This list is

River Wooley 0 Nov 29, 2021
A document scanner that creates a graph of the analogy between documents.

Social Analogizer The idea is that this program scans documents for keyword that correspond to other documents. Starting point is that a user has a pr

Tibart 0 Dec 20, 2021
null 43 Dec 13, 2022
Gotypegraph - Generate definitions and references graph

gotypegraph Generate definitions and references graph. Usage ❯ gotypegraph -h Us

null 0 Feb 15, 2022
Prisma Client Go is an auto-generated and fully type-safe database client

Prisma Client Go Typesafe database access for Go Quickstart • Website • Docs • API reference • Blog • Slack • Twitter Prisma Client Go is an auto-gene

Prisma 1.4k Jan 9, 2023
The Dual-Stack Dynamic DNS client, the world's first dynamic DNS client built for IPv6.

dsddns DsDDNS is the Dual-Stack Dynamic DNS client. A dynamic DNS client keeps your DNS records in sync with the IP addresses associated with your hom

Ryan Young 15 Sep 27, 2022
Go Substrate RPC Client (GSRPC)Go Substrate RPC Client (GSRPC)

Go Substrate RPC Client (GSRPC) Substrate RPC client in Go. It provides APIs and types around Polkadot and any Substrate-based chain RPC calls. This c

Chino Chang 1 Nov 11, 2021
Server and client implementation of the grpc go libraries to perform unary, client streaming, server streaming and full duplex RPCs from gRPC go introduction

Description This is an implementation of a gRPC client and server that provides route guidance from gRPC Basics: Go tutorial. It demonstrates how to u

Joram Wambugu 0 Nov 24, 2021
Godaddy-domains-client-go - Godaddy domains api Client golang - Write automaticly from swagger codegen

Go API client for swagger Overview This API client was generated by the swagger-codegen project. By using the swagger-spec from a remote server, you c

Mickael Stanislas 0 Jan 9, 2022
Tailscale-client-go - A client implementation for the Tailscale HTTP API

tailscale-client-go A client implementation for the Tailscale HTTP API Example p

David Bond 0 Sep 8, 2022
Comunicación de envios de archivos entres cliente-servidor, client-client.

Client - Server - Client Estes es un proyecto simple de comunicacion de envios de archivos del cliente al servidor y viceversamente, y de cliente a cl

Melvin RB 1 Jul 16, 2022
Simple mDNS client/server library in Golang

mdns Simple mDNS client/server library in Golang. mDNS or Multicast DNS can be used to discover services on the local network without the use of an au

HashiCorp 932 Jan 4, 2023
Go Beanstalkd Client Library

#gobeanstalk Go Beanstalkd client library. INSTALL go get github.com/iwanbk/gobeanstalk USAGE Producer import ( "github.com/iwanbk/gobeanstalk" "lo

Iwan Budi Kusnanto 63 Jun 15, 2022
🌧 BitTorrent client and library in Go

rain BitTorrent client and library in Go. Running in production at put.io. Features Core protocol Fast extension Magnet links Multiple trackers UDP tr

Cenk Altı 795 Jan 1, 2023
🐈📦 nyaa.si client library for Go. Fetch Anime, Manga, Music and more torrents

?? ?? go-nyaa nyaa.si client library for Go Built on top of: gofeed - search using RSS colly - scrap torrent details page Original idea: ejnshtein/nya

Ilya Revenko 25 Sep 23, 2022