Documentation
¶
Index ¶
- func IsTokenExpired(expiresAt int64) bool
- func StravaOAuthConfig(clientID, clientSecret string) *oauth2.Config
- type ClientConfig
- type Storage
- func (s *Storage) DeleteTokens() error
- func (s *Storage) GetValidAccessToken() (string, error)
- func (s *Storage) LoadClientConfig() (*ClientConfig, error)
- func (s *Storage) LoadTokens() (*StoredTokens, error)
- func (s *Storage) SaveClientConfig(clientID, clientSecret string) error
- func (s *Storage) SaveFullConfig(clientID, clientSecret string, tokens *TokenResponse) error
- func (s *Storage) SaveTokens(tokens *TokenResponse) error
- type StoredTokens
- type TokenResponse
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsTokenExpired ¶
IsTokenExpired checks if the token is expired or will expire soon
func StravaOAuthConfig ¶
StravaOAuthConfig returns an OAuth2 config for Strava
Types ¶
type ClientConfig ¶
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 ¶
NewStorage creates a new Storage instance
func (*Storage) DeleteTokens ¶
DeleteTokens removes the stored auth config from the database
func (*Storage) GetValidAccessToken ¶
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 ¶
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 ¶
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