Documentation
¶
Overview ¶
Package auth implements OAuth device-code flows for providers that don't use static API keys (Anthropic Claude.ai, GitHub Copilot, etc.).
Index ¶
- func ClearEndpointOverride(provider string)
- func DeleteToken(provider string) error
- func SaveToken(tok *Token) error
- func SetAuthDir(dir string)
- func SetEndpointOverride(provider string, cfg providerConfig)
- func SetHTTPClient(c *http.Client)
- func SupportedProviders() []string
- type DeviceFlow
- type Token
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ClearEndpointOverride ¶
func ClearEndpointOverride(provider string)
ClearEndpointOverride removes a test override.
func DeleteToken ¶
DeleteToken removes a stored token (used by /logout).
func SetAuthDir ¶
func SetAuthDir(dir string)
SetAuthDir is a test hook to override the auth storage directory.
func SetEndpointOverride ¶
func SetEndpointOverride(provider string, cfg providerConfig)
SetEndpointOverride is exposed for tests to redirect the device/token URLs to an httptest.Server.
func SupportedProviders ¶
func SupportedProviders() []string
SupportedProviders returns the list of providers with OAuth support.
Types ¶
type DeviceFlow ¶
type DeviceFlow struct {
UserCode string `json:"user_code"`
VerificationURL string `json:"verification_url"`
ExpiresAt time.Time `json:"expires_at"`
Interval int `json:"interval"`
// contains filtered or unexported fields
}
DeviceFlow is the state returned by StartDeviceFlow. The TUI shows VerificationURL + UserCode to the user; the deviceCode is opaque and used internally for polling.
func StartDeviceFlow ¶
func StartDeviceFlow(ctx context.Context, provider string) (*DeviceFlow, error)
StartDeviceFlow kicks off a device-code authorization. The returned flow contains a code/URL the user must visit, and the deviceCode used for polling.
func (*DeviceFlow) DeviceCode ¶
func (d *DeviceFlow) DeviceCode() string
DeviceCode returns the opaque device code for polling.
func (*DeviceFlow) Provider ¶
func (d *DeviceFlow) Provider() string
Provider returns which provider this flow targets.
type Token ¶
type Token struct {
AccessToken string `json:"access_token"`
RefreshToken string `json:"refresh_token,omitempty"`
TokenType string `json:"token_type,omitempty"`
ExpiresAt time.Time `json:"expires_at,omitempty"`
Provider string `json:"provider"`
}
Token is a stored OAuth credential.
func LoadToken ¶
LoadToken reads a token for the given provider, or returns (nil, nil) if not present.
func PollForToken ¶
func PollForToken(ctx context.Context, flow *DeviceFlow) (*Token, error)
PollForToken polls the token endpoint until the user authorizes (returns Token), denies (returns error), or the ctx is canceled.