Expand description
OAuth 2.0 Authorization Code + PKCE flow for Anthropic (Claude Pro/Max).
Implements the same flow as Claude Code and Pi coding agent:
- Generate PKCE verifier + challenge
- Start localhost callback server
- Open browser to claude.ai/oauth/authorize
- Capture redirect with auth code
- Exchange code for access + refresh tokens
- Save to ~/.pi/agent/auth.json (shared with Pi)
Modules§
- aws_
bedrock - Provider-local IAM Identity Center and Bedrock broker boundary. The transport trait is intentionally typed: it cannot sign arbitrary URLs or vend credentials.
- azure_
openai - Provider-local Azure OpenAI OAuth, catalog, and broker request contracts. No function in this module performs network I/O or returns credentials.
- broker
- The credential broker — the mandatory boundary between runtimes and
provider secrets (Checkpoint 1 decision,
docs/decisions/credential-broker-checkpoint-1.md). - cloud
- Shared, credential-free cloud provider contracts.
- cloud_
login - Provider-specific interactive cloud login protocols. Credentials remain persisted only through the broker-owned auth store.
- github_
copilot - GitHub Copilot OAuth (device authorization + broker-owned session mint).
- google_
gemini - Google Gemini (Code Assist) OAuth: authorization-code + PKCE.
- google_
vertex - Provider-local Google Vertex AI installed-app OAuth primitives.
- kimi_
code - Kimi Code OAuth (RFC 8628 device authorization; direct bearer, no mint).
- provider
- Typed OAuth provider identity, descriptors, registry validation, and dispatch.
- providers
- static_
providers - Static-key provider connection metadata, owned by the credential broker.
Structs§
- Access
Token - An OAuth access token vended by the broker.
- Auth
File - AwsBedrock
Config - Azure
Open AiConfig - Broker
Client - HTTP client for a credential broker. Presents the machine’s own bearer token (NOT the provider credential) and receives a short-lived access token.
- Broker
Message - Broker
Token - An access token as returned by the broker’s
GET /token. - Broker
Tool - Callback
Result - Result from the OAuth callback.
- Callback
Server Handle - Google
Vertex Config - Invoke
Options - Invoke
Request - Local
Broker - In-process credential broker. This module is the ONLY place runtime-serving
code may read
auth.json,provider.<key>config values, or credential environment variables. - OAuth
Credentials - OAuth
Provider Descriptor - OAuth
Provider Registry - Provider
Status - Non-secret capability/status row for one provider.
- Proxy
Request - A typed, credential-free request the broker executes on the caller’s behalf against an OpenAI-compatible provider endpoint.
- Proxy
Response - Buffered (non-streaming) proxy result: upstream status + body text.
- Remote
Broker - Client for a remote
synaps auth-broker. Presents the machine’s own bearer token; receives access tokens (OAuth) and proxied responses (static-key providers). Never receives refresh tokens or raw keys. - Static
Provider Spec - Connection/credential metadata for one static-key provider.
- Token
Cache - Thread-safe, per-provider cache of broker access tokens. Cloneable handle over shared state. Holds ONLY short-lived access tokens, never a refresh token, never persisted to disk.
Enums§
- Auth
Identity - Credential mechanism used behind the broker boundary.
- Broker
Credential Strategy - How a runtime may obtain a usable credential from the broker.
- Broker
Error - Broker failures. Messages never contain credential values.
- Broker
Operation - Callback
Outcome - Cloud
Provider Id - Credential
Kind - What kind of credential a provider uses. Never carries key material.
- Credential
Source - Where a client gets its provider credentials.
- Message
Role - OAuth
Provider Id - Provider
Id - General auth identity. Existing OAuth identity remains strongly typed.
- Proxy
Method - HTTP method subset the proxy protocol supports.
- Static
KeyStatus - Non-secret display status for one static key (settings UI).
Constants§
- DEFAULT_
MARGIN_ MS - Default refetch margin: 5 minutes (mirrors
is_token_expired). - LOCAL_
PROVIDER_ KEY - The local OpenAI-compatible endpoint pseudo-provider (Ollama, LM Studio…). Its endpoint URL is non-secret user configuration; its optional key is still broker-owned.
- MAX_
PROXY_ REQUEST_ BYTES - Maximum serialized size of a proxy request body.
- MAX_
PROXY_ RESPONSE_ BYTES - Maximum buffered (non-streaming) response body size.
- MAX_
UPSTREAM_ ERROR_ BYTES - Historical cap for upstream error-body snippets. Upstream/broker error
bodies are no longer read at all (spec §5.1: they may echo the request);
the constant remains only because it is re-exported from
auth::mod. - PROXY_
REQUEST_ TIMEOUT - Total time budget for a buffered (non-streaming) broker-executed request.
Traits§
- Credential
Broker - The typed credential broker protocol. One implementation runs in-process
(
LocalBroker) so normal local use needs no daemon; the other talks to a remotesynaps auth-brokerover authenticated HTTP(S) (RemoteBroker). - Token
Fetcher - “Get a fresh access token from somewhere.” Abstracted so the cache/resolve
logic is unit-testable without real HTTP. The real impl is
BrokerClient.
Functions§
- auth_
file_ path - Get the path to auth.json (~/.synaps-cli/auth.json).
- broker_
from_ source - remote transport. There is no third option — and no direct-read fallback.
- build_
auth_ url - Build the full authorize URL for the browser.
- ensure_
fresh_ provider_ token - Ensure an OAuth provider (including Anthropic) has a fresh token.
- ensure_
fresh_ token - Acquire the Anthropic refresh gate, check token freshness, refresh if needed, and persist the result atomically. Returns the current (possibly refreshed) credentials.
- exchange_
code_ for_ tokens - Exchange an authorization code for access + refresh tokens.
- extract_
codex_ account_ id - generate_
code_ challenge - Compute S256 code challenge from verifier.
- generate_
code_ verifier - Generate a cryptographically random code verifier (43-128 chars, base64url).
- generate_
state - Generate a random state parameter.
- global_
broker - The process-wide broker. Defaults to the in-process
LocalBrokerso normal local use never requires a separately launched daemon. - global_
broker_ install_ count - How many times
set_global_brokerhas run in this process. - is_
expired_ with_ margin - True if
expires_msis already past, or withinmargin_msof now. - is_
token_ expired - Check if the current token is expired.
- load_
auth - Load credentials from auth.json.
- load_
cloud_ state - Load an opaque broker-owned cloud provider state object.
- load_
provider_ auth - Load one provider’s OAuth credential from auth.json.
- load_
static_ key - Load one provider’s broker-owned static API key from auth.json.
- login
- Run the full OAuth login flow. Returns saved credentials.
- login_
github_ copilot - Production login entry (real network + system browser + auth.json).
- login_
kimi_ code - Production login entry (real network + system browser + auth.json).
- login_
openai_ codex - login_
xai - open_
browser - Open a URL in the default browser.
- preflight_
cloud_ capability - Build the right broker for a credential source. Local sources get the in-process broker (no daemon needed); remote sources get the authenticated Pre-flight capability check for a cloud route (spec §5.5). Pure function: callers MUST run it before constructing a broker, looking up credentials, or opening any connection. The invoke-time guard inside the broker remains in place as defense in depth.
- refresh_
token - Refresh an expired OAuth token.
- resolve_
access_ token - Provider-aware token resolution honoring the credential source — kept as a
compatibility adapter for CLI callers (
synaps status). Delegates to the typed credential broker: the local in-process broker or the authenticated remote transport. Vends the access token only. - resolve_
remote - Resolve a provider token via cache-or-fetch, returning the full
BrokerToken(access + expiry). The runtime needs the expiry to drive its in-memory refresh trigger. NEVER touches a refresh token orauth.json. - resolve_
remote_ token - Like
resolve_remotebut returns only the access token string. - save_
auth - Save credentials to auth.json.
- save_
cloud_ state - Atomically persist opaque cloud state while preserving every unrelated field.
- save_
provider_ auth - Save one provider credential while preserving other auth.json entries.
- save_
static_ key - Persist a broker-owned static API key while preserving every other auth.json entry and any provider metadata.
- set_
global_ broker - Install the process-wide broker (called once from runtime configuration).
Every call is counted (
global_broker_install_count) and, whenSYNAPS_MEM_TRACE=1, logged — the daemon-mode S7 gate asserts the count stays at 1 across subagent spawns. - start_
callback_ server - start_
callback_ server_ at - static_
provider - Look up a static provider spec by key.
Type Aliases§
- Proxy
Byte Stream - Streaming proxy result: raw upstream bytes (SSE), post-authorization.