auth

package
v0.0.0-...-6c19841 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsTokenExpired

func IsTokenExpired(expiresAt int64) bool

IsTokenExpired checks if the token is expired or will expire soon

func StravaOAuthConfig

func StravaOAuthConfig(clientID, clientSecret string) *oauth2.Config

StravaOAuthConfig returns an OAuth2 config for Strava

Types

type ClientConfig

type ClientConfig struct {
	ClientID     string
	ClientSecret string
}

ClientConfig represents the stored client credentials

type Storage

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

Storage handles auth data persistence using SQLite

func NewStorage

func NewStorage(queries *db.Queries) *Storage

NewStorage creates a new Storage instance

func (*Storage) DeleteTokens

func (s *Storage) DeleteTokens() error

DeleteTokens removes the stored auth config from the database

func (*Storage) GetValidAccessToken

func (s *Storage) GetValidAccessToken() (string, error)

GetValidAccessToken returns a valid access token, refreshing if necessary

func (*Storage) LoadClientConfig

func (s *Storage) LoadClientConfig() (*ClientConfig, error)

LoadClientConfig loads client credentials from the database

func (*Storage) LoadTokens

func (s *Storage) LoadTokens() (*StoredTokens, error)

LoadTokens loads tokens from the database

func (*Storage) SaveClientConfig

func (s *Storage) SaveClientConfig(clientID, clientSecret string) error

SaveClientConfig saves client credentials and optional tokens to the database

func (*Storage) SaveFullConfig

func (s *Storage) SaveFullConfig(clientID, clientSecret string, tokens *TokenResponse) error

SaveFullConfig saves client credentials and tokens together

func (*Storage) SaveTokens

func (s *Storage) SaveTokens(tokens *TokenResponse) error

SaveTokens saves tokens to the database

type StoredTokens

type StoredTokens struct {
	AccessToken  string
	RefreshToken string
	ExpiresAt    int64
}

StoredTokens represents the tokens stored in the database

type TokenResponse

type TokenResponse struct {
	AccessToken  string `json:"access_token"`
	RefreshToken string `json:"refresh_token"`
	ExpiresAt    int64  `json:"expires_at"`
	ExpiresIn    int    `json:"expires_in"`
	TokenType    string `json:"token_type"`
}

TokenResponse represents the OAuth token response from Strava We keep this for compatibility with existing storage

func Authenticate

func Authenticate(ctx context.Context, clientID, clientSecret string) (*TokenResponse, error)

Authenticate performs the OAuth flow and returns tokens

func RefreshAccessToken

func RefreshAccessToken(clientID, clientSecret, refreshToken string) (*TokenResponse, error)

RefreshAccessToken refreshes an expired access token using oauth2 library

func TokenFromOAuth2

func TokenFromOAuth2(token *oauth2.Token) *TokenResponse

TokenFromOAuth2 converts an oauth2.Token to our TokenResponse

func (*TokenResponse) ToOAuth2Token

func (t *TokenResponse) ToOAuth2Token() *oauth2.Token

ToOAuth2Token converts our TokenResponse to an oauth2.Token

Jump to

Keyboard shortcuts

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