Repository navigation
feat(api): serve an OAuth client that presents its client ID metadata document - #3488
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🦋 Changeset detectedLatest commit: b87e74d The changes in this PR will be included in the next version bump. This PR includes changesets to release 27 packages
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 |
…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
…hangeset Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U
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
…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
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U
There was a problem hiding this comment.
🟡 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) |
| // 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


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.enabledoff, which is the default.httpsURL 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'shttpsand loopback redirect URIs. Its metadata says so (client_id_metadata_document_supported). No customer project's issuer does.client_idmust be the URL it was fetched from. It is read again after an hour, or after what itsCache-Controlsays 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.none. A document that names another method is served when itstoken_endpoint_auth_methods_supportedoffersnone, as ChatGPT's does.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.isson every answer. The authorization endpoint's own error redirects carry it too, in place of anyissthe redirect URI already holds, and the metadata advertises it (RFC 9207).oauth.client_documents(NEXTGEN_OAUTH_CLIENT_DOCUMENTS), on by default: withfalsethe 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/apiunless noted:go vet ./..., and with-tags sqlite_integrationon the integration packagesgo test ./... -count=1go test -tags sqlite_integration ./internal/api/integration_test/... ./internal/storage/stmttest/... -count=1ZITADEL_TEST_POSTGRES_URL):go test -tags postgres_integration ./internal/api/integration_test/ -count=1node scripts/go-lint.mjs,turbo run check-generate openapi --filter=@zitadel/server,node scripts/check-adrs-index.mjsandpnpm 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)full-prpassed on the last commit.TestOAuthClientWithADocumentruns 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 startfrom this branch (NEXTGEN_OAUTH_ENABLED=true), 30 checks, with the document on a local TLS host the server was told to trust:client_id_metadata_document_supported,none,refresh_token,offline_accessandauthorization_response_iss_parameter_supported;queryUsersas the person;zitadel startallows loopback for local development; the run turned that off for this check);NEXTGEN_OAUTH_CLIENT_DOCUMENTS=false, the metadata no longer listsclient_id_metadata_document_supportedand 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-storecounts wherever it stands inCache-Control, and the server's own origin is recognised with its default port spelled out. Run for it inapps/api:go vet ./...,go test ./internal/service/ ./internal/oauth/ -count=1,go test -tags sqlite_integration ./internal/api/integration_test/ -run TestOAuth -count=1, andnode 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
issits redirect URI carries. Run for it at the top of the stack (#3499's head, which holds these commits), inapps/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, andturbo run lint --filter=@zitadel/server(repo root), which includescheck-generate.Release notes / 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
httpsURLs at the rate they call the authorization endpoint, 16 at a time, because a failed fetch is not remembered (ADR 082 §9 decides that). feat(api): name the hosts whose OAuth clients a server admits without registration #3499's host list bounds it when set; a short memory of failures or a rate limit would bound it without one. And the token endpoint opens a refresh token before it authenticates the client, so its answer tells whether text is a token this project sealed.iss.clientdoc.invalid,clientdoc.unavailable.publishApplicationtakes a project secret only, and the platform project hands none out), so Cursor and Gemini CLI, which register dynamically or by hand, stay out.https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U
Generated by Claude Code