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
(PARSLEE_ACCESS_TOKEN, default "car" service) — see
car-inference remote.rs::lease_key.
Structs§
- Account
Meta - Non-secret metadata for one signed-in Parslee login.
- 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. - Token
Set /connect/tokensuccess body.
Constants§
- DEFAULT_
API_ BASE - 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 keychain).
- access_
token_ refreshing - Current access token, proactively refreshed when the stored token
is within
REFRESH_SKEW_SECSof expiry (or already expired) and a refresh token is available. ThePARSLEE_ACCESS_TOKENenv override always wins and is never refreshed — it’s a deliberate injection for tests/CI. ReturnsNoneonly when no token is available at all. - api_
base - Resolve the API base: explicit override → stored → default.
- authorize_
url - Build the
/connect/authorizeURL the user opens in a browser. - clear_
tokens - Remove all stored Parslee credentials. Idempotent.
- exchange_
code - Exchange an authorization code + PKCE verifier for tokens.
- 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. - 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). - 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. - 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_
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).- register_
active_ login - After a fresh sign-in wrote the fixed slots, fetch the session, register the login (id/email/name), stash its tokens, and mark it active. Returns the id.
- 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.
- set_
active_ org - Set the account’s active organization (bearer
PUT /accounts/me/active-org). - stash_
active_ account - Save the currently-active fixed-slot tokens into the active login’s stash, so the outgoing login isn’t lost on a switch / add-account.
- store_
tokens - Persist a token set + the API base into the OS keychain (default
"car"service — the same placecar-inferencereads from). - switch_
account - Switch the active login: stash the current active’s latest tokens, load the target’s stashed tokens into the fixed slots. Sync (keychain only) — the caller should refresh/re-fetch the session afterward.
- 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.