auth

package
v0.2.82 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTokenExpired     = errors.New("token has expired")
	ErrTokenRevoked     = errors.New("token has been revoked")
	ErrTokenInvalid     = errors.New("token is invalid")
	ErrTokenMalformed   = errors.New("token is malformed")
	ErrRefreshFailed    = errors.New("token refresh failed")
	ErrNotAuthenticated = errors.New("not authenticated")
	ErrAuthExpired      = errors.New("authentication expired")
)

Authentication error types

Functions

func GenerateRandomState

func GenerateRandomState() (string, error)

GenerateRandomState generates a random state parameter for CSRF protection

func GetAuthErrorType added in v0.2.9

func GetAuthErrorType(err error) string

GetAuthErrorType returns the type of authentication error

func GetPlatformName

func GetPlatformName() string

GetPlatformName returns a human-readable platform name

func GetUserFriendlyMessage added in v0.2.9

func GetUserFriendlyMessage(err error) string

GetUserFriendlyMessage returns a user-friendly error message

func IsBrowserAvailable

func IsBrowserAvailable() bool

IsBrowserAvailable checks if a browser is available on the system

func IsRefreshFailed added in v0.2.9

func IsRefreshFailed(err error) bool

IsRefreshFailed checks if the error indicates refresh failure

func IsTokenExpired added in v0.2.9

func IsTokenExpired(err error) bool

IsTokenExpired checks if the error indicates token expiration

func IsTokenInvalid added in v0.2.9

func IsTokenInvalid(err error) bool

IsTokenInvalid checks if the error indicates an invalid token

func IsTokenRevoked added in v0.2.9

func IsTokenRevoked(err error) bool

IsTokenRevoked checks if the error indicates token revocation

func OpenBrowser

func OpenBrowser(url string) error

OpenBrowser opens the default browser to the specified URL

Types

type AuthError added in v0.2.9

type AuthError struct {
	Type    string `json:"type"`
	Message string `json:"message"`
	Code    int    `json:"code,omitempty"`
	Err     error  `json:"-"`
}

AuthError represents an authentication error with additional context

func NewAuthError added in v0.2.9

func NewAuthError(errType string, message string, code int, err error) *AuthError

NewAuthError creates a new authentication error

func (*AuthError) Error added in v0.2.9

func (e *AuthError) Error() string

Error implements the error interface

func (*AuthError) Unwrap added in v0.2.9

func (e *AuthError) Unwrap() error

Unwrap returns the underlying error

type OAuthCallbackResult

type OAuthCallbackResult struct {
	Code  string
	Token string // Direct token if server returns it
	Error error
}

OAuthCallbackResult represents the result of OAuth callback

type PKCEChallenge

type PKCEChallenge struct {
	CodeVerifier  string
	CodeChallenge string
	Method        string
}

PKCEChallenge represents a PKCE code challenge and verifier pair

func GeneratePKCEChallenge

func GeneratePKCEChallenge() (*PKCEChallenge, error)

GeneratePKCEChallenge creates a new PKCE challenge according to RFC 7636

func (*PKCEChallenge) Verify

func (p *PKCEChallenge) Verify(verifier string) bool

Verify checks if the given verifier matches this challenge

type PKCEOAuthService

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

PKCEOAuthService handles OAuth2 authentication with PKCE

func NewPKCEOAuthService

func NewPKCEOAuthService(cfg *config.Config) *PKCEOAuthService

NewPKCEOAuthService creates a new PKCE OAuth service

func (*PKCEOAuthService) GetAccessToken

func (s *PKCEOAuthService) GetAccessToken() string

GetAccessToken returns the current access token

func (*PKCEOAuthService) IsAuthenticated

func (s *PKCEOAuthService) IsAuthenticated() bool

IsAuthenticated checks if user is authenticated and attempts refresh if expired

func (*PKCEOAuthService) Login

func (s *PKCEOAuthService) Login(ctx context.Context) error

Login performs OAuth2 authentication with PKCE

func (*PKCEOAuthService) Refresh added in v0.2.9

func (s *PKCEOAuthService) Refresh(ctx context.Context) error

Refresh uses the refresh token to obtain a new access token

type UserInfo added in v0.2.0

type UserInfo struct {
	ID                 int       `json:"id"`       // Server returns number
	UUID               string    `json:"uuid"`     // Server returns UUID
	Username           string    `json:"username"` // May not be in response
	Email              string    `json:"email"`
	Name               string    `json:"name"`                // May not be in response
	FirstName          string    `json:"first_name"`          // Server field
	LastName           string    `json:"last_name"`           // Server field
	Avatar             string    `json:"avatar"`              // Server field
	Verified           bool      `json:"email_verified"`      // Server field (email_verified)
	SubscriptionActive bool      `json:"subscription_active"` // Server field
	CreatedAt          time.Time `json:"created_at"`          // May not be in response
	UpdatedAt          time.Time `json:"updated_at"`          // May not be in response
	LastLoginAt        time.Time `json:"last_login_at"`       // May not be in response
	Roles              []string  `json:"roles"`               // May not be in response
	Permissions        []string  `json:"permissions"`         // May not be in response
}

UserInfo represents the user information returned by the OAuth userinfo endpoint

func (*UserInfo) FormatUserInfo added in v0.2.0

func (ui *UserInfo) FormatUserInfo() string

FormatUserInfo formats user information for display

func (*UserInfo) GetDisplayName added in v0.2.6

func (ui *UserInfo) GetDisplayName() string

GetDisplayName returns the best available name for display

func (*UserInfo) GetFullName added in v0.2.6

func (ui *UserInfo) GetFullName() string

GetFullName returns the full name from first and last name

func (*UserInfo) GetIDString added in v0.2.6

func (ui *UserInfo) GetIDString() string

GetIDString returns the ID as a string for compatibility

type UserInfoService added in v0.2.0

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

UserInfoService handles OAuth userinfo API calls

func NewUserInfoService added in v0.2.0

func NewUserInfoService(cfg *config.Config) *UserInfoService

NewUserInfoService creates a new userinfo service

func (*UserInfoService) GetUserInfo added in v0.2.0

func (s *UserInfoService) GetUserInfo(ctx context.Context, accessToken string) (*UserInfo, error)

GetUserInfo fetches user information from the OAuth userinfo endpoint

Jump to

Keyboard shortcuts

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