Skip to content

Sign in through Client ID Metadata Documents in managed OAuth - #259

Merged
tnkuehne merged 1 commit into
mainfrom
feat/managed-oauth-metadata-documents
Nov 21, 2026
Merged

tnkuehne merged 1 commit into
mainfrom
feat/managed-oauth-metadata-documents

Conversation

@tnkuehne

@tnkuehne tnkuehne commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

What changes

Configuration. A managed OAuth client can now name an authorization server that accepts OAuth Client ID Metadata Documents instead of a registered client:

{
  "origin": "https://oauth.example.com",
  "clientName": "Widefleet",
  "clients": {
    "tracker": {
      "registration": "client-id-metadata-document",
      "authorizationUrl": "https://auth.tracker.example/authorize",
      "tokenUrl": "https://auth.tracker.example/token",
      "resource": "https://mcp.tracker.example/mcp",
      "issuer": "https://auth.tracker.example",
      "revocationUrl": "https://auth.tracker.example/revoke",
      "scopes": ["read", "write"],
      "hosts": ["https://mcp.tracker.example"]
    }
  }
}

Such a client has no clientId or clientSecret. clientName is optional and defaults to Widefleet. Existing registered clients are unchanged.

Document. The runtime serves GET /oauth/client-metadata.json on the managed OAuth origin before app authentication, next to the existing callbacks. Its URL is the client ID. It lists the callback /oauth/callback/<client> of every metadata document client, token_endpoint_auth_method: none and the authorization code and refresh token grants. Without such a client, or on another origin, the path falls through to normal routing.

Broker. Authorization, code exchange, refresh and revocation use Better Auth's generic OAuth 2.0 helpers as a public client: PKCE, client_id set to the document URL, no client secret, and the configured resource (RFC 8707) on every request. Placeholders, bound refresh grants, scope limits and issuer checks work as for registered clients. A metadata document client's callback returns to /auth/callback/<client> on the app, since it has no Better Auth provider.

managedOAuth().callback() is renamed to handle(), because it now serves both public routes.

Not included

  • No template uses a metadata document client yet.
  • Endpoints are configured rather than discovered at runtime.
  • Dynamic Client Registration is not supported.

Tests

  • packages/app-runtime/src/oauth.test.ts: the document and its origin, method and client checks; authorization URL, token, refresh and revocation requests without a secret; resource omission; callback separation; strict configuration; silent error responses.
  • packages/app-runtime/src/oauth-metadata-document.test.ts: sign-in, a resource call, refresh and revocation against @cloudflare/workers-oauth-provider in workerd with clientIdMetadataDocumentEnabled, which fetches the published document and names the client from it.
  • pnpm check, the app runtime and template suites and apps/control-plane/tests/managed-oauth-runtime.test.ts pass locally.

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge; no actionable issues were found.

Summary

Adds managed OAuth sign-in through Client ID Metadata Documents.

  • Managed OAuth publishes a document for metadata-based clients.
  • Apps can sign in to services that use metadata documents.

No actionable issues were found. tnkuehne explicitly deferred template adoption. Tests were reviewed but not run.

Diagram

sequenceDiagram
  participant App
  participant Broker as Managed OAuth
  participant Server as Authorization server
  App->>Broker: Authorize with client name and PKCE
  Broker-->>App: Authorization URL
  App->>Server: Start authorization
  Server->>Broker: Fetch client metadata document
  Broker-->>Server: Client name and allowed callbacks
  Server-->>Broker: Code and sealed state
  Broker-->>App: Redirect to app callback
  App->>Broker: Exchange code with PKCE
  Broker->>Server: Exchange as public client
  Server-->>Broker: Tokens
  Broker-->>App: Access placeholder and sealed refresh grant
Loading

Reviews (1) · Last reviewed commit: "Sign in through Client ID Metadata Docum..." · Reviewed by Greptile

Operators can configure managed OAuth clients for authorization servers that
accept OAuth Client ID Metadata Documents, without registering a client with
each service. The runtime publishes the installation's document at
/oauth/client-metadata.json on the managed OAuth origin, listing the callback
of every such client. Its URL is the client ID; authorization, code exchange,
refresh and revocation use PKCE without a client secret and send the
configured RFC 8707 resource.

Tokens follow the existing rules: apps receive placeholders bound to the
client's hosts, refresh grants stay bound to app, organization and caller, and
granted scopes must stay within the client's scopes.
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
widefleet-docs 125a478 Nov 20 2026, 11:36 PM

@tnkuehne
tnkuehne merged commit 05d8668 into main Nov 21, 2026
17 checks passed
@tnkuehne
tnkuehne deleted the feat/managed-oauth-metadata-documents branch November 21, 2026 10:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant