Documentation
¶
Overview ¶
Package auth manages credentials for the Timestripe CLI.
Two credential types are supported:
- "bearer": personal API token
- "oauth": OAuth2 authorization-code + PKCE access/refresh token pair
Credentials are persisted to $XDG_CONFIG_HOME/timestripe/credentials.json.
Index ¶
Constants ¶
const ClientID = "timestripe-cli"
ClientID is the OAuth client identifier for the CLI.
Variables ¶
var ErrNotFound = errors.New("no credentials stored; run `timestripe auth login`")
ErrNotFound is returned when no credentials are stored.
Functions ¶
This section is empty.
Types ¶
type Credentials ¶
type Credentials struct {
Type Type `json:"type"`
AccessToken string `json:"accessToken"`
RefreshToken string `json:"refreshToken,omitempty"`
ExpiresAt time.Time `json:"expiresAt,omitempty"`
// Backend is the Timestripe site root the user signed into.
// Used to pin subsequent requests to the same environment.
Backend string `json:"backend,omitempty"`
}
Credentials is the persisted auth state for a user.
func LoginPKCE ¶
LoginPKCE runs the OAuth2 authorization-code flow with PKCE against a loopback redirect on an OS-assigned random port. The backend accepts any 127.0.0.1 loopback redirect URI, so no static port registration is needed.
userAgent, if non-empty, is sent on the token-exchange request so the OAuth server can identify the CLI client.
Flow:
- Start an HTTP server on 127.0.0.1:0 (OS picks a free port).
- Open the user's browser to the authorization URL.
- Wait for the browser to hit /callback with ?code=...&state=....
- Exchange code + PKCE verifier for tokens.
func Resolve ¶
func Resolve(ctx context.Context) (*Credentials, error)
Resolve returns the caller's current credentials, respecting the TIMESTRIPE_TOKEN environment override (which wins over any stored creds). Callers should pass ctx through to token-refresh flows when Expired().
func (*Credentials) Expired ¶
func (c *Credentials) Expired() bool
Expired reports whether the access token has (or is about to) expire. Always false for bearer tokens (personal API keys do not expire client-side).
type Store ¶
type Store interface {
Load() (*Credentials, error)
Save(*Credentials) error
Delete() error
}
Store persists credentials to some backend.
func DefaultStore ¶
func DefaultStore() Store
DefaultStore returns the file-backed credentials store.