Documentation ¶
Index ¶
- Constants
- func NewRequestWithContext(ctx context.Context, method, url string, body io.Reader) (*retryablehttp.Request, error)
- type App
- func (app *App) ExportCache(path string) error
- func (app *App) ImportCache(path string) error
- func (app *App) ObtainTokenSourceViaAuthorizationCodeFlow(ctx context.Context, tenantID, clientID, clientSecret, redirectURL string, ...) (oauth2.TokenSource, error)
- func (app *App) ObtainTokenSourceViaClientCredential(ctx context.Context, tenantID string, clientID, clientCredential string, ...) (oauth2.TokenSource, error)
- func (app *App) ObtainTokenSourceViaDeviceFlow(ctx context.Context, tenantID string, clientID string, ...) (oauth2.TokenSource, error)
- type Client
- type ClientCredentialClient
- type DeviceAuthorizationAuth
- type DeviceAuthorizationCallback
- type HTTPClient
- type Token
- type TokenError
Constants ¶
const ( // General error code TokenErrorInvalidRequest = "invalid_request" TokenErrorInvalidClient = "invalid_client" TokenErrorInvalidGrant = "invalid_grant" TokenErrorUnsupportedGrantType = "unsupported_grant_type" TokenErrorInvalidScope = "invalid_scope" // Device flow specific error code TokenErrorAuthorizationPending = "authorization_pending" TokenErrorSlowDown = "slow_down" TokenErrorAccessDenied = "access_denied" TokenErrorExpiredToken = "expired_token" )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type App ¶
type App struct {
// contains filtered or unexported fields
}
func (*App) ExportCache ¶
func (*App) ImportCache ¶
func (*App) ObtainTokenSourceViaAuthorizationCodeFlow ¶
func (*App) ObtainTokenSourceViaClientCredential ¶
func (*App) ObtainTokenSourceViaDeviceFlow ¶
func (app *App) ObtainTokenSourceViaDeviceFlow(ctx context.Context, tenantID string, clientID string, f DeviceAuthorizationCallback, scopes ...string) (oauth2.TokenSource, error)
type Client ¶
type Client interface { // ObtainTokenSource obtains token source in different kinds of grant types ObtainTokenSource(ctx context.Context, t *oauth2.Token) (oauth2.TokenSource, error) // ObtainTokenSource obtains token in different kinds of grant types ObtainToken(ctx context.Context) (*oauth2.Token, error) // ID represents a unique ID of the client from oauth's POV ID() string }
func NewClientViaDeviceFlow ¶
func NewClientViaDeviceFlow(tenantID string, clientID string, f DeviceAuthorizationCallback, scopes ...string) Client
type ClientCredentialClient ¶
type ClientCredentialClient interface { // ObtainTokenSource obtains token source in different kinds of grant types ObtainTokenSource(ctx context.Context) (oauth2.TokenSource, error) }
func NewClientCredentialClient ¶
func NewClientCredentialClient(tenantID string, clientID, clientCredential string, scopes ...string) ClientCredentialClient
NOTE: The value passed for the scope parameter in this request should be the resource identifier (Application ID URI)
of the resource you want, affixed with the .default suffix (See https://docs.microsoft.com/en-us/graph/auth-v2-service#token-request for more details)
type DeviceAuthorizationAuth ¶
type DeviceAuthorizationCallback ¶
type DeviceAuthorizationCallback func(auth DeviceAuthorizationAuth) error
type HTTPClient ¶
type HTTPClient struct {
*retryablehttp.Client
}
func NewHTTPClient ¶
func NewHTTPClient(client *retryablehttp.Client) *HTTPClient
func (*HTTPClient) Do ¶
func (client *HTTPClient) Do(req *retryablehttp.Request, outputPtr interface{}) error
Do will send a general HTTP request and unmarshal the response into `outputPtr`. It returns error if the response status code is not 200.
func (*HTTPClient) DoToken ¶
func (client *HTTPClient) DoToken(req *retryablehttp.Request) (*Token, *TokenError, error)
DoToken is similar to Do, while it is specifically for access token request, in which case client not only care about the successful case, also needs to handle the error response.
On 200, `Token` will be returned with the unmarshalled successful response. (as defined in: https://tools.ietf.org/html/rfc6749#section-5.1) On 400, `TokenError` will be returned with the unmarshalled error response. (as defined in: https://tools.ietf.org/html/rfc6749#section-5.2, with some possible extension,
e.g. https://tools.ietf.org/html/rfc8628#section-3.5)
type Token ¶
type Token struct { AccessToken string `json:"access_token"` TokenType string `json:"token_type"` ExpiresIn int `json:"expires_in"` // "expires_in" is defined as RECOMMENDED, while in MSAUTH it is always returned, hence defined as `int` RefreshToken string `json:"refresh_token"` }
Token is defined at: https://tools.ietf.org/html/rfc6749#section-5.1
func (Token) ToOauth2Token ¶
type TokenError ¶
type TokenError struct { Error string `json:"error"` ErrorDescription *string `json:"error_description"` ErrorURI *string `json:"error_uri"` }
func (TokenError) String ¶
func (e TokenError) String() string