auth

package
v0.6.95 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2022 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// namespace used to set/get values from the keychain.
	SecNamespace = "auth0-cli"
)

Variables

This section is empty.

Functions

func ErrorIfBadHTTP added in v0.6.7

func ErrorIfBadHTTP(r *http.Response, exceptStatus ...int) error

func IsAuthError added in v0.6.26

func IsAuthError(err error) bool

func IsError added in v0.6.7

func IsError(statusCode int) bool

IsError method returns true if HTTP status `code >= 400` otherwise false.

func RequiredScopes

func RequiredScopes() []string

RequiredScopes returns the scopes used for login.

func RequiredScopesMin

func RequiredScopesMin() []string

RequiredScopesMin returns minimum scopes used for login in integration tests.

Types

type Auth

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

func NewAuth

func NewAuth(authStore AuthStore, oauth OAuth) *Auth

func (Auth) GetFreshAccessTokenOrLogin

func (t Auth) GetFreshAccessTokenOrLogin() (string, error)

Gets fresh access token and prompts for login and saves to store

func (Auth) GetFreshAccessTokenOrNil

func (t Auth) GetFreshAccessTokenOrNil() (string, error)

Gets fresh access token or returns nil and saves to store

func (Auth) Login

func (t Auth) Login(skipBrowser bool) (*LoginTokens, error)

func (Auth) LoginWithToken added in v0.6.63

func (t Auth) LoginWithToken(token string) error

func (Auth) Logout

func (t Auth) Logout() error

func (Auth) PromptForLogin

func (t Auth) PromptForLogin() (*LoginTokens, error)

Prompts for login and returns tokens, and saves to store

func (*Auth) WithAccessTokenValidator added in v0.4.3

func (t *Auth) WithAccessTokenValidator(val func(string) (bool, error)) *Auth

type AuthError added in v0.6.16

type AuthError struct {
	// https://auth0.com/docs/api/authentication#standard-error-responses
	Error            string `json:"error"`
	ErrorDescription string `json:"error_description"`
}

type AuthStore

type AuthStore interface {
	SaveAuthTokens(tokens entity.AuthTokens) error
	GetAuthTokens() (*entity.AuthTokens, error)
	DeleteAuthTokens() error
}

type Authenticator

type Authenticator struct {
	Audience           string
	ClientID           string
	DeviceCodeEndpoint string
	OauthTokenEndpoint string
}

func (Authenticator) DoDeviceAuthFlow

func (a Authenticator) DoDeviceAuthFlow(onStateRetrieved func(url string, code string)) (*LoginTokens, error)

func (*Authenticator) Start

func (a *Authenticator) Start(ctx context.Context) (State, error)

Start kicks-off the device authentication flow by requesting a device code from Auth0, The returned state contains the URI for the next step of the flow.

func (*Authenticator) Wait

func (a *Authenticator) Wait(ctx context.Context, state State) (Result, error)

Wait waits until the user is logged in on the browser.

type LoginAuth

type LoginAuth struct {
	Auth
}

func NewLoginAuth

func NewLoginAuth(authStore AuthStore, oauth OAuth) *LoginAuth

func (LoginAuth) GetAccessToken

func (l LoginAuth) GetAccessToken() (string, error)

type LoginTokens

type LoginTokens struct {
	entity.AuthTokens
	IDToken string
}

type NoLoginAuth

type NoLoginAuth struct {
	Auth
}

func NewNoLoginAuth

func NewNoLoginAuth(authStore AuthStore, oauth OAuth) *NoLoginAuth

func (NoLoginAuth) GetAccessToken

func (l NoLoginAuth) GetAccessToken() (string, error)

type OAuth

type OAuth interface {
	DoDeviceAuthFlow(onStateRetrieved func(url string, code string)) (*LoginTokens, error)
	GetNewAuthTokensWithRefresh(refreshToken string) (*entity.AuthTokens, error)
}

type Result

type Result struct {
	Tenant       string
	Domain       string
	RefreshToken string
	AccessToken  string
	IDToken      string
	ExpiresIn    int64
}

type State

type State struct {
	DeviceCode      string `json:"device_code"`
	UserCode        string `json:"user_code"`
	VerificationURI string `json:"verification_uri_complete"`
	ExpiresIn       int    `json:"expires_in"`
	Interval        int    `json:"interval"`
}

func (*State) IntervalDuration

func (s *State) IntervalDuration() time.Duration

type StdHTTPResponseError added in v0.6.16

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

func NewHTTPResponseError added in v0.6.16

func NewHTTPResponseError(response *http.Response) *StdHTTPResponseError

func (StdHTTPResponseError) Error added in v0.6.16

func (e StdHTTPResponseError) Error() string

Jump to

Keyboard shortcuts

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