Expand description
What srv does with a service-OAuth account’s tokens once it has them: read the keychain blob, take the account’s email from the ID token, refresh near expiry, revoke on delete, and keep the user’s own OAuth client (BYO) in the keychain. docs/specs/SPEC_GOOGLE_CONNECTORS_GMAIL_CALENDAR_DRIVE_2026_10_14.md G0 (§2.1’s gaps, §3.1, D2, D8).
The flow that obtains the tokens is oauth_client. Every network call
here goes through OAuthHttp and every keychain call through
TokenSecrets, so tests stub both and never reach Google.
No token, refresh token, client secret or ID token is ever logged, put in
an error string, or returned over RPC: errors carry an HTTP status and the
provider’s error code, nothing from the request.
Structs§
- Http
Reply - A provider’s HTTP answer: the status and the JSON body (
{}when the body isn’t JSON). A token response’s body holds tokens, soDebugshows only the status and the OAuth error code. - IdToken
Claims - What srv keeps from an ID token. Not secret.
- Keychain
Secrets TokenSecretsoversecret_store, off the async workers (the keyring calls block).- Live
Http OAuthHttpover the network.- Saved
Client - A BYO OAuth client saved for a provider, reused by later connects.
- Token
Blob - An OAuth account’s keychain entry:
{access_token, refresh_token, expires_at}as JSON, plus the client secret of a BYO client that has one, so a refresh uses the same client the account was made with (D8) even after the saved BYO client is cleared or replaced.
Enums§
- Client
Mode - Where an account’s OAuth client came from: AgentMux’s own, the user’s own, or the user’s own created as an “Internal” Workspace app.
- Refresh
Error - Why a refresh produced no token.
Constants§
- RECONNECT_
NEEDED - The start of every error that means “reconnect, don’t retry”.
- REFRESH_
MARGIN_ SECS - Refresh an access token this many seconds before it expires.
- STATUS_
NEEDS_ REAUTH - The account status a refresh answered with
invalid_grantleaves behind. The Connectors card shows it as “Reconnect needed” (identity-manager.tsx).
Traits§
- OAuth
Http - The calls srv makes to a provider’s OAuth endpoints.
- Token
Secrets - Reads and writes of an account’s keychain entry.
Functions§
- access_
token_ for - A valid access token for
account: the stored one, or a refreshed one when it expires withinREFRESH_MARGIN_SECS(written back to the keychain). A plain (non-OAuth) secret is returned as it is. A grant the provider no longer accepts marks the accountSTATUS_NEEDS_REAUTHand fails withRECONNECT_NEEDED; it is never retried. - account_
client - The client an account was made with, as recorded in its context
(
context.oauth_client). The client id isn’t secret. - bearer_
value - The value to use as a token for a stored secret: the
access_tokenof an OAuth blob, or the secret itself when it is a plain key. An OAuth-connected GitHub account used to reach agents asGH_TOKEN='{"access_token":…}'(spec §2.3). - clear_
saved_ client - Forget the client saved for
provider. Accounts made with it keep working: each keeps its own copy of what a refresh needs. Returns whether one was saved. Blocking. - granted_
scopes - The scopes a token response granted. Google, Microsoft and Slack separate
them with spaces, GitHub with commas. RFC 6749 §5.1 lets a server omit
scopewhen it granted exactly what was asked, so then it isrequested. - id_
token_ claims - Read an ID token’s claims. It came straight from the token endpoint over TLS, so per OIDC Core §3.1.3.7 (6) the TLS server check stands in for the signature; the issuer, audience and expiry are still checked. Errors never quote the token.
- load_
saved_ client - The client saved for
provider, if any. Blocking (keychain). - missing_
scopes - What was asked for and not granted: the user can untick any scope on
Google’s consent screen (granular consent, spec §3.1).
emailandprofilematch the full names Google returns for them. - refresh_
blob - Exchange
blob’s refresh token for a new access token with the client the account was made with. Pure apart fromhttp. - revoke_
before_ delete - Before an OAuth account is deleted, revoke its grant at the provider, so
it doesn’t live on there (spec §7 “Disconnect”).
Nonewhen there’s nothing to revoke: not an OAuth account, a provider with no revoke endpoint, or no stored token. Otherwise{ outcome: "revoked" | "failed", detail? }, for the delete’s result. - revoke_
blob - Revoke
blob’s grant atrevoke_url(RFC 7009). The refresh token is sent when there is one: revoking it ends the whole grant, where an access token may already have expired. - save_
client - Save
clientforprovider, replacing any saved before. Blocking. - saved_
client_ key - The keychain entry a provider’s saved client lives in.