Documentation
¶
Overview ¶
Package auth provides authentication helpers.
Index ¶
- func GetAccessToken(ctx context.Context, _ui ui.UI, fsys afero.Fs, v *viper.Viper, ...) (string, error)
- func GetCSRFToken(ctx context.Context, controlPlaneEndpoint, accessToken string) (string, error)
- func GetCachedIdentityToken(fsys afero.Fs, v *viper.Viper, controlPlaneEndpoint string) string
- func IsRole(token string, role string) bool
- func PKCECallbackURL(port int) string
- func ParseTokenPayloadAsBytes(token string) ([]byte, error)
- func RemoveAccessToken(fsys afero.Fs, v *viper.Viper, controlPlaneEndpoint string) error
- func SetCallbackTimeout(timeout *time.Duration)
- func SetListenPort(port int)
- func SetStateValidator(validator func(string, string) bool)
- type GetAccessTokenParams
- type JWTPayload
- type SASWorkbenchClaims
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetAccessToken ¶
func GetAccessToken( ctx context.Context, _ui ui.UI, fsys afero.Fs, v *viper.Viper, params GetAccessTokenParams, ) (string, error)
GetAccessToken retrieves an access token. The cache is checked first and, if a valid token is not found, the specified auth mode is used to create one.
func GetCSRFToken ¶
GetCSRFToken fetches the CSRF token cookie from postgrest.
func GetCachedIdentityToken ¶
GetCachedIdentityToken returns the cached identity token for the given controlPlaneEndpoint. Returns an empty string if there is no cached identity token.
func PKCECallbackURL ¶
PKCECallbackURL returns the pkce callback url for the given port.
func ParseTokenPayloadAsBytes ¶
ParseTokenPayloadAsBytes parses the payload fo a JWT and returns the raw bytes. If the token is invalid, it returns nil.
func RemoveAccessToken ¶
RemoveAccessToken removes an access token from the token cache.
func SetCallbackTimeout ¶
SetCallbackTimeout sets the length of time that the pkce callback listener waits for an authorization response. Used in tests to override default behavior.
func SetListenPort ¶
func SetListenPort(port int)
SetListenPort sets the pkce callback listen port. Used in tests to override the default behavior.
func SetStateValidator ¶
SetStateValidator sets the function used to validate returned state. Used in tests to override the default behavior.
Types ¶
type GetAccessTokenParams ¶
type GetAccessTokenParams struct {
AuthMode string `json:"authMode,omitempty"`
ClientID string `json:"clientID,omitempty"`
ClientSecret string `json:"-"`
ControlPlaneEndpoint string `json:"endpoint,omitempty"`
IgnoreTokenCache bool `json:"ignoreTokenCache,omitempty"`
IngressHost string `json:"ingressHost,omitempty"`
NoListen bool `json:"noListen,omitempty"`
Organization string `json:"organization,omitempty"`
}
GetAccessTokenParams collects the inputs to GetAccessToken in a struct so they can be addressed by name.
func (*GetAccessTokenParams) NormalizedAuthMode ¶
func (p *GetAccessTokenParams) NormalizedAuthMode() string
NormalizedAuthMode returns the normalized auth mode. Anything other than pkce is returned as device.
type JWTPayload ¶
type JWTPayload struct {
Sas SASWorkbenchClaims `json:"sas"`
Iss string `json:"iss"`
Sub string `json:"sub"`
Iat int `json:"iat"`
Exp int `json:"exp"`
Scope string `json:"scope"`
OrgID string `json:"org_id"`
OrgName string `json:"org_name"`
Azp string `json:"azp"`
Name string `json:"name"`
}
JWTPayload represents the payload of a Workbench JWT.
func ParseTokenPayload ¶
func ParseTokenPayload(token string) (JWTPayload, error)
ParseTokenPayload parses the payload of a JWT token and returns a JWTPayload struct. If the token is invalid, it returns an empty JWTPayload struct.
type SASWorkbenchClaims ¶
type SASWorkbenchClaims struct {
Auth0OrgID string `json:"auth0_org_id"`
Auth0UserID string `json:"auth0_user_id"`
OrgID string `json:"org_id"`
OrgName string `json:"org_name"`
Roles []string `json:"roles"`
UserID string `json:"user_id"`
}
SASWorkbenchClaims are the claims added to Workbench JWTs for Workbench clients.