Skip to main content

Module oauth_tokens

Module oauth_tokens 

Source
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§

HttpReply
A provider’s HTTP answer: the status and the JSON body ({} when the body isn’t JSON). A token response’s body holds tokens, so Debug shows only the status and the OAuth error code.
IdTokenClaims
What srv keeps from an ID token. Not secret.
KeychainSecrets
TokenSecrets over secret_store, off the async workers (the keyring calls block).
LiveHttp
OAuthHttp over the network.
SavedClient
A BYO OAuth client saved for a provider, reused by later connects.
TokenBlob
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§

ClientMode
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.
RefreshError
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_grant leaves behind. The Connectors card shows it as “Reconnect needed” (identity-manager.tsx).

Traits§

OAuthHttp
The calls srv makes to a provider’s OAuth endpoints.
TokenSecrets
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 within REFRESH_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 account STATUS_NEEDS_REAUTH and fails with RECONNECT_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_token of an OAuth blob, or the secret itself when it is a plain key. An OAuth-connected GitHub account used to reach agents as GH_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 scope when it granted exactly what was asked, so then it is requested.
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). email and profile match 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 from http.
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”). None when 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 at revoke_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 client for provider, replacing any saved before. Blocking.
saved_client_key
The keychain entry a provider’s saved client lives in.