Expand description
Service-account OAuth 2.0 client for Connectors → Accounts.
Distinct from the CLI-provider OAuth in auth_session.rs (which scrapes a
spawned CLI’s stdout): this drives the flow itself — opens the system
browser, runs a transient loopback listener (or polls a device endpoint),
exchanges the code, and stores the resulting tokens in the OS keychain.
Security posture follows RFC 8252 (OAuth for Native Apps), RFC 7636 (PKCE, S256), RFC 8628 (Device Grant), and RFC 9700 (Security BCP):
- Authorization Code + PKCE(S256) over a loopback
127.0.0.1:<ephemeral>redirect for code-flow providers (Google, Microsoft). - Device Authorization Grant for GitHub (no client secret needed).
- High-entropy
stategenerated and verified on the callback (CSRF). - Public clients carry no secret; secret-mandatory providers (Slack) use BYO credentials (the user supplies their own client_id/secret).
- Tokens are stored in the OS keychain (never the DB, never logged).
Client status: the per-provider built-in client_ids are not yet
provisioned (client_id: None below), so a flow runs with the user’s own
client (BYO), which is saved in the keychain after the first successful
connect and reused (oauth_tokens::SavedClient, spec D8). With neither,
start returns a clear “not configured” error and no flow runs.
What happens to the tokens afterwards (refresh, revoke, the ID token) is
oauth_tokens. docs/specs/SPEC_GOOGLE_CONNECTORS_GMAIL_CALENDAR_DRIVE_2026_10_14.md
G0; the original design is docs/specs/archive/SPEC_TRUST_CENTER_2026_06_15.md §4.2/§12.1.
Structs§
- ByoCredentials
- BYO OAuth-app credentials, supplied by the user for secret-mandatory providers (Slack) or to override the built-in public client.
- OAuth
Session Manager - Pkce
Pair - A PKCE verifier/challenge pair.
challenge = BASE64URL(SHA256(verifier)). - Resolved
Client - The client a flow runs with, and where it came from.
- ServiceO
Auth Config - Static per-service OAuth configuration.
client_idisNonein the shipped scaffold — supply it (or BYO) to activate the provider. - Start
Options - What
startneeds besides the provider. - Stop
Signal - The flow task’s end of its session’s stop signal.
Enums§
- Flow
Target - What a flow connects: a new account, or an existing one authorized again — a service turned on (more scopes) or a reconnect — whose keychain entry is updated in place.
- OAuth
Flow - How a provider’s OAuth flow is driven.
- OAuth
Status - Terminal/transient status surfaced to the frontend poll.
Constants§
- GOOGLE_
CLIENT_ ID - AgentMux’s own Google client id, from the
agentmux-connectorsproject. Public: it is in every authorization URL. - NEEDS_
CLOUD_ SIGN_ IN - What a GitHub connect answers when the person isn’t signed in to AgentMux Cloud: a code the UI
turns into “Sign in to AgentMux Cloud to connect GitHub” and a sign-in button, never a bare error
(
frontend/app/view/accounts/github-cloud-gate.tshas the same string). GitHub through AgentMux’s own App is a Cloud feature (the Connect with GitHub design). - PICKER_
SCOPE - The scope Google’s desktop picker takes, and the only one it takes: the request can’t be combined with other scopes (spec §3.3).
Functions§
- build_
auth_ url - The authorization URL for a code flow: the standard parameters, PKCE
(S256) and
state, then the provider’sextra_auth_params. - build_
picker_ url - The authorization URL that opens Google’s file picker in the browser:
drive.filealone,trigger_onepickandprompt=consent, no refresh token and no earlier scopes asked for (spec §3.3, Google’s “Picker for desktop and mobile apps”). - builtin_
client_ available - Whether the build has a client of its own for the provider, secret included where the provider demands one.
- check_
reauth_ target - Refuse to re-authorize
accountasproviderunless it is a keychain OAuth account of that provider. - config_
for - Per-provider catalog. Endpoints + flow choice follow each provider’s
native-app guidance (see SPEC §12.1).
client_idintentionallyNoneuntil provisioned. - manager
- Process-global manager. A dedicated singleton (rather than an AppState field) keeps this scaffold’s blast radius small; service-OAuth sessions are short-lived and window-agnostic.
- oauth_
context - The account’s non-secret context after a successful flow: what was there before, plus the granted scopes, the client it was made with (D8), and the email and user id from the ID token.
- picker_
client - The client
accountwas made with, secret included (its token blob keeps a copy, D8): the picker has to run as that client. - pkce_
pair - Generate a PKCE pair. The verifier is 256 bits of CSPRNG entropy (two v4
UUIDs, as
uuiddraws from the OS RNG) base64url-encoded — well within the 43–128 char range, charset-safe. Challenge uses S256 (neverplain). - random_
state - High-entropy CSRF
statevalue. Verified byte-for-byte on the callback. - requested_
scopes - The scopes a connect asks for: the provider’s base scopes, then
extra(a service being turned on), without repeats. Each must be an RFC 6749 §3.3 scope token. - resolve_
client - Resolve the client a flow runs with: credentials passed with the request, else the user’s client saved for this provider, else the built-in one. Returns an error string when none is available (the “not configured” gate) or when a secret-mandatory provider is missing its secret.
- start
- Start an OAuth flow. Resolves config + client (gating on “not configured”),
creates a session, and spawns the background task that drives it. Returns
(session_id, initial_status). The frontend then pollsmanager().poll. - start_
picker - Open Google’s file picker for
accountin the system browser, with the client the account was made with (a picked file is the client’s to read, so no other client will do). The result isOAuthStatus::Picked; the account’s tokens are not changed. Needs Drive turned on for the account (drive.filegranted).