auth

package
v0.11.0-beta.1 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: Apache-2.0, MIT Imports: 13 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClearEndpointOverride

func ClearEndpointOverride(provider string)

ClearEndpointOverride removes a test override.

func DeleteToken

func DeleteToken(provider string) error

DeleteToken removes a stored token (used by /logout).

func SaveToken

func SaveToken(tok *Token) error

SaveToken writes a token to disk with restrictive permissions.

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 SetHTTPClient

func SetHTTPClient(c *http.Client)

SetHTTPClient is for test injection.

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

func LoadToken(provider string) (*Token, error)

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.

Jump to

Keyboard shortcuts

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