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 ¶
- Variables
- func DefaultStateDir() string
- func NewPKCE() (verifier, challenge, state string, err error)
- func ProviderIDs() []string
- type Provider
- type Store
- func (s *Store) AccessToken(ctx context.Context, provider string) (string, error)
- func (s *Store) Delete(provider string) error
- func (s *Store) Get(provider string) (Token, bool)
- func (s *Store) Path() string
- func (s *Store) Put(provider string, tok Token) error
- func (s *Store) Token(ctx context.Context, provider string) (Token, error)
- func (s *Store) Tokens() (map[string]Token, error)
- type Token
Constants ¶
This section is empty.
Variables ¶
var ErrNoToken = errors.New("auth: no token — run `panda auth login <provider>`")
ErrNoToken is returned when the store holds no credential for a provider.
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 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
// External marks a credential this package does not own: another tool
// holds it and refreshes it, so the token is read from that tool's file on
// every call instead of being copied into the store. Such a provider has
// no browser flow of its own — the login belongs to the tool that owns the
// file (see codex.go).
External func() (Token, error)
}
Provider describes one OAuth integration point.
func (Provider) AuthorizeURLFor ¶
AuthorizeURL builds the consent URL the user opens in a browser.
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 (*Store) AccessToken ¶
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.
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"`
// AccountID is the provider-side account a subscription token belongs to.
// The Codex ChatGPT backend routes requests by it (chatgpt-account-id);
// other providers leave it empty.
AccountID string `json:"account_id,omitempty"`
}
Token is one stored OAuth credential set for a provider.