msauth

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2023 License: MPL-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// General error code
	TokenErrorInvalidRequest       = "invalid_request"
	TokenErrorInvalidClient        = "invalid_client"
	TokenErrorInvalidGrant         = "invalid_grant"
	TokenErrorUnauthorizedClient   = "unauthorized_client"
	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

func NewRequestWithContext

func NewRequestWithContext(ctx context.Context, method, url string, body io.Reader) (*retryablehttp.Request, error)

Types

type App

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

func NewApp

func NewApp() *App

func (*App) ExportCache

func (app *App) ExportCache(path string) error

func (*App) ImportCache

func (app *App) ImportCache(path string) error

func (*App) ObtainTokenSourceViaAuthorizationCodeFlow

func (app *App) ObtainTokenSourceViaAuthorizationCodeFlow(ctx context.Context, tenantID, clientID, clientSecret, redirectURL string, scopes ...string) (oauth2.TokenSource, error)

func (*App) ObtainTokenSourceViaClientCredential

func (app *App) ObtainTokenSourceViaClientCredential(ctx context.Context, tenantID string, clientID, clientCredential string, scopes ...string) (oauth2.TokenSource, error)

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 NewClientViaAuthorizationCodeFlow

func NewClientViaAuthorizationCodeFlow(tenantID, clientID, clientSecret, redirectURL string, scopes ...string) Client

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 DeviceAuthorizationAuth struct {
	DeviceCode              string  `json:"device_code"`
	UserCode                string  `json:"user_code"`
	VerificationURI         string  `json:"verification_uri"`
	VerificationURIComplete *string `json:"verification_uri_complete"`
	ExpiresIn               int     `json:"expires_in"`
	Interval                *int    `json:"interval"`
}

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

func (t Token) ToOauth2Token() *oauth2.Token

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

Jump to

Keyboard shortcuts

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