auth

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package auth handles authentication and OAuth flows.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrStoreUnavailable = errors.New("credential storage unavailable")
	ErrConfigMismatch   = errors.New("authentication configuration mismatch")

	// ErrAuthRequired indicates that authentication is required.
	ErrAuthRequired = errors.New("authentication required")

	// ErrInvalidInput indicates invalid input to an auth function.
	ErrInvalidInput = errors.New("invalid input")
)

Functions

func ErrorMessage

func ErrorMessage(err error) string

ErrorMessage removes classification sentinels from user-facing diagnostics.

func GeneratePKCE

func GeneratePKCE() (*pkceParams, error)

GeneratePKCE generates new PKCE parameters for an OAuth flow.

func NewCallbackServer

func NewCallbackServer(ctx context.Context, path string) (*callbackServer, error)

NewCallbackServer creates a new callback server.

func NewOAuthClient

func NewOAuthClient(cfg *config.OAuthConfig) *oauthClient

NewOAuthClient creates a new OAuth client.

func OpenBrowser

func OpenBrowser(ctx context.Context, urlStr string) error

OpenBrowser opens a URL in the user's default browser.

Types

type FileStore

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

FileStore stores OAuth credentials separately from ordinary configuration.

func (*FileStore) DeleteToken

func (s *FileStore) DeleteToken() error

func (*FileStore) LoadToken

func (s *FileStore) LoadToken() (*Token, error)

func (*FileStore) LoadTokenForLogout

func (s *FileStore) LoadTokenForLogout() (*Token, error)

func (*FileStore) Path

func (s *FileStore) Path() string

func (*FileStore) PrepareLogin

func (s *FileStore) PrepareLogin() error

PrepareLogin rejects known storage failures before browser authentication. The temporary probe does not replace existing credentials.

func (*FileStore) SaveToken

func (s *FileStore) SaveToken(token *Token) error

func (*FileStore) Source

func (s *FileStore) Source() string

type IntrospectResponse

type IntrospectResponse struct {
	Active   bool   `json:"active"`
	Username string `json:"username,omitempty"`
	Scope    string `json:"scope,omitempty"`
	Exp      int64  `json:"exp,omitempty"`
	Iat      int64  `json:"iat,omitempty"`
}

IntrospectResponse represents the token introspection response.

type Store

type Store interface {
	LoadToken() (*Token, error)
	SaveToken(*Token) error
	DeleteToken() error
	Source() string
}

Store is the selected credential source. Environment credentials are read-only.

func NewStore

func NewStore() (Store, error)

NewStore resolves environment credentials before the configured persistent store.

type Token

type Token struct {
	// External tokens have no local expiry or refresh metadata.
	External     bool      `json:"-"`
	AccessToken  string    `json:"access_token"`
	RefreshToken string    `json:"refresh_token,omitempty"`
	TokenType    string    `json:"token_type"`
	ExpiresAt    time.Time `json:"expires_at"`
	Scope        string    `json:"scope,omitempty"`
	IssuedAt     time.Time `json:"issued_at"`
	BaseURL      string    `json:"base_url"`
}

Token represents an OAuth token with expiry information.

func RequireAuthFrom

func RequireAuthFrom(store Store) (*Token, error)

RequireAuthFrom loads credentials and checks their configured destination.

func (*Token) IsExpired

func (t *Token) IsExpired() bool

IsExpired checks if the token has expired, accounting for clock skew.

func (*Token) IsExpiringSoon

func (t *Token) IsExpiringSoon(within time.Duration) bool

IsExpiringSoon checks if the token will expire within the given duration.

func (*Token) TimeUntilExpiry

func (t *Token) TimeUntilExpiry() time.Duration

TimeUntilExpiry returns the duration until the token expires.

type WritableStore

type WritableStore interface {
	Store
	PrepareLogin() error
	LoadTokenForLogout() (*Token, error)
}

WritableStore supports the persistent authentication lifecycle. Logout may read an insecure regular file solely to revoke its credentials.

func NewWritableStore

func NewWritableStore() (WritableStore, error)

NewWritableStore selects persistent storage without relying on display labels.

Jump to

Keyboard shortcuts

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