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§
- 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). - 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).- store_
tokens - Persist a token set + the API base into the OS keychain (default
"car"service — the same placecar-inferencereads from).