Expand description
Shared Parslee OAuth2 PKCE + token/keychain logic.
Used by car-cli (car auth login parslee, loopback flow) and by
car-server (the auth.* JSON-RPC surface that CAR Host.app’s
signup GUI drives). The keychain keys + default service exactly
match what car-inference reads at request time. The serialized
PARSLEE_AUTH_STATE_V2 record under the default "car" service is the
durable authority; the old fixed slots are read only by locked migration.
Structs§
- Account
Meta - Non-secret metadata for one signed-in Parslee login.
- Auth
Attempt Failure - Safe terminal failure metadata persisted for one exact attempt.
- Auth
Completion Record - The latest causally-bound browser completion. Only one completion can remain
current because every identity-changing credential mutation advances
generation; a later mutation therefore supersedes this proof. - Auth
Completion Status - One authoritative, coordinator-locked view of completion, generation, and attempt lifecycle. Optional fields are populated only for their matching state.
- Credential
Authority Hint - Non-secret routing/presentation metadata.
Configuredis never proof of authenticated identity; authoritative operations still read the OS store. - Credential
Read Error - One terminal authoritative-read failure.
- Credential
Read Event Handoff - Atomic starting point for an ordered credential-event consumer.
- Credential
Read Event Subscription - One owned subscription to future credential-read lifecycle events.
- Credential
Read Status - Latest process-owned credential-read generation and its public state.
- Local
Auth Snapshot - A local, non-mutating view of the persisted Parslee login state.
- Login
Attempt Lease - Persisted reservation and worker fence for one browser login attempt.
auth.startpublishes the awaiting-callback form.auth.completemay atomically populate the worker fields exactly once before network I/O; only a completion carrying that exact claimed lease may replace credentials. - Refreshed
Tokens - Result of a
refresh_grant. The gateway may omit a rotated refresh token (reuse the prior one) and/or an expiry, so both are optional. - Resolved
Parslee Credential - Parslee request authority resolved from one credential snapshot.
- Token
Set /connect/tokensuccess body.
Enums§
- Auth
Attempt Phase - Durable phase of an incomplete browser login attempt.
- Auth
Completion State - Typed result returned by the local-only completion-status read.
- Auth
Operation Error - Classified failure for coordinator-backed auth operations.
- Credential
Authority State - Non-secret presentation state for passive auth surfaces.
- Credential
Read Event Close Reason - Why an ordered credential-event subscription stopped.
- Credential
Read Failure Kind - Stable recovery classes. No variant contains secret material.
- Credential
Read Mode - Whether an authoritative credential use may start a new physical read.
- Credential
Read Status State - Secret-free state suitable for daemon event fanout.
- Credential
State - Why there is no usable Parslee access token — for ERROR MESSAGES, not for control flow.
Constants§
- AUTH_
COMPLETION_ NETWORK_ DEADLINE - Maximum time allowed for the aggregate token-exchange and completion-session network phase.
- AUTH_
COORDINATOR_ QUEUE_ TIMEOUT - Maximum time an auth operation may wait behind another in-process coordinator operation before failing safely without starting storage work.
- AUTH_
PROCESS_ LOCK_ TIMEOUT - Maximum time allowed to acquire the per-user cross-process auth-state lock.
- AUTH_
STATE_ OPERATION_ BUDGET - Bound used for one authoritative credential-store read or publication in the login-worker budget. The macOS keychain helper enforces this duration; the other local backends are expected to complete within the same budget.
- DEFAULT_
API_ BASE - LOGIN_
ATTEMPT_ CALLBACK_ TTL - The host allows up to 300 seconds for the browser callback. Keep the durable reservation valid beyond that window so a callback at the edge can still atomically claim its bounded completion worker.
- LOGIN_
ATTEMPT_ WORKER_ SCHEDULING_ MARGIN - Explicit scheduler/runtime headroom after every bounded serial phase.
- LOGIN_
ATTEMPT_ WORKER_ SERIAL_ BUDGET - Worst-case serial work between calculating the redeeming lease expiry and the strict expiry check immediately before credential publication:
- LOGIN_
ATTEMPT_ WORKER_ TTL - Redeeming-worker lease derived from the complete serial budget plus positive scheduling margin. Keep this below the host’s 480-second reconciliation horizon when changing any component.
- PARSLEE_
ACCESS_ TOKEN_ KEY - PARSLEE_
API_ BASE_ KEY - PARSLEE_
EXPIRES_ AT_ KEY - PARSLEE_
REFRESH_ TOKEN_ KEY - REFRESH_
SKEW_ SECS - Seconds before the stored expiry at which
access_token_refreshingproactively refreshes — absorbs clock skew plus a slow request. Public so the daemon’sload_or_refreshshares the same threshold (#320).
Functions§
- access_
token - Current access token (env override first, then authoritative V2 record).
- access_
token_ is_ available - Whether Parslee inference may enter request-time credential reconciliation.
- access_
token_ lifetime_ remaining - Seconds of life left in the active access token, for callers that want to warn before a long operation dies rather than diagnose it afterwards.
- access_
token_ refreshing - Compatibility token-only view of
resolve_credential. - account_
id_ from_ session - Parse the stable account id from a
/connect/sessionresponse. - api_
base - Resolve the API base: explicit override → process environment → authoritative V2 record → default.
- auth_
completion - Read the latest browser completion without refreshing or mutating tokens.
- auth_
completion_ status - One local-only, coordinator-locked completion/lifecycle snapshot.
- auth_
completion_ status_ classified - Read completion proof while preserving a typed pre-operation deadline.
- auth_
generation - Current durable generation of the active Parslee credential identity.
- authorize_
url - Build the
/connect/authorizeURL the user opens in a browser. - claim_
login_ attempt - Atomically claim one exact awaiting-callback attempt for a single daemon worker. Duplicate, missing, stale, or expired attempts fail before OAuth token exchange.
- claim_
login_ attempt_ classified - Claim a login attempt while preserving a typed pre-operation deadline.
- commit_
login - Atomically publish a newly-authorized login and its attempt-bound completion.
- credential_
authority_ hint - Read the passive, non-authoritative auth hint from
CAR_HOME. - credential_
state - Classify the current credential state. See
CredentialState. - exchange_
code - Exchange an authorization code + PKCE verifier for tokens.
- fail_
login_ attempt - Persist a terminal result only while the worker still owns its exact fence.
- fetch_
status - Fetch the Parslee session JSON for the stored token. Returns the
raw response body (the caller renders it).
Ok(None)= not signed in. - fetch_
status_ with_ access - Fetch
/connect/sessionwith an explicitly supplied access token. - force_
refresh - Unconditionally refresh the Parslee bearer, for the reactive 401
path.
access_token_refreshingonly refreshes inside a proactive window keyed on the stored expiry — but a token can be revoked or invalidated server-side before its advertised expiry, and a token stored without an expiry never enters that window at all. When a live request is rejected with 401/403, the caller invokes this to mint a fresh bearer and retry once, instead of letting the failure poison 30-day model health (#313). - invalidate_
access_ token_ cache - Drop any process-cached access token.
- list_
accounts - List every known login (
activemarks the current one). Migrates a pre-multi-login session (tokens in the fixed slots, no registry entry) in. - local_
auth_ snapshot - Local pre-browser auth state. No network request or refresh occurs. The first read may import an attributable legacy session into the authoritative V2 record; an ambiguous legacy marker reports signed-out and its orphan token is discarded, so the caller can sign in again.
- logout
- Publish a signed-out tombstone before best-effort legacy cleanup.
- new_
state - Opaque OAuth
statevalue (CSRF guard). - pkce_
challenge - PKCE S256 challenge for a verifier.
- pkce_
verifier - PKCE code verifier (URL-safe, no padding).
- refresh_
credential - Force one coordinator-owned Parslee refresh after a server auth rejection.
- refresh_
grant refresh_tokengrant against/connect/token. Network-only — the caller persists. Mirrors the Parslee gateway contract used by the daemon’s own refresh path (car-server-core::parslee_auth): the gateway treats this as a public-client grant, so noclient_idis sent. This lives incar-auth(notcar-server-core) so the request-time inference path — which cannot depend oncar-server-core— shares one definition of “mint a fresh Parslee bearer” (#313).- remove_
account - Remove a login (deletes its stashed tokens). If it was active, switch to another remaining login, or clear the session when none remain.
- reserve_
login_ attempt - Atomically reserve one browser login attempt during
auth.start. Publishing a newer reservation advances the credential generation and permanently fences every older completion before any code can be redeemed. - reserve_
login_ attempt_ classified - Reserve a login attempt while preserving a typed pre-operation deadline.
- resolve_
credential - Resolve one Parslee credential through the process-owned flight.
- set_
active_ org - Set the account’s active organization (bearer
PUT /accounts/me/active-org). - subscribe_
credential_ read_ event_ handoff - Atomically capture the last secret-free status and subscribe to later ones.
- subscribe_
credential_ read_ events - Subscribe to future secret-free credential-read events without coalescing.
- subscribe_
credential_ read_ updates - Subscribe to the latest secret-free credential-read state snapshot.
- switch_
account - Switch the active login by publishing the selected account credential as part of the same V2 record.
- switch_
org - Switch the active organization silently by minting a fresh token
scoped to
org_idvia the refresh grant’sorganization_idoverride (/connect/token,grant_type=refresh_token). The backend validates membership and stampsactive_org=org_idon the new access token — which is what inference reads — so the switch takes effect without a browser re-authorization. Rotated tokens are persisted to the keychain. Also best-effort updates the account’s default org so a future fresh sign-in lands in the same place.