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)
Structs§
- Auth
File - Callback
Result - Result from the OAuth callback.
- Callback
Server Handle - Handle to shut down the callback server.
- OAuth
Credentials
Functions§
- auth_
file_ path - Get the path to auth.json (~/.synaps-cli/auth.json).
- build_
auth_ url - Build the full authorize URL for the browser.
- ensure_
fresh_ provider_ token - Ensure a non-Anthropic OAuth provider has a fresh token.
- ensure_
fresh_ token - Acquire an exclusive lock on auth.json, check token freshness, refresh if needed, and persist the result. 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.
- is_
token_ expired - Check if the current token is expired (or will expire within 5 minutes).
- load_
auth - Load credentials from auth.json.
- load_
provider_ auth - Load one provider’s OAuth credential from auth.json.
- login
- Run the full OAuth login flow. Returns saved credentials.
- login_
openai_ codex - open_
browser - Open a URL in the default browser.
- refresh_
token - Refresh an expired OAuth token.
- save_
auth - Save credentials to auth.json.
- save_
provider_ auth - Save one provider credential while preserving other auth.json entries.
- start_
callback_ server - Start a temporary HTTP server on localhost that captures the OAuth callback. Returns a oneshot receiver that resolves with the auth code + state.