auth

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: Apache-2.0 Imports: 29 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package auth provides authentication helpers.

Index

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

func GetCSRFToken(
	ctx context.Context,
	controlPlaneEndpoint,
	accessToken string,
) (string, error)

GetCSRFToken fetches the CSRF token cookie from postgrest.

func GetCachedIdentityToken

func GetCachedIdentityToken(
	fsys afero.Fs,
	v *viper.Viper,
	controlPlaneEndpoint string,
) string

GetCachedIdentityToken returns the cached identity token for the given controlPlaneEndpoint. Returns an empty string if there is no cached identity token.

func IsRole

func IsRole(
	token string,
	role string,
) bool

IsRole reports whether the JWTPayload contains the requested role.

func PKCECallbackURL

func PKCECallbackURL(port int) string

PKCECallbackURL returns the pkce callback url for the given port.

func ParseTokenPayloadAsBytes

func ParseTokenPayloadAsBytes(token string) ([]byte, error)

ParseTokenPayloadAsBytes parses the payload fo a JWT and returns the raw bytes. If the token is invalid, it returns nil.

func RemoveAccessToken

func RemoveAccessToken(
	fsys afero.Fs,
	v *viper.Viper,
	controlPlaneEndpoint string,
) error

RemoveAccessToken removes an access token from the token cache.

func SetCallbackTimeout

func SetCallbackTimeout(timeout *time.Duration)

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

func SetStateValidator(validator func(string, string) bool)

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.

Jump to

Keyboard shortcuts

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