Skip to main content

Module oauth

Module oauth 

Source
Expand description

Codewhale-owned OAuth login and protected credential lifecycle. ChatGPT uses its official dynamic registration and direct inference grant. Providers are data rows in the parameter table below, not modules.

External Codex CLI credentials are read only after an exact, provider-scoped consent grant. Codewhale never refreshes or rewrites that external file.

§Security

Token values are never logged or printed. All debug representations redact sensitive fields.

Structs§

BrowserAuthRequest
A browser authorization request in flight: state, PKCE pair, and the registered redirect the callback server answers on.
ChatgptKeys
ChatgptRegistration
Verified registration identity. The client ID also binds the selected workspace. One active registration is supported; use CODEWHALE_CHATGPT_NEW_ACCOUNT=1 to explicitly replace it after a new, fully validated browser sign-in.
CodexCredentials
Resolved OAuth credentials ready for API use.
OAuthActivation
Receipt for a committed Codewhale-owned OAuth generation.
OAuthEnvOverrides
Test/dev knobs a provider reads from the environment. Data, so a new provider adds rows here instead of a new module.
OAuthProviderParams
Everything about one provider’s OAuth login that is not logic.
OAuthTokenMaterial
Token material from a completed grant. No Debug: the tokens never print. interval rides along because a slow_down error response may carry the server’s new minimum, which the loop prefers over its own tracked value (RFC 8628 §3.5; WSL/VM clock drift).
OrcaCredential
The credential the rest of Codewhale consumes for OrcaRouter.
OrcaLoginInputs
Where an injected OrcaRouter login reads its inputs from. Tests override this so the whole adapter — bind, authorize URL, callback, exchange — runs against a local fake auth server with no network egress.
OwnedAuthEntry
One entry in a Codewhale-owned auth generation. Reads both historical on-disk shapes; key was the xAI/Grok field name for the access token.
OwnedOAuthCredentials
Resolved owned credentials ready for API use. No Debug: bearer material never prints; consumers redact explicitly.
PendingOAuthLogin
A completed login awaiting activation (owned-generation commit). The provider is the table row it resolved through; unified activation (3b-ii) matches on it.
PkceChallenge
RFC 7636 S256 PKCE pair. Custom Debug: the verifier is exchanged for bearer material and never prints.
PluginOAuthConfig
Declarative public OAuth configuration for a reviewed plugin provider.
PluginOAuthTokens
ReqwestOAuthFormClient
ResolvedOAuthInputs
Resolved login inputs: schema defaults, environment-tested in order.
UsableSignIn
A subscription sign-in the structural check found usable, named by the same read that proved it usable. Holds a display label only.

Enums§

CallbackOutcome
Parsed callback query: a code+state pair, or the issuer’s refusal.
OAuthProvider
Providers with an OAuth login Codewhale can own.
OrcaCallback
OrcaCredentialSource
How an OrcaCredential was obtained. Presentation only: it selects copy, never behaviour. Nothing downstream of the credential seam may read it to decide whether the key is usable.

Constants§

CALLBACK_TIMEOUT
CHATGPT_OAUTH_CLIENT_ID
CHATGPT_OAUTH_ISSUER
ChatGPT issuer and public client.
CHATGPT_OAUTH_PARAMS
CHATGPT_OAUTH_RESOURCE
CHATGPT_OAUTH_SCOPE
DEFAULT_SCOPES
GROK_OIDC_CLIENT_ID
ORCAROUTER_API_BASE
OrcaRouter’s public inference/catalog origin.
ORCAROUTER_APP_ID
ORCAROUTER_APP_NAME
Shown on the OrcaRouter consent screen.
ORCAROUTER_AUTHORIZE_PATH
Consent endpoint path. Not an API route: the browser is pointed at it.
ORCAROUTER_AUTH_BASE
OrcaRouter’s public authentication origin. Inference lives on a different host (https://api.orcarouter.ai/v1); neither origin is derived from the other.
ORCAROUTER_CLIENT_ID
OrcaRouter’s authorize contract carries no client id: this public label is a constant, not a secret. PKCE — not a client secret — binds the auth code to this process.
ORCAROUTER_EXCHANGE_PATH
Code-for-key exchange path under the auth origin. The relay’s /v1/auth/keys is a different route and a 404; the auth API lives at /api/v1/auth/keys.
ORCAROUTER_OAUTH_PARAMS
ORCAROUTER_REF
ORCAROUTER_SCOPE
The scope this client asks for, and the only scope it accepts back.
XAI_OAUTH_PARAMS
XAI_OIDC_ISSUER
xAI issuer and public client (constants the params rows and the route surfaces share).

Traits§

OAuthFormClient

Functions§

account_label_from_id_token
Non-secret account label from an ID token’s claims, decoded locally: email, email (plan), or for a workspace plan email (plan, workspace 1a2b3c4d). The signature is not verified: the label is for display only and never authorizes anything. Claim text is bounded and stripped of control characters so a hostile token cannot smuggle terminal escapes into status output. None when no usable email claim exists.
activate_login
Commit a pending login as a uniquely named owned generation and atomically point the provider’s config table at it under the shared config lock.
activate_orcarouter_credential
Persist an OrcaCredential through the host’s ordinary, transactional provider-credential path.
auth_file_path
Resolve the path to the Codex auth file.
auth_mode_uses_xai_oauth
Whether [providers.xai] auth_mode selects the OAuth path.
bind_loopback_callback
Bind ChatGPT’s exact 127.0.0.1 callback, with an ephemeral-port fallback. Other providers using localhost bind both IP stacks when available.
bind_orcarouter_callback
Bind the OrcaRouter loopback callback: always 127.0.0.1, ephemeral port.
build_authorize_url
build_orcarouter_authorize_url
The OrcaRouter authorize URL.
clear_dangling_generation
Best-effort repair for the #5032 bricked-launch state: remove the stale oauth_credential_generation pointer from the PERSISTED config file so the next launch is no longer bricked. Mirrors the document edits in activate_login_locked (which replaces the pointer under the config lock) and crate::config::clear_api_key’s unlocked scrub.
cli_challenge_writer
Terminal-or-stdout challenge writer for shell commands that drive a login outside the TUI (codewhale auth ...).
credentials_present
credentials_valid
Prompt-free structural check for owned OAuth material. Never refreshes, writes, or makes network requests. External storage is not inspected until exact read-only consent has been persisted, and then only at the exact consented path — no ambient candidate is ever resolved or opened (#5772).
device_code_login
Interactive device-code login for any provider whose row offers it. Shows the verification URL + user code only on a terminal and polls until approved. A provider with no device flow (ChatGPT) fails here with the reason, instead of deep in transport code.
exchange_orcarouter_code
Exchange an OrcaRouter auth code for a durable API key.
generate_pkce
RFC 7636 S256 PKCE pair.
generate_state
get_credentials
Load read-only credentials from the exact external path authorized by grant. Expired tokens fail with guidance; they are never refreshed.
get_owned_credentials
Load owned subscription credentials from the configured generation, refreshing through the seam when stale.
get_owned_credentials_read_only
Read-only diagnostics: never refreshes or changes protected storage.
get_xai_credentials
Load xAI OAuth credentials with full precedence: configured generation, legacy owned file, then the consented Grok CLI import. Codewhale-owned credentials may refresh and rewrite Codewhale-owned storage; external credentials are read-only.
grok_auth_file_path
Resolve the Grok CLI auth file path.
login
One login entry point for every provider: the params row decides whether the grant is device-code or browser PKCE. A provider with neither fails here with the reason.
login_with_config
Reauthorize the registration selected by the caller’s actual config.
missing_auth_message
oauth_provider_params
The parameter table. A provider login looks its row up here; adding a provider means adding a row, never a module.
official_chatgpt_registration
Metadata only: no network, refresh, token return, or external credential import.
orcarouter_exchange_url
The OrcaRouter code-for-key exchange endpoint, always on the auth origin.
orcarouter_pkce_login
One interactive OrcaRouter PKCE login.
owned_account_label_for_generation
Account label of the Codewhale-owned sign-in stored in one generation file. Reads only that file; never refreshes, writes, or touches the network. Ok(None) when the usable entry’s ID token carries no email; Err (a fixed, token-free reason) when the generation name is invalid, the file is missing or unreadable, or it holds no usable sign-in.
owned_generation_is_dangling
Detect the #5032 bricked-launch state: the provider’s config selects OAuth and points oauth_credential_generation at a Codewhale-owned credential file that no longer exists. This is a distinct, more specific failure than “unconfigured” — the pointer is present and authoritative, so credentials_valid returns false and cannot fall through to a legacy or external credential, which is exactly what bricked the dogfood machine.
owned_oauth_account_label
Non-secret account label (email, plan) of the Codewhale-owned subscription sign-in stored in generation, for codewhale auth status and auth list. Reads only that Codewhale-owned file: no refresh, no network, no external CLI file. Err carries a fixed, token-free reason the sign-in is unusable (missing, unreadable, no usable entry).
parse_callback_query
pin_plugin_oauth_grant
pkce_login
Interactive PKCE browser login for any provider whose row offers it. Shows the authorize URL only on a terminal, opens a browser, and waits for the loopback callback. A provider with no browser flow (xAI) fails here with the reason, before any listener binds.
plugin_oauth_access_token
Resolve only the exact provider, endpoint and descriptor-bound credential. Async consumers must call this sync secure-store/HTTP worker off-runtime.
plugin_oauth_access_token_for_grant
plugin_oauth_credentials_present
Prompt-free stored-login status. Readiness reads only this exact host-owned secure slot, without refreshing, migrating or contacting the issuer.
plugin_oauth_logout
Local logout is authoritative; declarative plugins do not get a remote revocation hook or raw refresh token.
plugin_oauth_slot
plugin_token_response
resolve_orcarouter_api_base
Resolve the OrcaRouter inference/catalog origin.
resolve_orcarouter_auth_base
Resolve the OrcaRouter authentication origin.
revoke_owned_login
Remove Codewhale-owned tokens and the config pointer for one provider.
start_orcarouter_auth_request
Build the loopback callback URL + authorize URL for one OrcaRouter attempt.
usable_sign_in
credentials_valid, also naming the account of the entry that passed: the configured Codewhale-owned generation, else (xAI) the legacy owned file or the consented Grok CLI import — the credential the route would send. Readiness surfaces take the label from here so naming the account costs no second credential read.
usage_limit_guidance
What to tell someone whose subscription sign-in hit a plan limit: which account made the request (label only, never a token) and how to sign in with a different one, both inside a running session and from a shell. A shell login does not reach a session that is already open, so the shell route says to restart.
validate_grok_external_credentials
Grant-time validation for an external Grok CLI credential file (#5772).
wait_for_callback_validated
wait_for_orcarouter_callback