Documentation
¶
Overview ¶
Package auth implements Strava OAuth2 login and automatic token refresh.
Index ¶
- func CompleteRemoteLogin(clientID, clientSecret, redirectURI, expectedState, pastedInput string) (*config.Tokens, error)
- func ExtractCode(input string) string
- func GenerateState() (string, error)
- func IsLocalhost(u string) bool
- func Login(clientID, clientSecret, redirectURI string) (*config.Tokens, error)
- func RefreshIfExpired(cfg *config.Config) error
- func RemoteAuthURL(clientID, redirectURI, state string) string
- func SetTokenURL(u string) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CompleteRemoteLogin ¶
func CompleteRemoteLogin(clientID, clientSecret, redirectURI, expectedState, pastedInput string) (*config.Tokens, error)
CompleteRemoteLogin extracts the authorization code from a pasted redirect URL, validates the state token against expectedState, and exchanges the code for tokens. Used for step 2 of the two-step remote login flow.
func ExtractCode ¶
ExtractCode parses an authorization code from either a full URL or a bare code string. Exported for testing.
func GenerateState ¶
GenerateState returns a 16-byte cryptographically random hex string suitable for use as an OAuth2 CSRF state token.
func IsLocalhost ¶
IsLocalhost reports whether u is a localhost URI. Exported for testing.
func Login ¶
Login initiates the OAuth2 authorization code flow.
If redirectURI is empty or a localhost URI, a local callback server is started on port 8089 to capture the code automatically.
If redirectURI is an external HTTPS URI, the auth URL is displayed and the user is prompted to paste either the full callback URL or just the code.
func RefreshIfExpired ¶
RefreshIfExpired checks whether the access token is expired (with a 30s buffer) and refreshes it if necessary, updating cfg in-place and saving it.
func RemoteAuthURL ¶
RemoteAuthURL builds a Strava authorization URL that includes a state token. Used for step 1 of the two-step remote login flow.
func SetTokenURL ¶
SetTokenURL overrides the token endpoint URL and returns the previous value. Intended for use in tests only.
Types ¶
This section is empty.