Skip to content

feat(api): serve an OAuth client that presents its client ID metadata document - #3488

Merged
fforootd merged 12 commits into
claude/oauth-refresh-tokensfrom
claude/api-person-token-scope-checks
Dec 1, 2026
Merged

fforootd merged 12 commits into
claude/oauth-refresh-tokensfrom
claude/api-person-token-scope-checks

Conversation

@fforootd

@fforootd fforootd commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

Context

Summary

A client needs no registration with the platform project's issuer: it presents the URL of its client ID metadata document, as Claude, ChatGPT, Codex, VS Code and Zed do. Nothing changes for a server that leaves oauth.enabled off, which is the default.

  • A client ID that is an https URL names a document. The platform project's issuer fetches it and serves the client it describes: public, never the project's own, with the document's https and loopback redirect URIs. Its metadata says so (client_id_metadata_document_supported). No customer project's issuer does.
  • The fetch is the egress client's (ADR 061): public addresses only, no redirect, JSON of at most 16 KiB, five seconds. The document's client_id must be the URL it was fetched from. It is read again after an hour, or after what its Cache-Control says between five minutes and a day; a failed fetch is not remembered, and while a host does not answer, what it said last stands. A document its host withdrew stays withdrawn through a later outage: an answer that is no usable document, a refused redirect and an oversized body among them, replaces what was read before.
  • The client must be able to authenticate with none. A document that names another method is served when its token_endpoint_auth_methods_supported offers none, as ChatGPT's does.
  • Consent says who vouches. The step shows the host that serves the document (step.consent.client.document_host) and warns when the answer goes to a loopback address of the person's device (loopback), since any local program can present another client's document and listen there. Both are part of the <zl-consent> atom from feat(api): sign a person in for an MCP client, with scopes and consent #3494 (document-host, loopback-warning), so a project's own template shows them too.
  • iss on every answer. The authorization endpoint's own error redirects carry it too, in place of any iss the redirect URI already holds, and the metadata advertises it (RFC 9207).
  • One setting turns it off. oauth.client_documents (NEXTGEN_OAUTH_CLIENT_DOCUMENTS), on by default: with false the metadata no longer lists the support, and a client with a document is an unknown client.

ADR 092 §8 lists what is built and what is not. What still keeps Claude or ChatGPT from connecting to the cloud: its routes for /oauth/ and /.well-known/, and a public address.

Validation

Run in apps/api unless noted:

  • go vet ./..., and with -tags sqlite_integration on the integration packages
  • go test ./... -count=1
  • go test -tags sqlite_integration ./internal/api/integration_test/... ./internal/storage/stmttest/... -count=1
  • Against a local PostgreSQL 16 (ZITADEL_TEST_POSTGRES_URL): go test -tags postgres_integration ./internal/api/integration_test/ -count=1
  • node scripts/go-lint.mjs, turbo run check-generate openapi --filter=@zitadel/server, node scripts/check-adrs-index.mjs and pnpm run check-openapi-rules (repo root)
  • turbo run lint typecheck test --filter=@zitadel/config, turbo run lint typecheck --filter=@zitadel/components --filter=@zitadel/console, and the components' unit project (repo root)
  • CI's full-pr passed on the last commit.

TestOAuthClientWithADocument runs it over HTTP from end to end: a document on a TLS host, PKCE, no secret, refusals with their reason.

In a browser, against a local server. Started with zitadel start from this branch (NEXTGEN_OAUTH_ENABLED=true), 30 checks, with the document on a local TLS host the server was told to trust:

  • the metadata lists client_id_metadata_document_supported, none, refresh_token, offline_access and authorization_response_iss_parameter_supported;
  • consent shows the client's name, the host that publishes it, the loopback address the answer goes to with the warning, the MCP endpoint and the scopes;
  • the client exchanges its code without a secret, and a code without its PKCE verifier buys nothing;
  • its token lists eight tools at the MCP endpoint and runs queryUsers as the person;
  • a refresh rotates; the replaced token is answered once more; a token two rotations old ends the grant; signing out ends a grant;
  • the document is fetched once for all of it;
  • refused with the reason: no document at the URL, a document behind a redirect, a client that only authenticates with a key, a redirect URI the document does not list;
  • with the server's default egress policy, no request reaches a document on a loopback address (zitadel start allows loopback for local development; the run turned that off for this check);
  • with NEXTGEN_OAUTH_CLIENT_DOCUMENTS=false, the metadata no longer lists client_id_metadata_document_supported and a client with a document is an unknown client.

The documents Claude, Claude Code, ChatGPT, Codex, VS Code, Zed, goose and Antigravity published on 2026-12-01 were fetched and read by the parser: all eight are served.

Not run: the e2e lanes, and a real MCP client: the container cannot reach a client's document host directly, which the server's egress client requires. CI ran the components' browser project.

After a review of the stack, one more commit: a refused or reset connection and a failing name server now read as an outage (temporarily_unavailable) and not as the client's refusal, no-store counts wherever it stands in Cache-Control, and the server's own origin is recognised with its default port spelled out. Run for it in apps/api: go vet ./..., go test ./internal/service/ ./internal/oauth/ -count=1, go test -tags sqlite_integration ./internal/api/integration_test/ -run TestOAuth -count=1, and node scripts/go-lint.mjs.

After an automated review, one more commit: a withdrawn document is no longer served again when its host stops answering, a redirect the egress client refuses and a body over the limit count as the host's answer, and an error redirect replaces an iss its redirect URI carries. Run for it at the top of the stack (#3499's head, which holds these commits), in apps/api: go vet ./..., go test ./... -count=1, go test -tags sqlite_integration ./internal/api/integration_test/ ./internal/api/integration_test/helpers/ ./internal/bootstrap/platform/ -count=1, and turbo run lint --filter=@zitadel/server (repo root), which includes check-generate.

Release notes / changeset

  • Changeset: .changeset/oauth-client-documents.md — the platform's issuer serves a client that presents its client ID metadata document (@zitadel/server, @zitadel/api, @zitadel/components, @zitadel/config)

Notes

https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U


Generated by Claude Code

@vercel

vercel Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
cloud Ready Ready Preview Dec 1, 2026 6:02pm UTC

Request Review

@github-actions

github-actions Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

🦋 Changeset detected

Latest commit: b87e74d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 27 packages
Name Type
@zitadel/server Minor
@zitadel/api Minor
@zitadel/components Minor
@zitadel/config Minor
@zitadel/cli Minor
@zitadel/sdk-angular Minor
@zitadel/sdk-core Minor
@zitadel/sdk-next Minor
@zitadel/sdk-nuxt Minor
@zitadel/sdk-qwik Minor
@zitadel/sdk-react Minor
@zitadel/sdk-solid Minor
@zitadel/sdk-svelte Minor
@zitadel/sdk-tanstack-start Minor
@zitadel/sdk-vue Minor
@zitadel/testing Minor
@zitadel/cloud Patch
@zitadel/client-sdk-contract Patch
@zitadel/sdk-qwik-router Minor
@zitadel/sdk-solid-start Minor
@zitadel/sdk-sveltekit Minor
@zitadel/server-sdk-contract Patch
@zitadel/server-darwin-arm64 Minor
@zitadel/server-darwin-x64 Minor
@zitadel/server-linux-arm64 Minor
@zitadel/server-linux-x64 Minor
@zitadel/server-win32-x64 Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@fforootd fforootd changed the title Add MCP endpoint and auth scope validation for API operations feat(api): accept a person's access token on the management API, held to its scopes Dec 1, 2026
@fforootd
fforootd changed the base branch from main to claude/festive-hamilton-y0f0dx December 1, 2026 00:51
@fforootd fforootd changed the title feat(api): accept a person's access token on the management API, held to its scopes feat(api): accept a person's access token on the management API, and sign them in for one with consent Dec 1, 2026
…client ID

The platform project's issuer reads a client ID metadata document where a
client ID is an https URL, and its metadata says so. No customer project's
issuer does. Such a client is public, never the project's own, and exists
nowhere but in its document.

The document is fetched with the egress policy: from public addresses only,
without a redirect, as JSON of at most 16 KiB, within five seconds. Its
client_id must be the URL it was fetched from, and it must offer the `none`
authentication method. Of its redirect URIs the https ones and the loopback
ones are kept. It is read again after an hour, or after what its
Cache-Control says between five minutes and a day; a failed fetch is not
remembered, and while a host does not answer, what it said last stands.

The consent step names the host that serves the document, and says when the
answer goes to a loopback address of the person's device. The authorization
endpoint's own error redirects carry `iss`, and the metadata advertises it.

A token request without a secret gets one answer for an unknown client and
for a confidential one, so the endpoint does not tell which client IDs
exist.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U
… an answer to this device

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U
@fforootd fforootd changed the title feat(api): accept a person's access token on the management API, and sign them in for one with consent feat(api): sign a person in for an MCP client, with scopes, consent, refresh tokens and client documents Dec 1, 2026
A host that could not be reached at all was read as a document that is
gone, so a refresh during a DNS or connection failure at a client's vendor
refused the client. Only an answer of the host withdraws a document the
server has read; a host that cannot be reached changes nothing while an
earlier read is kept.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U
…t_documents

With the authorization server on, the platform project's issuer admits any
client that presents its metadata document. `oauth.client_documents`
(`NEXTGEN_OAUTH_CLIENT_DOCUMENTS`), on by default, turns that off as a
whole: only the clients of the project's applications then sign people in,
and the issuer's metadata no longer says that it reads documents.

It is the one switch until an operation policy narrows which documents are
admitted. A policy's settings are numbers, booleans and enumerated strings,
so one that names the admitted hosts needs a setting that holds a list.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U
@fforootd fforootd changed the title feat(api): sign a person in for an MCP client, with scopes, consent, refresh tokens and client documents feat(api): serve an OAuth client that presents its client ID metadata document Dec 1, 2026
@fforootd
fforootd changed the base branch from claude/festive-hamilton-y0f0dx to claude/oauth-refresh-tokens December 1, 2026 05:20
…ge, not as the client's refusal

A refused or reset connection, or a name server that failed, was reported
as an unusable document. With no copy kept, as after a restart, the token
endpoint then answered `invalid_client`, which a client reads as its own
refusal and drops its grant for. Those faults are now "unavailable", as a
timeout was: the client is told to try again. What the URL itself causes
stays a refusal: an address the server does not fetch from, a name that
does not exist, a certificate that does not verify.

Two smaller corrections:

- `no-store` and `no-cache` count wherever they stand in `Cache-Control`,
  not only before `max-age`.
- The server recognises its own origin when a client ID spells the default
  port, and still fetches no document from itself.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U
@fforootd
fforootd marked this pull request as ready for review December 1, 2026 06:37
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
🔒 Security Review ✅ Completed 2026-12-01T06:47:28.832888Z 96aead8 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Critical cache revalidation flaws can reuse withdrawn documents or accept unusable responses through outage fallback, while error redirects can retain a client-supplied issuer.

3 open issues
What changed in this PR

Adds registration-free OAuth clients to the platform issuer through client ID metadata documents, building on the stack’s sign-in, consent, and refresh-token support.

Changes:

  • Fetches and validates client documents with bounded egress requests, caching, outage fallback, and an operator disable switch.
  • Shows document provenance and loopback warnings during consent.
  • Adds issuer identifiers to authorization error redirects and updates discovery metadata, API contracts, tests, and documentation.
File Description
packages/​go/​api/​oas_schemas_gen.go Generated consent fields and document-error types.
packages/​go/​api/​oas_json_gen.go Generated JSON handling for new fields and errors.
packages/​config/​defaults/​branding/​centered/​login.liquid Shows document host and loopback warning.
packages/​components/​src/​orchestrator/​zitadel-login-auth-request.spec.ts Tests provenance, warnings, and safe name rendering.
packages/​components/​src/​orchestrator/​templates/​layout-chrome.css Styles the loopback warning.
packages/​components/​src/​orchestrator/​templates/​default.liquid Adds document provenance and device warning.
packages/​components/​src/​orchestrator/​locales/​it.ts Adds Italian consent text.
packages/​components/​src/​orchestrator/​locales/​en.ts Adds English consent text.
packages/​components/​src/​orchestrator/​locales/​de.ts Adds German consent text.
packages/​components/​README.md Documents expanded consent presentation.
docs/​quick-start/​configuration.md Documents the client-document setting.
docs/​operations/​nextgen.example.yaml Adds example configuration and explanatory comments.
docs/​adrs/​092-mcp-server.md Records implemented support and remaining MCP gaps.
docs/​adrs/​082-oauth-and-oidc-server.md Records authentication and discovery amendments.
apps/​api/​internal/​service/​flow_engine.go Wires consent through the client directory.
apps/​api/​internal/​service/​flow_auth_request.go Resolves document clients and builds consent details.
apps/​api/​internal/​service/​flow_auth_request_test.go Tests document consent and lookup failures.
apps/​api/​internal/​service/​client_document.go Implements bounded fetching, caching, and fallback.
apps/​api/​internal/​service/​client_document_internal_test.go Tests fetching, freshness, failures, and concurrency limits.
apps/​api/​internal/​service/​client_directory.go Unifies declared and document-based client lookup.
apps/​api/​internal/​service/​client_directory_test.go Tests admission, lookup, and own-origin refusal.
apps/​api/​internal/​oauth/​token.go Maps document failures to token-endpoint responses.
apps/​api/​internal/​oauth/​token_test.go Tests invalid and unavailable document responses.
apps/​api/​internal/​oauth/​server.go Wires discovery and issuer-response middleware.
apps/​api/​internal/​oauth/​metadata.go Advertises document and issuer-parameter support.
apps/​api/​internal/​oauth/​metadata_test.go Tests discovery capabilities and admission failures.
apps/​api/​internal/​oauth/​authorize.go Reports document failures and adds iss to refusals.
apps/​api/​internal/​oauth/​authorize_test.go Tests document refusals and issuer parameters.
apps/​api/​internal/​flowengine/​auth_request.go Extends consent data with provenance and loopback status.
apps/​api/​internal/​domain/​client_document.go Defines document validation, parsing, and errors.
apps/​api/​internal/​domain/​client_document_test.go Tests document validation and public-client conversion.
apps/​api/​internal/​cache/​names.go Names the client-document cache.
apps/​api/​internal/​api/​integration_test/​oauth_sign_in_test.go Extends consent response decoding.
apps/​api/​internal/​api/​integration_test/​oauth_metadata_test.go Recognizes the new discovery fields.
apps/​api/​internal/​api/​integration_test/​oauth_client_document_test.go Exercises document-client authorization and token flows.
apps/​api/​internal/​api/​integration_test/​helpers/​oauth.go Uses the client directory in OAuth fixtures.
apps/​api/​internal/​api/​integration_test/​helpers/​harness.go Tracks document-host and admission fixtures.
apps/​api/​internal/​api/​integration_test/​helpers/​flow.go Uses the client directory in flow fixtures.
apps/​api/​internal/​api/​integration_test/​helpers/​client_document.go Provides TLS document hosting and test admission.
apps/​api/​internal/​api/​generated/​oas_schemas_gen.go Regenerates server consent and error types.
apps/​api/​internal/​api/​flow.go Serializes optional consent details.
apps/​api/​internal/​api/​error_handler_test.go Records document errors outside API status mappings.
apps/​api/​cmd/​server/​server.go Configures fetching, cache, directory, and defaults.
apps/​api/​cmd/​server/​server_test.go Tests default, environment, and YAML settings.
apps/​api/​cmd/​server/​config.go Adds the client-document configuration field.
apps/​api/​api/​openapi/​endpoints/​flows/​submit/​submitFlowStep-error-response.yaml Adds document-error variants and examples.
apps/​api/​api/​openapi/​endpoints/​flows/​session/​getFlowStep-error-response.yaml Adds document-error variants and examples.
apps/​api/​api/​openapi/​components/​schemas/​errors/​clientdoc-unavailable.yaml Generated unavailable-document error schema.
apps/​api/​api/​openapi/​components/​schemas/​errors/​clientdoc-invalid.yaml Generated invalid-document error schema.
apps/​api/​api/​openapi/​components/​flows/​flow-step.yaml Defines provenance and loopback consent fields.
apps/​api/​api/​openapi/​components/​examples/​errors/​clientdoc-unavailable.yaml Generated unavailable-document example.
apps/​api/​api/​openapi/​components/​examples/​errors/​clientdoc-invalid.yaml Generated invalid-document example.
apps/​api/​api/​openapi/​bundled/​openapi.json Regenerates the bundled API contract.
.changeset/​oauth-client-documents.md Announces support and the redirect-parameter change.

Review effort: Balanced

if known && (!answered || errors.Is(err, domain.ErrClientDocumentUnavailable(""))) {
return kept.Document, nil
}
return domain.ApplicationClientDocument{}, err
request.Header.Set("Accept", "application/json")
response, err := d.client.Do(request)
if err != nil {
return none, 0, false, fetchFailure(err)
Comment on lines +231 to +236
// The library wrote the query; the issuer is appended to it.
if target, err := url.Parse(location); err == nil && !strings.Contains(location, "#") {
if query := target.Query(); query.Has("error") && !query.Has("iss") {
w.Header().Set("Location", location+"&iss="+url.QueryEscape(w.issuer))
}
}
…issuer a redirect URI carries

Three findings of the review:

- A document its host answered 404 for was refused, but the copy the
  server kept stayed, and an outage after that served it again, with its
  old redirect URIs. The copy is now marked withdrawn. That is no
  remembered refusal: the document is fetched again on every request.
- A redirect, and a body announced as too large, are refused by the
  hardened client as errors, and were read as "the host did not answer",
  so a kept copy outlasted them. They are the host's answer.
- A redirect URI that carries an `iss` of its own kept it in the
  authorization endpoint's error redirects. The server's replaces it, as
  in the answer that carries a code.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U
…en-scope-checks

The consent step's summary became the `<zl-consent>` atom below this branch,
so what this branch adds to it moves into the atom: the host that serves an
unregistered client's document (`document-host`) and the warning under an
answer that goes to the visitor's own device (`loopback-warning`). The three
templates, the safety net, the mock API's request and the specs follow.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U
@fforootd
fforootd added this pull request to the merge queue Dec 1, 2026
Merged via the queue into main with commit 37e512b Dec 1, 2026
18 of 19 checks passed
@fforootd
fforootd deleted the claude/api-person-token-scope-checks branch December 1, 2026 20:44
@github-project-automation github-project-automation Bot moved this from Inbox to Done in Engineering Kanban Dec 1, 2026

This branch was successfully deployed

1 active deployment
Preview — b87e74d0 Deployed Dec 1, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants