auth

package
v0.1.8 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidPort         = errors.New("invalid local port")
	ErrInvalidState        = errors.New("invalid or expired state")
	ErrIncompatibleVersion = errors.New("incompatible client version")
	ErrRateLimited         = errors.New("rate limit exceeded")
	ErrAccountBanned       = errors.New("account banned")
	ErrAuthDenied          = errors.New("authorization denied")
	ErrInvalidRefreshToken = errors.New("invalid or missing refresh token")
	ErrRefreshFailed       = errors.New("token refresh failed")
)

Functions

This section is empty.

Types

type AuthError

type AuthError struct {
	Err       error
	LocalPort string
	ErrorCode string
	ErrorDesc string
	Extra     map[string]string
}

func (*AuthError) Error

func (e *AuthError) Error() string

func (*AuthError) Unwrap

func (e *AuthError) Unwrap() error

type CallbackRequest

type CallbackRequest struct {
	State     string
	Code      string
	ErrorCode string
	ErrorDesc string
}

type CallbackResult

type CallbackResult struct {
	Token     *oauth2.Token
	APIKey    string
	LocalPort string
}

type OAuth

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

func NewOAuth

func NewOAuth(
	oauthConfig *oauth2.Config,
	stateStore storage.StateStore,
	userService user.Service,
	whoopLimiter storage.WhoopRateLimiter,
) *OAuth

func (*OAuth) HandleCallback

func (s *OAuth) HandleCallback(ctx context.Context, req CallbackRequest) (*CallbackResult, error)

func (*OAuth) RefreshToken

func (s *OAuth) RefreshToken(ctx context.Context, req RefreshRequest) (*RefreshResult, error)

func (*OAuth) StartAuth

func (s *OAuth) StartAuth(ctx context.Context, req StartAuthRequest) (*StartAuthResult, error)

type RefreshRequest

type RefreshRequest struct {
	RefreshToken string
}

type RefreshResult

type RefreshResult struct {
	Token *oauth2.Token
}

type Service

type Service interface {
	// StartAuth validates the request, stores state, and returns the auth URL.
	// Returns ErrInvalidPort if the local port is invalid.
	// Returns *VersionError (wrapping ErrIncompatibleVersion) if version check fails.
	StartAuth(ctx context.Context, req StartAuthRequest) (*StartAuthResult, error)

	// HandleCallback processes the OAuth callback.
	// Returns ErrInvalidState if state is missing or invalid.
	// Returns ErrAuthDenied if WHOOP denied authorization.
	// Returns ErrRateLimited if rate limited.
	// Returns ErrAccountBanned if the user is banned.
	// The returned *AuthError contains LocalPort for redirect construction.
	HandleCallback(ctx context.Context, req CallbackRequest) (*CallbackResult, error)

	// RefreshToken exchanges a refresh token for new access and refresh tokens.
	// Returns ErrInvalidRefreshToken if refresh token is missing.
	// Returns ErrRefreshFailed if the token exchange fails.
	RefreshToken(ctx context.Context, req RefreshRequest) (*RefreshResult, error)
}

type StartAuthRequest

type StartAuthRequest struct {
	LocalPort     string
	ClientVersion string
}

type StartAuthResult

type StartAuthResult struct {
	AuthURL string
}

type VersionError

type VersionError struct {
	MinVersion string
}

func (*VersionError) Error

func (e *VersionError) Error() string

func (*VersionError) Unwrap

func (e *VersionError) Unwrap() error

Jump to

Keyboard shortcuts

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