auth

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: AGPL-3.0 Imports: 18 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package auth holds subscription-OAuth plumbing: PKCE flows against providers whose consumer subscriptions also grant API access, plus the on-disk token store the entry client reads for a Bearer credential.

The first supported provider is Anthropic (a Claude Pro/Max subscription can answer Messages API calls with an OAuth Bearer where an API key would go). Other providers with different token shapes — e.g. OpenAI's subscription tokens only work against a separate backend surface, not /v1/chat/completions — slot into the Providers table once the entry client speaks their wire protocol.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoToken = errors.New("auth: no token — run `panda auth login <provider>`")

ErrNoToken is returned when the store holds no credential for a provider.

View Source
var ErrUnknownProvider = errors.New("auth: unknown oauth provider")

ErrUnknownProvider is returned for a provider id not in the registry.

Functions

func DefaultStateDir

func DefaultStateDir() string

DefaultStateDir mirrors the CLI's state-dir convention (XDG_STATE_HOME/openpanda, %LOCALAPPDATA%\openpanda on Windows, else ~/.local/state/openpanda) so a token written by `panda auth login` is the same one the entry client finds later.

func NewPKCE

func NewPKCE() (verifier, challenge, state string, err error)

NewPKCE generates a code verifier, its S256 challenge, and a random state parameter.

func ProviderIDs

func ProviderIDs() []string

ProviderIDs lists registered provider ids, for help text.

Types

type Provider

type Provider struct {
	ID    string // provider key used in config and the token store
	Label string // human label for status output
	// AuthorizeURL is the browser-facing consent page; TokenURL the
	// code/refresh exchange endpoint. RedirectURI must be a URI the
	// provider has registered for this client — Claude's flow lands on a
	// hosted page that shows the user a code to paste back.
	AuthorizeURL string
	TokenURL     string
	ClientID     string
	RedirectURI  string
	Scope        string
}

Provider describes one OAuth integration point.

func Lookup

func Lookup(id string) (Provider, error)

Lookup resolves a provider id.

func (Provider) AuthorizeURLFor

func (p Provider) AuthorizeURLFor(challenge, state string) string

AuthorizeURL builds the consent URL the user opens in a browser.

func (Provider) Exchange

func (p Provider) Exchange(ctx context.Context, code, verifier, state string) (*Token, error)

Exchange trades an authorization code (+ PKCE verifier + state, as the user pastes it back) for tokens.

func (Provider) Refresh

func (p Provider) Refresh(ctx context.Context, refreshToken string) (*Token, error)

Refresh trades a stored refresh token for a fresh access token. The provider may rotate the refresh token; the new pair is returned whole.

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store persists OAuth tokens at <state dir>/auth.json, mode 0600 — the same on-disk trust level as the config's api_key.

func OpenStore

func OpenStore(stateDir string) *Store

OpenStore returns the token store rooted at stateDir.

func (*Store) AccessToken

func (s *Store) AccessToken(ctx context.Context, provider string) (string, error)

AccessToken returns a live access token for the provider, transparently refreshing an expired one when a refresh token exists. ErrNoToken means the user has not logged in.

func (*Store) Delete

func (s *Store) Delete(provider string) error

Delete removes a provider's token (logout).

func (*Store) Get

func (s *Store) Get(provider string) (Token, bool)

Get returns a provider's stored token, if any.

func (*Store) Path

func (s *Store) Path() string

Path exposes the backing file path for diagnostics.

func (*Store) Put

func (s *Store) Put(provider string, tok Token) error

Put stores a token under its provider id.

func (*Store) Tokens

func (s *Store) Tokens() (map[string]Token, error)

Tokens returns a snapshot of all stored tokens, for `auth status`.

type Token

type Token struct {
	AccessToken  string    `json:"access_token"`
	RefreshToken string    `json:"refresh_token,omitempty"`
	ExpiresAt    time.Time `json:"expires_at,omitempty"`
	Scope        string    `json:"scope,omitempty"`
}

Token is one stored OAuth credential set for a provider.

func (Token) Expired

func (t Token) Expired(now time.Time) bool

Expired reports whether the token is at or past its usable life. A token without an expiry never reports expired (some providers issue non-expiring access tokens).

Jump to

Keyboard shortcuts

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