Skip to content

OAuth sign-in for MCP servers: connect from Settings in the browser, tokens held and refreshed by Core #3512

Closed

Description

@integry

Problem

A library MCP server can authenticate only with nothing or with a static Bearer token. Many hosted MCP servers accept only OAuth: a person signs in interactively in a browser and the client receives short-lived access tokens plus a refresh token. Agent containers are headless and one-shot, so a login flow cannot happen inside a run.

Approach

ProPR acts as its own OAuth client. An administrator connects a server once from Settings, in their own browser. Core stores the tokens encrypted, refreshes them, and the existing MCP gateway injects a current access token into upstream calls exactly as it injects a static Bearer token today. Agent containers never see a token and never take part in a login flow, for Claude and Codex alike.

ProPR always identifies itself truthfully as ProPR. It must not present another product's client id, client metadata, redirect URI or user agent to an authorization server.

Requirements

  1. Contract: authentication on an https library server gains the value oauth (next to none and bearer). An oauth server stores no administrator-entered token. Optional administrator-entered fields: scopes (list), and for pre-registered clients clientId and a write-only clientSecret. Catalog servers are out of scope.
  2. Discovery, following the MCP authorization specification: an unauthenticated request to the server returns 401 with WWW-Authenticate naming the protected resource metadata (RFC 9728), with the well-known location as fallback; that document names the authorization server; fetch its metadata (RFC 8414, falling back to OpenID Connect discovery). Every discovery, registration and token request goes through the existing endpoint policy (HTTPS only, no private or loopback addresses unless the operator policy allows them, bounded size and time). A "Check" action in the server form runs discovery and reports what was found and which registration method will be used, without storing anything.
  3. Client registration, tried in this order and recorded on the item:
    • Client ID Metadata Document when the authorization server advertises support: ProPR serves its own client metadata document at a public HTTPS URL of this instance and uses that URL as the client id.
    • Dynamic Client Registration (RFC 7591) when a registration endpoint is advertised. The issued client id (and secret, if any) is stored with the item, the secret encrypted.
    • Pre-registered client: the administrator enters a client id (and secret if the provider issued one) obtained from the provider's developer console. The form shows the exact redirect URI to register there.
      When none is possible the form says so plainly and suggests a static Bearer token if the provider offers one.
  4. Authorization flow: authorization code with PKCE (S256). "Connect" in the server row opens the provider's authorization page in a new tab. The request carries a state that is random, single-use, expires after 10 minutes and is bound to the administrator's session, the library item and the item's endpoint; and the resource parameter (RFC 8707) set to the MCP server URL. The redirect URI is <public API base URL>/api/instance/extensions/v1/oauth/callback. The callback validates state, the iss parameter when the server supplies it (RFC 9207), exchanges the code, stores the tokens and shows a small result page that tells the Settings tab to refresh. If the instance has no public base URL configured, Connect is disabled with an explanation.
  5. Token custody: access token, refresh token, expiry, granted scopes and the registration secret are encrypted with the existing private-secret mechanism (privateSecrets.ts), bound to the instance and the library item, and are write-only: no API, MCP tool, CLI command, log line, task event, telemetry field or native export ever contains them. Exports erase them like other extension credentials. Connecting, refreshing and disconnecting do not create library revisions (they are credential state, not configuration), but connect and disconnect are recorded in the audit trail with the administrator and time.
  6. Refresh: Core refreshes an access token shortly before it expires and when the upstream answers 401. Refresh is single-flight per item (a second caller waits for the first result) and stores a rotated refresh token atomically with the new access token, so concurrent runs never invalidate each other's token. If refresh fails with an authorization error the item moves to Needs sign-in; network errors are retried and do not change the state.
  7. Gateway: for an oauth server the gateway asks Core for the current access token on each upstream call rather than using a token captured at launch, because a run can outlive a token. On an upstream 401 it triggers one refresh and retries the call once. The token is added to the gateway's redaction list.
  8. Launch: an oauth server that is not connected, or is in Needs sign-in, is left out of the run. For auto-applied items and for items an automation adds explicitly it is reported as skipped with the reason in the applied-extensions task event; the run itself proceeds. Changing an oauth server's URL, or switching its authentication type, discards its tokens and requires a new sign-in. Disabling the item keeps the connection.
  9. Settings UI (in the server list and form from the settings issue): an oauth server row shows its connection state (Not connected, Connected, Needs sign-in), who connected it and when, and the granted scopes; with Connect, Reconnect and Disconnect actions. Disconnect calls the provider's revocation endpoint when one is advertised, then deletes the stored tokens. The form explains that every run this server applies to acts with the access of the account that signed in, so a dedicated service account with the narrowest scopes is recommended.
  10. Notification: when an item moves to Needs sign-in, administrators receive one notification through the existing notification system (not one per run).

Out of scope

  • Login flows inside agent containers, and reuse of the Claude or Codex runtimes' own MCP connectors or stored credentials.
  • Presenting any other product's OAuth client identity.
  • Per-user connections: a connection belongs to the instance library item and is shared by every run the item applies to.
  • OAuth for operator catalog servers and for skills.

Acceptance criteria

  • Against a synthetic authorization server and MCP server fixture: discovery succeeds from the 401 challenge and from the well-known fallback; each of the three registration methods completes a sign-in; the stored connection is used by a run through the gateway.
  • PKCE verifier mismatch, unknown or reused or expired state, a state from another administrator's session, and a mismatched iss are each rejected and store nothing.
  • An expired access token is refreshed before use; two concurrent callers cause exactly one refresh request; a rotated refresh token is persisted; an upstream 401 causes one refresh and one retry.
  • A refresh rejected by the authorization server moves the item to Needs sign-in, sends one notification, and later runs launch without that server with the skip reason recorded. A network failure during refresh does not change the state.
  • Discovery, registration and token requests to private or loopback addresses are refused under the default endpoint policy.
  • Sentinel tests: no access token, refresh token or client secret appears in API responses, MCP projections, logs, task events, telemetry or a native export.
  • Changing the server URL discards the connection; disabling and re-enabling the item keeps it; Disconnect revokes (when supported) and deletes.
  • Only durable administrators with instance.manage_settings can start a sign-in, and the callback completes only for the session that started it.
  • UI component tests for the three states and the actions; a Playwright spec drives Connect against the fixture.
  • docs/docs/features/agent-extensions.md documents OAuth servers: how to connect, the three registration methods and the redirect URI, the shared-identity warning, refresh and Needs sign-in behaviour, and what is out of scope.

Implementation

  1. Shared: extend the server schema in packages/shared/src/extensionProfiles.ts (authentication: 'oauth', scopes, client fields) and the public connection-state projection.
  2. Core: new packages/core/src/extensions/extensionOAuth.ts (discovery, registration, PKCE, code exchange, refresh with single-flight, revocation), sending every request through endpointPolicy.ts. Token storage in a new table bound to instance + library item, encrypted with privateSecrets.ts; knex migration following the existing extension migrations.
  3. Gateway: packages/core/src/extensions/mcpGateway.ts resolves the secret for oauth servers per call through the store, with the one-retry-on-401 path and redaction.
  4. Launch: extensionLaunch.ts and resolveExtensionSet callers skip unconnected oauth servers with a reason.
  5. API: routes under /api/instance/extensions/v1 for check, start sign-in, callback, disconnect, and the public client metadata document; reuse how packages/api/mcp/oauth.ts derives the instance's public base URL. OpenAPI schemas, npm run gen:openapi.
  6. UI: connection state and actions in the server row and form components from the settings issue.
  7. Notification category for Needs sign-in through the existing notification service.
  8. Tests: a synthetic authorization server + MCP server fixture next to test/fixtures/extensionLaunchIntegration.ts; core, API and UI tests; Playwright spec.

Notes

Depends on the library, auto-apply and settings issues. Security invariants: tokens never leave Core in readable form; SSRF protection on every outbound OAuth request; state is single-use and session-bound; ProPR never impersonates another OAuth client. ProPR runs on SQLite only. Read the MCP authorization specification and docs/docs/features/agent-extensions.md first.

Activity

  1. propr-dev commented on Nov 13, 2026

    @propr-dev
    Contributor

    🤖 AI processing has started for this issue using claude agent with claude-opus-5-5 model.

    I'll analyze the problem and work on a solution. This may take a few minutes.

    Processing Details:

    • Agent: claude
    • Model: claude-opus-5-5
    • Branch: 3512/claude-opus-5-5-oauth-sign-in-for-mcp-ser-20261113-1145-czn
    • Base Branch: 3509-epic-extensions-library-14j
    • Worktree: issue-3512-20261113-1145-claude-opus-5-5-czn

    🔍 Track Task Execution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions