Add user-verified personal read-only agent registration

Merged
SI
1mo ago
+2152-84

Agents with an account holder's email can now request a personal read-only connection. Registration returns a six-digit code and a Recoup sign-in URL. No credential is issued until the account holder signs in with the matching verified email and explicitly approves.

The opt-in auth.md service-auth profile uses the existing OAuth issuer, encrypted store, grants, MCP permission checks, and Connected Agents revocation. Connections last one hour, access tokens at most five minutes, and assertion exchanges cannot extend that deadline. No refresh token, organization access, anonymous registration, or external-provider assertion trust is added.

The implementation includes atomic approval/polling transitions, five-attempt code lockout, single-use consent tickets, strict origin and input checks, bounded expiry cleanup, two token grants, token revocation, and truthful discovery/instructions. Ordinary PKCE requests retain oidc-provider's original form parsing.

Validation:

  • All 244 OAuth tests pass with the isolated PostgreSQL fixture enabled, including two provider instances sharing storage. Agent HTTP routing uses the in-memory fixture; provider and storage integration cases use PostgreSQL.
  • OAuth TypeScript and repository lint pass.
  • Tests cover code/identity binding, concurrency, expiry, scope/resource escalation, signed assertion validation, existing PKCE exchange, and revocation.
  • The configured Vercel preview passes the production build; local page collection requires the absent Privy project secret.

Deployment requires the companion database migration and chat consent page. OAUTH_AGENT_REGISTRATION_ENABLED defaults off. Apply the migration, deploy both services, enable and verify chat, then enable API and perform the account-holder read/denied-write/renew/disconnect smoke test. See docs/agent-registration.md for exact steps and rollback.

These synthetic test receipts do not establish live account-holder or named-agent-client interoperability. Merge and rollout await user approval.

Dependencies: Database #118 and App #2249.

The activation flag is read in loadOAuthConfig and gates the dispatcher in getOAuthRuntime. The Pages OAuth route applies shared/IP limits before initializing that runtime; identity registration also receives the stricter registration budgets. Regression tests pin both boundaries.

Registration, approval, polling, token-form parsing, and discovery are separate modules. Tests additionally pin the exact fifth-code lockout, malformed form rejection, upload draining, and a fixed deadline under an advancing clock. Identity infrastructure failures return a temporary error; logs contain a fixed operational event rather than credentials or provider diagnostics.

Malformed, reused, or concurrently consumed consent tickets return a client error; storage failures remain temporary errors. A failed approval revokes its entire grant family, including registration state, so subsequent polling terminates with expired_token. A partial-issuance regression test verifies this cleanup; moving the deleted registration to another status is unnecessary.