Skip to main content

Module oauth

Module oauth 

Source
Expand description

Claude Pro/Max subscription auth (OAuth) for the Anthropic backend.

Implements the same subscription sign-in the community bridges use (pi-claude-bridge, anthropic-auth): a PKCE authorize URL the user opens in a browser, a pasted-back code exchanged for tokens, and transparent refreshes afterwards. Inference requests then carry Bearer tokens with the oauth-2025-04-20 beta instead of an API key, so usage bills to the subscription instead of API credits.

At your own risk. This project is not affiliated with or endorsed by Anthropic. Using a subscription outside Anthropic’s official clients may violate their terms and can lead to account restrictions or suspension. The preset stays dormant unless explicitly opted in.

Structs§

Authorization
Authorize redirect for one sign-in attempt.
Callback
Pasted callback: full redirect URL, code#state, or code=&state= pairs.
IssuedTokens
Freshly issued tokens.
LoadedCredentials
Loaded credentials plus where to persist refreshed tokens (None = don’t).
OAuthError
Failure talking to the token endpoint.
OAuthSession
Credential set backing one subscription session.
Pkce
PKCE pair for the authorize redirect.

Enums§

AccountMode
Subscription account type selecting the authorize endpoint.

Constants§

ANTHROPIC_VERSION
Anthropic API version header.
AUTHORIZE_URL_CONSOLE
Authorize endpoints by account type.
AUTHORIZE_URL_MAX
Authorize endpoints by account type.
BASE_URL_ENV
Base URL override for subscription inference.
CLAUDE_CODE_USER_AGENT
User-Agent identifying requests as Claude Code, mirroring the bridges.
CLIENT_ID
OAuth client id embedded in Claude Code (public, shared by bridges).
CODE_CALLBACK_URL
Callback the browser flow redirects to (code is pasted back manually).
OAUTH_BETA
Beta flag billing inference to the subscription.
OAUTH_SCOPES
Scopes requested at sign-in.
OPT_IN_ENV
Explicit opt-in env var enabling the subscription preset.
REFRESH_SCOPE
Narrower scopes sent on refresh.
REFRESH_SKEW_MS
Refresh this far ahead of expiry (5 minutes).
STATIC_TOKEN_ENV
Static bearer token (no refresh); implies opt-in.
TOKEN_TIMEOUT
Network timeout for token endpoint calls.
TOKEN_URL
Token endpoint for both code exchange and refresh.
TOKEN_USER_AGENT
User-Agent used for token endpoint calls.

Functions§

authorize
Build the authorize URL, PKCE pair, and state for a sign-in attempt.
claude_code_credentials_path
Path of Claude Code’s credentials file (claude auth login target).
ensure_fresh_token
Ensure the session holds a fresh bearer token, refreshing when needed.
exchange_code
Exchange a verified callback for tokens.
force_refresh
Refresh unconditionally and store the result (used after a 401).
load_credentials
Load subscription credentials: our file first, then Claude Code’s login.
needs_refresh
Whether the bearer token should be refreshed before use.
now_ms
Current time as unix millis; 0 when the clock is unavailable.
own_credentials_path
Path of our own credentials file (~/.infinity/claude-oauth.json).
parse_callback
Parse pasted callback input, rejecting blank fields.
store_login
Persist freshly exchanged login tokens; returns the file path.

Type Aliases§

OAuthSessionHandle
Shareable handle for concurrent completions.