oauth

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ParamError            = "error"
	ParamErrorDescription = "error_description"
	ParamMinVersion       = "min_version"
	ParamClientVersion    = "client_version"
	ParamLocalPort        = "local_port"
)

Variables

View Source
var (
	ErrInvalidState       = errors.New("invalid state parameter")
	ErrMissingAuthCode    = errors.New("missing authorization code")
	ErrMissingAccessToken = errors.New("missing access_token")
)
View Source
var (
	ErrNoToken      = errors.New("no token found - please authenticate first")
	ErrTokenExpired = errors.New("token expired and no refresh token available")
)

Functions

func GenerateState

func GenerateState() (string, error)

func NewConfig

func NewConfig(provider ConfigProvider) *oauth2.Config

func ValidateState

func ValidateState(expected string, received string) bool

Types

type AuthResult

type AuthResult struct {
	Token  *oauth2.Token
	APIKey string
}

type ConfigProvider

type ConfigProvider interface {
	GetClientID() string
	GetClientSecret() string
	GetRedirectURL() string
}

type DBTokenSource

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

DBTokenSource implements TokenSource using SQLite for metadata and OS keyring for secrets.

func NewDBTokenSource

func NewDBTokenSource(config *oauth2.Config, querier sqlitec.Querier, kr keyring.Store) *DBTokenSource

func (*DBTokenSource) ExpiresWithin

func (s *DBTokenSource) ExpiresWithin(ctx context.Context, d time.Duration) (bool, error)

func (*DBTokenSource) GetAPIKey added in v0.1.3

func (s *DBTokenSource) GetAPIKey() (string, error)

func (*DBTokenSource) HasToken

func (s *DBTokenSource) HasToken(ctx context.Context) (bool, error)

func (*DBTokenSource) RefreshIfNeeded

func (s *DBTokenSource) RefreshIfNeeded(ctx context.Context, threshold time.Duration) (*oauth2.Token, error)

func (*DBTokenSource) SaveAPIKey added in v0.1.3

func (s *DBTokenSource) SaveAPIKey(apiKey string) error

func (*DBTokenSource) Token

func (s *DBTokenSource) Token() (*oauth2.Token, error)

type DirectFlow

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

func NewDirectFlow

func NewDirectFlow(config *oauth2.Config, querier sqlitec.Querier, kr keyring.Store) (*DirectFlow, error)

func (*DirectFlow) Run

func (f *DirectFlow) Run(ctx context.Context) (*AuthResult, error)

type ErrorCode

type ErrorCode string
const (
	ErrorCodeIncompatibleVersion ErrorCode = "incompatible_version"
	ErrorCodeAccessDenied        ErrorCode = "access_denied"
	ErrorCodeInvalidRequest      ErrorCode = "invalid_request"
	ErrorCodeAccountBanned       ErrorCode = "account_banned"
	ErrorCodeRateLimited         ErrorCode = "rate_limited"
)

type Flow

type Flow interface {
	Run(ctx context.Context) (*AuthResult, error)
}

type ProxyTokenSource

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

ProxyTokenSource implements oauth2.TokenSource and TokenChecker, refreshing tokens via the server's /auth/refresh endpoint. Secrets are stored in the OS keyring, metadata in SQLite.

func NewProxyTokenSource

func NewProxyTokenSource(serverURL string, querier sqlitec.Querier, kr keyring.Store) *ProxyTokenSource

func (*ProxyTokenSource) ExpiresWithin

func (s *ProxyTokenSource) ExpiresWithin(ctx context.Context, d time.Duration) (bool, error)

func (*ProxyTokenSource) GetAPIKey added in v0.1.3

func (s *ProxyTokenSource) GetAPIKey() (string, error)

func (*ProxyTokenSource) HasToken

func (s *ProxyTokenSource) HasToken(ctx context.Context) (bool, error)

func (*ProxyTokenSource) RefreshIfNeeded

func (s *ProxyTokenSource) RefreshIfNeeded(ctx context.Context, threshold time.Duration) (*oauth2.Token, error)

func (*ProxyTokenSource) SaveAPIKey added in v0.1.3

func (s *ProxyTokenSource) SaveAPIKey(apiKey string) error

func (*ProxyTokenSource) Token

func (s *ProxyTokenSource) Token() (*oauth2.Token, error)

type ServerFlow

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

func NewServerFlow

func NewServerFlow(serverURL string, querier sqlitec.Querier, kr keyring.Store) *ServerFlow

func (*ServerFlow) Run

func (f *ServerFlow) Run(ctx context.Context) (*AuthResult, error)

type TokenChecker

type TokenChecker interface {
	HasToken(ctx context.Context) (bool, error)
}

type TokenSource

type TokenSource interface {
	oauth2.TokenSource
	TokenChecker
	RefreshIfNeeded(ctx context.Context, threshold time.Duration) (*oauth2.Token, error)
}

TokenSource combines oauth2.TokenSource with token management capabilities.

Jump to

Keyboard shortcuts

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