GraphClient

package module
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 8, 2022 License: Apache-2.0 Imports: 11 Imported by: 0

README

Microsoft-Graph-SDK-go

Microsoft Graph SDK for Golang(Unofficial)

You can:

1.Get Authenticated easily

2.Manage AccessTokens and RefreshTokens automatically(Auto refresh)

3.Do Request to Microsoft Graph endpoints easily

Inspired by official NodeJS SDK.

You can find more by reading Documents in Doc folder.

中文简介:

个人编写的Microsoft Graph客户端

你可以:
1.通过Auth很容易的登录

2.自动管理令牌和刷新令牌(令牌到期自动刷新)

3.内置的Client可以让您很容易的连接到Microsoft Graph 服务

本包的思想基于官方的NodeJS SDK

您可以在Doc文件夹阅读详情

Documentation

Index

Constants

View Source
const (
	ApiVersion10   = "v1.0"
	ApiVersionBeta = "beta"

	EndpointInternational = "graph.microsoft.com"
	EndpointChina         = "microsoftgraph.chinacloudapi.cn"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Auth

type Auth struct {
	Tenant       string
	ClientId     string
	ClientSecret string
	RedirectUrl  string
	Scopes       []string
	ResponseMode string
	TokenCache   ITokenCache
	ApiVersion   string
	Endpoint     string
}

func (*Auth) GetAccessToken

func (t *Auth) GetAccessToken(code string) (string, error)

GetAccessToken Stores user AccessToken and RefreshToken to TokenStore

returns User's HomeAccountId

func (*Auth) GetAuthUrl

func (t *Auth) GetAuthUrl(state string) string

func (*Auth) GetValidateToken

func (t *Auth) GetValidateToken(token Token) (Token, error, bool)

func (*Auth) Logout added in v0.0.3

func (t *Auth) Logout(HomeAccountId string) error

func (*Auth) RefreshAccessToken

func (t *Auth) RefreshAccessToken(token Token) (Token, error)

type AuthBuilder

type AuthBuilder struct {
	// contains filtered or unexported fields
}

func NewAuthBuilder added in v1.0.0

func NewAuthBuilder() *AuthBuilder

NewAuthBuilder Create a new builder

func (*AuthBuilder) Build

func (t *AuthBuilder) Build() (*Auth, error)

func (*AuthBuilder) WithApiVersion added in v1.0.0

func (t *AuthBuilder) WithApiVersion(apiVersion string) *AuthBuilder

func (*AuthBuilder) WithClientId

func (t *AuthBuilder) WithClientId(ClientId string) *AuthBuilder

func (*AuthBuilder) WithClientSecret

func (t *AuthBuilder) WithClientSecret(ClientSecret string) *AuthBuilder

func (*AuthBuilder) WithCustomTokenCache

func (t *AuthBuilder) WithCustomTokenCache(TokenCache ITokenCache) *AuthBuilder

func (*AuthBuilder) WithEndpoint added in v1.0.0

func (t *AuthBuilder) WithEndpoint(endpointLocation string) *AuthBuilder

func (*AuthBuilder) WithRedirectUrl

func (t *AuthBuilder) WithRedirectUrl(RedirectUrl string) *AuthBuilder

func (*AuthBuilder) WithResponseMode

func (t *AuthBuilder) WithResponseMode(ResponseMode string) *AuthBuilder

func (*AuthBuilder) WithScopes

func (t *AuthBuilder) WithScopes(Scopes []string) *AuthBuilder

func (*AuthBuilder) WithTenant

func (t *AuthBuilder) WithTenant(Tenant string) *AuthBuilder

type Client

type Client struct {
	HomeAccountId string
	TokenCache    ITokenCache
	AuthClient    *Auth
}

func GetClient

func GetClient(auth *Auth, HomeAccountId string, tokenCache ...ITokenCache) *Client

GetClient

Get a *Client

HomeAccountId can be set to "",but should be set by WithHomeAccountId()

func (*Client) Request

func (t *Client) Request(method string, path string, body []byte, header *map[string][]string, query *map[string][]string) (*GraphResponse, error)

Request

method:HTTP method used to request

path: e.g.:https://graph.microsoft.com/v1.0/me => /me

body: Set "" when method is GET, otherwise you will get an error

header:Optional.Set custom headers by it.

func (*Client) WithHomeAccountId

func (t *Client) WithHomeAccountId(HomeAccountId string) *Client

WithHomeAccountId

Set HomeAccountId.

If you set it when create Client, previous will be override.

type DefaultTokenCache

type DefaultTokenCache struct {
	// contains filtered or unexported fields
}

func (*DefaultTokenCache) Delete added in v0.0.3

func (t *DefaultTokenCache) Delete(HomeAccountId string) error

func (*DefaultTokenCache) Get

func (t *DefaultTokenCache) Get(HomeAccountId string) *Token

func (*DefaultTokenCache) Set

func (t *DefaultTokenCache) Set(HomeAccountId string, token Token) error

type GraphResponse

type GraphResponse struct {
	Body        string
	RawBody     []byte
	Headers     http.Header
	RawResponse *http.Response
}

func (*GraphResponse) GetJson

func (t *GraphResponse) GetJson() gjson.Result

func (*GraphResponse) ToJson

func (t *GraphResponse) ToJson() (map[string]interface{}, error)

type ITokenCache

type ITokenCache interface {
	Get(HomeAccountId string) *Token
	Set(HomeAccountId string, token Token) error
	Delete(HomeAccountId string) error
}

type Token

type Token struct {
	AccessToken  string
	Expires      int64
	RefreshToken string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL