Skip to main content

Module oauth_client

Module oauth_client 

Source
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 state generated 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.
OAuthSessionManager
PkcePair
A PKCE verifier/challenge pair. challenge = BASE64URL(SHA256(verifier)).
ResolvedClient
The client a flow runs with, and where it came from.
ServiceOAuthConfig
Static per-service OAuth configuration. client_id is None in the shipped scaffold — supply it (or BYO) to activate the provider.
StartOptions
What start needs besides the provider.
StopSignal
The flow task’s end of its session’s stop signal.

Enums§

FlowTarget
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.
OAuthFlow
How a provider’s OAuth flow is driven.
OAuthStatus
Terminal/transient status surfaced to the frontend poll.

Constants§

GOOGLE_CLIENT_ID
AgentMux’s own Google client id, from the agentmux-connectors project. 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.ts has 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’s extra_auth_params.
build_picker_url
The authorization URL that opens Google’s file picker in the browser: drive.file alone, trigger_onepick and prompt=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 account as provider unless 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_id intentionally None until 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 account was 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 uuid draws from the OS RNG) base64url-encoded — well within the 43–128 char range, charset-safe. Challenge uses S256 (never plain).
random_state
High-entropy CSRF state value. 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 polls manager().poll.
start_picker
Open Google’s file picker for account in 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 is OAuthStatus::Picked; the account’s tokens are not changed. Needs Drive turned on for the account (drive.file granted).