authenticator

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoPrinter        = errors.New("printer is required for device code flow")
	ErrFlowNotSupported = errors.New("unsupported authentication flow")
	ErrNoAccounts       = errors.New("no accounts found")
	ErrTokenExpired     = errors.New("token has expired")
	ErrDeclinedScopes   = errors.New("scopes have been declined")
)

Functions

This section is empty.

Types

type Authenticator

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

func NewAuthenticator

func NewAuthenticator(config Config, options ...Option) *Authenticator

NewAuthenticator creates a new authenticator with the given configuration.

func (*Authenticator) Authenticate

func (a *Authenticator) Authenticate(ctx context.Context) (public.AuthResult, error)

Authenticate initiates the authentication flow. If the user is already authenticated, the cached token is used. If the user is not authenticated, the user is prompted to authenticate using the configured flow.

func (*Authenticator) GetCurrentAccount

func (a *Authenticator) GetCurrentAccount(ctx context.Context) (public.Account, error)

func (*Authenticator) IsAuthenticated

func (a *Authenticator) IsAuthenticated(ctx context.Context) (bool, error)

IsAuthenticated checks if the user is authenticated by checking if there are any cached accounts.

type Config

type Config struct {
	ClientID    string
	Authority   string
	Scopes      []string
	RedirectURI string
}

func ConfigFromBuildProps

func ConfigFromBuildProps() Config

type Flow

type Flow int
const (
	FlowInteractive Flow = iota
	FlowDeviceCode
)

type Option

type Option func(authenticator *Authenticator)

func WithDeviceCodeFlow

func WithDeviceCodeFlow(printer Printer) Option

WithDeviceCodeFlow configures the authenticator to use the device code flow for authentication. The printer is used to display the device code message to the user.

func WithTokenCache

func WithTokenCache(cache cache.ExportReplace) Option

WithTokenCache configures the authenticator to use a custom token cache.

type Printer

type Printer func(ctx context.Context, message string) error

Jump to

Keyboard shortcuts

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