tokenrequest

package
v0.0.0-...-6018a90 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2024 License: Apache-2.0 Imports: 21 Imported by: 2

Documentation

Index

Constants

View Source
const (

	// BasicAuthNoUsernameMessage will differentiate unauthorized errors from basic login with no username
	BasicAuthNoUsernameMessage = "BasicChallengeNoUsername"
)

Variables

This section is empty.

Functions

func RequestTokenWithChallengeHandlers

func RequestTokenWithChallengeHandlers(clientCfg *restclient.Config, challengeHandlers ...challengehandlers.ChallengeHandler) (string, error)

RequestTokenWithChallengeHandlers uses the cmd arguments to locate an openshift oauth server and attempts to authenticate with the OAuth code flow and challenge handling. It returns the access token if it gets one or an error if it does not.

func RequestTokenWithLocalCallback

func RequestTokenWithLocalCallback(clientCfg *restclient.Config, authzURLHandler AuthorizationURLHandlerFunc, callbackPort int) (string, error)

RequestTokenWithLocalCallback will perform the OAuth authorization code grant flow to obtain an access token. authzURLHandler is used to forward the user to the OAuth server's parametrized authorization URL to retrieve the authorization code. It starts a localhost server on port `callbackPort` (random port if unspecified) to exchange the authorization code for an access token.

Types

type AuthorizationURLHandlerFunc

type AuthorizationURLHandlerFunc func(url *url.URL) error

type RequestTokenOptions

type RequestTokenOptions struct {
	ClientConfig *restclient.Config
	Handler      challengehandlers.ChallengeHandler
	OsinConfig   *osincli.ClientConfig
	Issuer       string
	TokenFlow    bool

	// AuthorizationURLHandler defines how the authorization URL of the OAuth Code Grant flow
	// should be handled; for example use this function to take the URL and open it in a browser
	AuthorizationURLHandler AuthorizationURLHandlerFunc

	// LocalCallbackServer receives the callback once the user authorizes the request
	// as a redirect from the OAuth server, and exchanges the authorization code for an access token
	LocalCallbackServer *callbackServer
}

func NewRequestTokenOptions

func NewRequestTokenOptions(
	clientCfg *restclient.Config,
	tokenFlow bool,
) *RequestTokenOptions

func (*RequestTokenOptions) RequestToken

func (o *RequestTokenOptions) RequestToken() (string, error)

RequestToken decides on how to perform the token request based on the configured RequestTokenOptions object and performs the request. It returns the access token if it gets one, or an error if it does not. It should only be invoked once on a given RequestTokenOptions instance.

func (*RequestTokenOptions) SetDefaultOsinConfig

func (o *RequestTokenOptions) SetDefaultOsinConfig(clientID string, redirectURL *string) error

SetDefaultOsinConfig overwrites RequestTokenOptions.OsinConfig with the default CLI OAuth client and PKCE support if the server supports S256 / a code flow is being used

func (*RequestTokenOptions) WithChallengeHandlers

func (o *RequestTokenOptions) WithChallengeHandlers(challengeHandlers ...challengehandlers.ChallengeHandler) (*RequestTokenOptions, error)

WithChallengeHandlers sets up the RequestTokenOptions with the provided challengeHandlers to be used in the OAuth code flow. If RequestTokenOptions.OsinConfig is nil, it will be defaulted using SetDefaultOsinConfig. The caller is responsible for setting up the entire OsinConfig if the value is not nil.

func (*RequestTokenOptions) WithLocalCallback

func (o *RequestTokenOptions) WithLocalCallback(handleAuthzURL AuthorizationURLHandlerFunc, localCallbackPort int) (*RequestTokenOptions, error)

WithLocalCallback sets up the RequestTokenOptions with an AuthorizationURLHanderFunc and an unstarted local callback server on the specified port. If RequestTokenOptions.OsinConfig is nil, it will be defaulted using SetDefaultOsinConfig. The caller is responsible for setting up the entire OsinConfig if the value is not nil.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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