oauth

package
v0.7.1-0...-e6f8ddd Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2021 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidProfile = errors.New("invalid profile")

ErrInvalidProfile is thrown when a profile is missing or invalid.

Functions

func TokenHandler

func TokenHandler(source oauth2.TokenSource, key string, request *http.Request) error

TokenHandler takes a token source, gets a token, and modifies a request to add the token auth as a header. Uses the CLI cache to store tokens on a per- profile basis between runs.

Types

type AuthorizationCodeHandler

type AuthorizationCodeHandler struct{}

AuthorizationCodeHandler sets up the OAuth 2.0 authorization code with PKCE authentication flow.

func (*AuthorizationCodeHandler) OnRequest

func (h *AuthorizationCodeHandler) OnRequest(request *http.Request, key string, params map[string]string) error

OnRequest gets run before the request goes out on the wire.

func (*AuthorizationCodeHandler) Parameters

func (h *AuthorizationCodeHandler) Parameters() []cli.AuthParam

Parameters returns a list of OAuth2 Authorization Code inputs.

type AuthorizationCodeTokenSource

type AuthorizationCodeTokenSource struct {
	ClientID       string
	ClientSecret   string
	AuthorizeURL   string
	TokenURL       string
	EndpointParams *url.Values
	Scopes         []string
}

AuthorizationCodeTokenSource with PKCE as described in: https://www.oauth.com/oauth2-servers/pkce/ This works by running a local HTTP server on port 8484 and then having the user log in through a web browser, which redirects to the local server with an authorization code. That code is then used to make another HTTP request to fetch an auth token (and refresh token). That token is then in turn used to make requests against the API.

func (*AuthorizationCodeTokenSource) Token

Token generates a new token using an authorization code.

type ClientCredentialsHandler

type ClientCredentialsHandler struct{}

ClientCredentialsHandler implements the Client Credentials OAuth2 flow.

func (*ClientCredentialsHandler) OnRequest

func (h *ClientCredentialsHandler) OnRequest(request *http.Request, key string, params map[string]string) error

OnRequest gets run before the request goes out on the wire.

func (*ClientCredentialsHandler) Parameters

func (h *ClientCredentialsHandler) Parameters() []cli.AuthParam

Parameters returns a list of OAuth2 Authorization Code inputs.

type RefreshTokenSource

type RefreshTokenSource struct {
	// ClientID of the application
	ClientID string

	// TokenURL is used to fetch new tokens
	TokenURL string

	// EndpointParams are extra URL query parameters to include in the request
	EndpointParams *url.Values

	// RefreshToken from a cache, if available. If not, then the first time a
	// token is requested it will be loaded from the token source and this value
	// will get updated if it's present in the returned token.
	RefreshToken string

	// TokenSource to wrap to fetch new tokens if the refresh token is missing or
	// did not work to get a new token.
	TokenSource oauth2.TokenSource
}

RefreshTokenSource will use a refresh token to try and get a new token before calling the original token source to get a new token.

func (RefreshTokenSource) Token

func (ts RefreshTokenSource) Token() (*oauth2.Token, error)

Token generates a new token using either a refresh token or by falling back to the original source.

Jump to

Keyboard shortcuts

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