Skip to content

feat(api): sign a person in for an MCP client, with scopes and consent - #3494

Merged
fforootd merged 16 commits into
claude/festive-hamilton-y0f0dxfrom
claude/oauth-person-sign-in
Dec 1, 2026
Merged

fforootd merged 16 commits into
claude/festive-hamilton-y0f0dxfrom
claude/oauth-person-sign-in

Conversation

@fforootd

@fforootd fforootd commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

Context

Summary

With oauth.enabled, the management API takes an access token the platform project's issuer signed for a person, and holds it to its scopes. A sign-in answers the authorization request for such a token, with consent for a client that is not the project's own. Nothing changes for a server that leaves oauth.enabled off, which is the default.

A person's token on the API

  • The person is the principal. They act with the grants their Console session has, on the operations a Console session may call. Events name the person and the client that acted for them.
  • Scopes are a ceiling, never a grant. An operation that names a scope the token was not issued with answers 403 with the new error code auth.scope_insufficient and the challenge WWW-Authenticate: Bearer error="insufficient_scope" (RFC 6750 §3). project.write is one scope among the others, not the umbrella it is for a project secret. Where a session's grants waive a scope on an expanded read, a token still needs the scope. The two secrets keep the rule they had.
  • The token ends with its session. It names the session it was issued in, and the API checks that session on every call.
  • The token endpoint issues such a token. An authorization request names the API with resource (RFC 8707) and asks for scopes the API's document declares. A resource the issuer has no API for answers invalid_target, and a scope the API does not define invalid_scope. A request without resource gets what it got before: a token for its client.
  • The MCP endpoint follows. It shows a person's token the tools its scopes cover among the operations the API takes it on, serves its protected-resource metadata (RFC 9728) at /.well-known/oauth-protected-resource/api/v1/mcp, and names it in the challenge of a 401.
  • A token for the MCP endpoint works only through the endpoint. The API takes it on the calls the endpoint makes and on no other, so its holder cannot call an operation the endpoint offers no tool for, such as one that returns a secret.
  • Reading the project takes project.read. getProject, listProjectMembers and search name project.write, which guards them from the preview secret. A person's token reads them with project.read, as the permission catalog has it for an operator. A test holds that list to the spec.

The sign-in that answers the request

  • The handle opens nothing by itself. POST /flows with auth_request_id starts a flow only from the browser the authorization endpoint redirected, which holds the request's binding cookie, on the issuer's origin, while the request is open. Anything else answers 400 with the new error code flow.auth_request_invalid. On a secure origin only the __Host- cookie is read, so no other host can plant one.
  • The flow ends in the client's redirect. Whatever its terminal step says, the answer is the registered redirect URI with code, state and iss. The code is issued after the handoff, which is what proves the sign-in complete, and is bound to the flow's session: it buys a token only once the browser exchanged the handoff.
  • Consent is a step the engine inserts. Before it answers a client that is not first-party, the flow shows a consent step with the new step.consent: the client's name, the host its answer goes to, the API and the scopes. No flow definition holds the step, so no edit removes it, and consent and account_choice are now reserved step names. Accepting continues to the code. Denying returns error=access_denied, signs nobody in and ends the request.
  • Consent is asked on every request. Nothing remembers one yet. A client that is asked anyway may now send prompt=consent; a first-party client still cannot.
  • The platform's login is the Console's. The platform project's issuer sends the browser to the Console's /login, which keeps the handle and shows the sign-in to someone it already knows too.
  • <zitadel-login> reads the handle from the page's auth_request parameter, renders the consent step with the project's template, and exchanges the handoff before it follows the redirect.
  • What is asked is an atom, <zl-consent>. The built-in template and both ejectable designs place it above the step's two answers. A template that leaves it out, such as one written before the step existed, gets it back before its first button, by the same safety net that puts back a required field. When the step appears, focus goes to the summary and not to a button, so the Enter that sent the password allows nothing.
  • The title names the client whatever a template passes to it. consent.title says {client}, which the page fills in from the step, so a template that greets the visitor in every title does not show "Authorize Alice".
  • The mock API answers an authorization request. A test opens one with openAuthRequest(...), and a flow started with its handle passes through the consent step and ends in the client's redirect, as on the server. A handle nobody opened is refused with flow.auth_request_invalid.

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, and ./internal/storage/stmttest/ on the commit that changed storage
  • 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, the components' unit project and the console's tests (repo root)
  • CI's full-pr passed on this PR's last commit while it was part of feat(api): serve an OAuth client that presents its client ID metadata document #3488.

TestOAuthSignInFromTheAuthorizationEndpointToAToken runs the flow over HTTP from end to end: the authorization endpoint, the login flow, consent, the code, the session exchange and the token endpoint.

In a browser, against a local server. Started with zitadel start from this branch (NEXTGEN_OAUTH_ENABLED=true), Chromium went from /oauth/authorize through the Console's sign-in and the consent step to a loopback client, which bought a token and used it:

  • consent shows the client, its redirect host, the MCP endpoint and the scopes; focus is on the summary, and a second Enter allows nothing;
  • Allow returns code, state and iss; the code is spent once; Deny returns access_denied;
  • a token for the MCP endpoint lists the eight tools user.read project.read cover, runs queryUsers as the person, and is refused on the API outside the endpoint;
  • a first-party client gets no consent; its token for the API reads users and answers auth.scope_insufficient on a write; signing out ends it;
  • another browser given the same link cannot start the sign-in, and the Console's ordinary sign-in still works.

The test client of that run was planted in the local database.

Not run: the Spanner lane locally, the journey lane, and a real MCP client.

After an automated review, one more commit: the 403 for a missing scope carries the bearer challenge, and reloading the consent step after its sign-in ran out answers flow.restart_required where it answered a server fault. 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.

After the frontend review, one more commit (2c6ef56): the consent step's summary is the <zl-consent> atom, a project's template renders the step, the safety net puts a missing summary back, the title's {client} needs no switch in a template, the mock API answers an authorization request, and the handoff is exchanged by one helper. Run for it at the repo root:

  • turbo run typecheck lint test --filter=@zitadel/components --filter=@zitadel/api-mock --filter=@zitadel/storybook --filter=@zitadel/config: the components' unit, edge and browser projects (80 files), the mock's unit and browser projects with its OpenAPI conformance check, and Storybook's tests, where the new atom's story passes the accessibility gate;
  • turbo run demo-next-mock --filter=@zitadel/e2e (4 passed) and turbo run demo-nuxt-mock --filter=@zitadel/e2e (2 passed), since maybeCompleteFlow changed;
  • turbo run typecheck lint test --filter=@zitadel/console.

In the browser project: focus lands on the summary when the consent step appears, a second Enter and a Space allow nothing, and both answers are one Tab away.

Release notes / changeset

  • Changeset: .changeset/api-person-token.md — with oauth.enabled, the management API and the MCP endpoint take an access token issued for a person, held to its scopes (@zitadel/server, @zitadel/api)
  • Changeset: .changeset/oauth-sign-in-consent.md — a sign-in answers an OAuth authorization request, with consent for a client that is not the project's own (@zitadel/server, @zitadel/api, @zitadel/components, @zitadel/config)

Notes

  • Breaking. A flow definition can no longer name a step consent or account_choice. POST /flows refuses an auth_request_id it accepted before without the request's cookie.
  • New error codes. auth.scope_insufficient is listed on every operation that takes both a bearer and a session cookie, and flow.auth_request_invalid on the three flow operations. The error-response files, the bundled document and the generated Go server and client are regenerated for them, which is about 13,000 of the 18,700 added lines.
  • Migration. auth_requests gains a nullable resource column (Postgres 000061, SQLite 000048, Spanner 000065). feat: add public OAuth clients with origins and private-use redirects #3409 may claim the same numbers; whichever merges later renumbers.
  • No client connects by this PR alone. publishApplication takes a project secret only, and the platform project hands none out, so the platform project cannot register a client. feat(api): serve an OAuth client that presents its client ID metadata document #3488, the top of the stack, lets a client in by its metadata document.
  • Who skips consent. A client whose document says first_party: true, which a declared client is by default and a registered one only when its document says so. Whoever may write an application (application.write) can therefore register a client that is asked no consent. That was the document's meaning before; this PR is the first code that reads it.
  • Seen in the local run, not fixed here. The MCP endpoint's 401 challenge names no scope, so a client asks for every scope its metadata lists. The issuer's metadata lists every scope the API's document declares, 57 today, where the endpoint's lists the 26 a person's token can use.
  • No design frame for the atom. The Storybook recipe starts from a Figma frame; <zl-consent> was built from the markup the step already had, on existing tokens. The PR author accepted it without one.
  • The demos still cannot open an authorization request. The mock opens one in process (openAuthRequest); the standalone mock server serves no authorization endpoint, so the demo e2e lanes cover the handoff and not consent.
  • Open from the review, not changed: the handoff and the authorization code are two writes. If the second fails, the sign-in is spent and the person signs in again; no code was issued.
  • A refusal spends the request. Denying gives the request a code that nobody receives, so no later flow answers it. That reuses the stored request as it is; a column of its own would say it more plainly.
  • Someone already signed in signs in again. No request is answered from a live session yet.
  • The consent screen lists scopes by name. A host can word a scope through locales (consent.scope.<scope>); the platform's scopes have no lines of their own yet.
  • Scopes the endpoint lists. Its metadata lists every scope a person's token can use, 26 today, deletes among them. A client that asks for all of them asks for a long consent. ADR 092 keeps this as an open question.
  • Token response. It carries scope whenever the request was granted one.

https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U


Generated by Claude Code

…ts scopes

With oauth.enabled the management API takes an access token the platform
project's issuer signed for a person (ADR 036, amendment of 2026-11-25). The
person is the principal, with the grants their Console session has, on the
operations a Console session may call. The token's scopes are a ceiling on
them and never a grant: an operation that names a scope the token was not
issued with answers 403 auth.scope_insufficient, and project.write is one
scope among the others, not the umbrella it is for a project secret. Where a
session's grants waive a scope on an expanded read, a token still needs the
scope. The two secrets keep the rule they had.

The verifier checks the signature against the platform project's own keys,
the type, the issuer and the expiry, and that the session the token names is
active and its subject's, so a token ends when its session does. A token
issued for the MCP endpoint is taken only on the calls the endpoint makes,
so its holder cannot call an operation the endpoint offers no tool for. The
endpoint shows a person's token the tools its scopes cover among the
operations the API takes it on.

Nothing issues such a token yet: the token endpoint still signs for the
client as audience and drops every scope.

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

The platform project's issuer signs tokens for the server's own API. An
authorization request names the API with resource (RFC 8707), by the API's
URL or the MCP endpoint's, and asks for scopes the API's document declares.
The request is stored with both, and the token its code buys carries the
resource as its audience, the scopes, and the session it was issued in,
which the API checks on every call. A request without a resource gets what
it got: a token for its client, with no scope and no session claim.

A resource the issuer has no API for is refused with invalid_target, which
for a customer project's issuer is every resource, and a scope the API does
not define with invalid_scope. Both go back to the client before anyone
signs in. OpenID Connect's scopes are ignored, as before.

The authorization requests table gains a nullable resource column in the
three dialects.

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

The MCP endpoint is an OAuth protected resource when the platform project's
issuer signs tokens for it. It serves its metadata (RFC 9728) at
/.well-known/oauth-protected-resource/api/v1/mcp, ahead of the OAuth server's
well-known subtree, and names it in the challenge of a 401. The metadata
names the issuer and the scopes a person's token can be used for: those of
the operations that take such a token.

Three reads a person's token reaches name project.write, which guards them
from the preview secret until the credential planes split: getProject,
listProjectMembers and search. A person's token reads them with
project.read, as the permission catalog has it for an operator, and that
scope writes nothing. A test holds the list to the spec.

The endpoint asks the API one question about a credential, whether it covers
an operation, where it asked two. ADR 091 and the permission catalog say what
is checked now, and what still keeps a client from signing a person in.

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

A flow started with auth_request_id now ends in the redirect that carries
the code to the client (ADR 081 §8 and §9), and the engine puts a consent
step before it for a client that is not the project's own (§11).

- POST /flows opens a flow for a request only from the browser that holds
  the request's binding cookie, on the issuer's origin, while the request is
  open, and against the deployment it resolved. Anything else answers
  flow.auth_request_invalid. On a secure origin only the __Host- cookie is
  read.
- The code is issued after the handoff, which is what proves the sign-in
  complete, and is bound to the flow's session: it buys a token only once
  the browser exchanged the handoff.
- The consent step is the engine's. No definition holds it, and consent and
  account_choice are reserved step names. It is asked of a person who has
  proven who they are, on every request, and carries the client's name, the
  host its answer goes to, the API and the scopes. Accepting continues to
  the code. Denying returns access_denied, signs nobody in and spends the
  request.
- The platform project's issuer sends the browser to the Console's sign-in
  page.
- A client that is asked for consent anyway may send prompt=consent.

TestOAuthSignInFromTheAuthorizationEndpointToAToken runs the authorization
code flow over HTTP from the authorization endpoint to the token endpoint.

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

The login page the authorization endpoint sends a browser to has the
request's handle in its auth_request parameter.

- <zitadel-login> reads the handle from the page URL and sends it with the
  flow it starts, also when it restarts one.
- It renders the consent step with its built-in template whatever the
  project's branding says: the client's name, the host its answer goes to,
  the API and one line per scope, worded by consent.scope.<scope> in locales
  or else the scope itself. Focus goes to that summary, never to a button,
  so the Enter that sent the password allows nothing.
- On the redirect that answers the request it exchanges the handoff first,
  since the code buys a token only once the session holds the sign-in. A
  refusal carries no handoff and is followed at once. A redirect of a flow
  for no request is unchanged.
- The Console's /login keeps the handle and shows the sign-in to someone it
  already knows too, where it used to send them on.
- The centered branding design stays the bundled template's copy.

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

ADR 091 §8 now lists the sign-in that answers an authorization request and
the consent step as built, and drops the sentence that said the server
refuses every third-party client: it never did. What still keeps a client
from connecting stays listed: a client that may ask, client documents,
refresh tokens, remembered consent and the cloud's routes.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U
A sign-in page opened for an authorization request that expired, was
answered, or belongs to another browser showed the server's own message,
lowercase and with no next step. <zitadel-login> now words
flow.auth_request_invalid itself, in the visitor's language: what happened,
and to go back to the app and start again.

Found by running the flow in a browser against a local server.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U
@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: d70c77e

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

@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:46:29.053290Z bfcb783 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.

…guments and lifetime

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

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

Unresolved issues can strand sign-ins after transient database failures, turn normal consent expiry into server errors, and omit the required bearer challenge for insufficient-scope responses.

3 open issues
What changed in this PR

Adds OAuth sign-in and consent for person-bound access tokens, extending the existing MCP endpoint and management API while keeping OAuth disabled by default.

Changes:

  • Connects authorization requests to browser-bound login flows, consent, and authorization-code issuance.
  • Adds resource audiences, scope ceilings, MCP discovery, and corresponding API errors.
  • Updates consent rendering, Console routing, storage migrations, tests, and public contracts.
File Description
packages/​go/​api/​oas_validators_gen.go Regenerates consent validation.
packages/​config/​src/​validation/​flow.ts Reserves engine-owned step names.
packages/​config/​src/​validation/​flow.test.ts Tests reserved step names.
packages/​config/​defaults/​branding/​centered/​login.liquid Adds consent summary rendering.
packages/​components/​src/​orchestrator/​templates/​layout-chrome.css Styles the consent summary.
packages/​components/​src/​orchestrator/​templates/​default.liquid Adds built-in consent rendering.
packages/​components/​src/​orchestrator/​template-context.ts Types the consent template context.
packages/​components/​src/​orchestrator/​locales/​it.ts Adds Italian consent messages.
packages/​components/​src/​orchestrator/​locales/​en.ts Adds English consent messages.
packages/​components/​src/​orchestrator/​locales/​de.ts Adds German consent messages.
packages/​components/​src/​orchestrator/​liquid.ts Adds scope-label fallback.
packages/​components/​README.md Documents OAuth login and consent.
docs/​quick-start/​configuration.md Documents person-token MCP access.
docs/​design/​api/​system-permission-catalog.md Clarifies token scope enforcement.
apps/​console/​src/​routes/​login.tsx Preserves authorization requests during login.
apps/​console/​src/​routes/​auth-guard.spec.tsx Tests OAuth login routing.
apps/​api/​internal/​storage/​stmttest/​auth_request_test.go Tests resource persistence.
apps/​api/​internal/​storage/​dialect/​sqlite/​migration/​sql/​000048_auth_request_resource.sql Adds SQLite resource column.
apps/​api/​internal/​storage/​dialect/​sqlite/​auth_request.go Persists SQLite request resources.
apps/​api/​internal/​storage/​dialect/​spanner/​migration/​sql/​000065_auth_request_resource.sql Adds Spanner resource column.
apps/​api/​internal/​storage/​dialect/​spanner/​auth_request.go Persists Spanner request resources.
apps/​api/​internal/​storage/​dialect/​postgres/​migration/​sql/​000061_auth_request_resource.sql Adds PostgreSQL resource column.
apps/​api/​internal/​storage/​dialect/​postgres/​auth_request.go Persists PostgreSQL request resources.
apps/​api/​internal/​service/​mocks/​service.mock.go Regenerates client lookup mocks.
apps/​api/​internal/​service/​flow.go Validates authorization-request browser binding.
apps/​api/​internal/​service/​flow_test.go Tests request admission and binding.
apps/​api/​internal/​service/​flow_engine.go Wires authorization-request services.
apps/​api/​internal/​service/​flow_auth_request.go Implements consent and OAuth answers.
apps/​api/​internal/​service/​flow_auth_attempt.go Exposes attempt completion checks.
apps/​api/​internal/​service/​auth_request.go Issues resource- and session-bound tokens.
apps/​api/​internal/​service/​auth_request_test.go Tests resource-token claims.
apps/​api/​internal/​service/​application.go Exposes deployment-specific client lookup.
apps/​api/​internal/​oauth/​server.go Adds platform login and API configuration.
apps/​api/​internal/​oauth/​issuer.go Exposes platform issuer construction.
apps/​api/​internal/​oauth/​client.go Tracks first-party status and requested scopes.
apps/​api/​internal/​mcp/​handler.go Adds discovery and operation-level credential checks.
apps/​api/​internal/​flowengine/​state.go Tracks consent progress.
apps/​api/​internal/​flowengine/​state_machine.go Routes consent submissions.
apps/​api/​internal/​flowengine/​render.go Restores consent on reload.
apps/​api/​internal/​flowengine/​mock/​generate.go Adds authorization-request mock generation.
apps/​api/​internal/​flowengine/​completion.go Gates completion on consent and issues redirects.
apps/​api/​internal/​flowengine/​auth_attempt.go Adds completion-check interface.
apps/​api/​internal/​domain/​flow_errors.go Defines invalid authorization-request error.
apps/​api/​internal/​domain/​flow_definition.go Defines reserved step names.
apps/​api/​internal/​domain/​flow_definition_validator.go Rejects reserved step names.
apps/​api/​internal/​domain/​flow_definition_validator_test.go Tests reserved-name rejection.
apps/​api/​internal/​domain/​auth.go Defines insufficient-scope error.
apps/​api/​internal/​domain/​auth_request.go Adds requested resource field.
apps/​api/​internal/​domain/​application.go Adds client display name.
apps/​api/​internal/​api/​user.go Enforces scope ceilings on team expansion.
apps/​api/​internal/​api/​scopes.go Derives declared and person-token scopes.
apps/​api/​internal/​api/​scopes_test.go Checks scopes against the API contract.
apps/​api/​internal/​api/​integration_test/​oauth_token_test.go Updates test ownership comment.
apps/​api/​internal/​api/​integration_test/​mcp_test.go Updates MCP authentication harness.
apps/​api/​internal/​api/​integration_test/​helpers/​server.go Wires token verification and browser binding.
apps/​api/​internal/​api/​integration_test/​helpers/​flow.go Wires OAuth flow collaborators.
apps/​api/​internal/​api/​integration_test/​helpers/​access_token.go Adds person-token test helper.
apps/​api/​internal/​api/​generated/​oas_validators_gen.go Regenerates server consent validation.
apps/​api/​internal/​api/​flow.go Maps browser binding, consent, and errors.
apps/​api/​internal/​api/​flow_internal_test.go Tests consent mapping and binding cookies.
apps/​api/​internal/​api/​error_handler.go Maps insufficient scope to HTTP 403.
apps/​api/​internal/​api/​deployment.go Enforces release-expansion scope ceiling.
apps/​api/​internal/​api/​authz.go Applies token ceilings to scope waivers.
apps/​api/​internal/​api/​authz_contract_internal_test.go Reads scope and read-only contract metadata.
apps/​api/​internal/​api/​auth_request_binding.go Exposes request-binding cookies to flows.
apps/​api/​cmd/​server/​mux_test.go Tests MCP discovery and platform login paths.
apps/​api/​api/​openapi/​endpoints/​variables/​listVariables-error-response.yaml Adds insufficient-scope response.
apps/​api/​api/​openapi/​endpoints/​variables/​by_name/​getVariable-error-response.yaml Adds insufficient-scope response.
apps/​api/​api/​openapi/​endpoints/​users/​query/​queryUsers-error-response.yaml Adds insufficient-scope response.
apps/​api/​api/​openapi/​endpoints/​users/​createUser-error-response.yaml Adds insufficient-scope response.
apps/​api/​api/​openapi/​endpoints/​users/​by_id/​updateUser-error-response.yaml Adds insufficient-scope response.
apps/​api/​api/​openapi/​endpoints/​users/​by_id/​teams/​listUserTeams-error-response.yaml Adds insufficient-scope response.
apps/​api/​api/​openapi/​endpoints/​users/​by_id/​password/​getUserPasswordState-error-response.yaml Adds insufficient-scope response.
apps/​api/​api/​openapi/​endpoints/​users/​by_id/​passkeys/​listUserPasskeys-error-response.yaml Adds insufficient-scope response.
apps/​api/​api/​openapi/​endpoints/​users/​by_id/​identity_links/​listUserIdentityLinks-error-response.yaml Adds insufficient-scope response.
apps/​api/​api/​openapi/​endpoints/​users/​by_id/​getUser-error-response.yaml Adds insufficient-scope response.
apps/​api/​api/​openapi/​endpoints/​users/​by_id/​deleteUser-error-response.yaml Adds insufficient-scope response.
apps/​api/​api/​openapi/​endpoints/​teams/​query/​queryTeams-error-response.yaml Adds insufficient-scope response.
apps/​api/​api/​openapi/​endpoints/​teams/​createTeam-error-response.yaml Adds insufficient-scope response.
apps/​api/​api/​openapi/​endpoints/​teams/​by_id/​updateTeam-error-response.yaml Adds insufficient-scope response.
apps/​api/​api/​openapi/​endpoints/​teams/​by_id/​getTeam-error-response.yaml Adds insufficient-scope response.
apps/​api/​api/​openapi/​endpoints/​search/​search-error-response.yaml Adds insufficient-scope response.
apps/​api/​api/​openapi/​endpoints/​schemas/​listSchemas-error-response.yaml Adds insufficient-scope response.
apps/​api/​api/​openapi/​endpoints/​schemas/​flow-definition.json Reserves engine-owned step names.
apps/​api/​api/​openapi/​endpoints/​schemas/​by_id/​getSchema-error-response.yaml Adds insufficient-scope response.
apps/​api/​api/​openapi/​endpoints/​releases/​listReleases-error-response.yaml Adds insufficient-scope response.
apps/​api/​api/​openapi/​endpoints/​releases/​by_id/​revoke/​revokeRelease-error-response.yaml Adds insufficient-scope response.
apps/​api/​api/​openapi/​endpoints/​releases/​by_id/​getRelease-error-response.yaml Adds insufficient-scope response.
apps/​api/​api/​openapi/​endpoints/​projects/​by_id/​updateProject-error-response.yaml Adds insufficient-scope response.
apps/​api/​api/​openapi/​endpoints/​projects/​by_id/​origins/​remove/​removeProjectOrigin-error-response.yaml Adds insufficient-scope response.
apps/​api/​api/​openapi/​endpoints/​projects/​by_id/​origins/​addProjectOrigin-error-response.yaml Adds insufficient-scope response.
apps/​api/​api/​openapi/​endpoints/​projects/​by_id/​members/​listProjectMembers-error-response.yaml Adds insufficient-scope response.
apps/​api/​api/​openapi/​endpoints/​projects/​by_id/​getProject-error-response.yaml Adds insufficient-scope response.
apps/​api/​api/​openapi/​endpoints/​policies/​revisions/​by_id/​getPolicyRevision-error-response.yaml Adds insufficient-scope response.
apps/​api/​api/​openapi/​endpoints/​policies/​listPolicies-error-response.yaml Adds insufficient-scope response.
apps/​api/​api/​openapi/​endpoints/​policies/​evaluate/​evaluatePolicy-error-response.yaml Adds insufficient-scope response.
apps/​api/​api/​openapi/​endpoints/​policies/​by_id/​revisions/​listPolicyRevisions-error-response.yaml Adds insufficient-scope response.
apps/​api/​api/​openapi/​endpoints/​policies/​by_id/​getPolicy-error-response.yaml Adds insufficient-scope response.
apps/​api/​api/​openapi/​endpoints/​oauth_settings/​by_id/​getOAuthSettings-error-response.yaml Adds insufficient-scope response.
apps/​api/​api/​openapi/​endpoints/​invitations/​listInvitations-error-response.yaml Adds insufficient-scope response.
apps/​api/​api/​openapi/​endpoints/​invitations/​createInvitation-error-response.yaml Adds insufficient-scope response.
apps/​api/​api/​openapi/​endpoints/​invitations/​by_id/​getInvitation-error-response.yaml Adds insufficient-scope response.
apps/​api/​api/​openapi/​endpoints/​invitations/​by_id/​cancelInvitation-error-response.yaml Adds insufficient-scope response.
apps/​api/​api/​openapi/​endpoints/​idps/​revisions/​by_id/​getIdpRevision-error-response.yaml Adds insufficient-scope response.
apps/​api/​api/​openapi/​endpoints/​idps/​query/​queryIdps-error-response.yaml Adds insufficient-scope response.
apps/​api/​api/​openapi/​endpoints/​idps/​by_id/​getIdp-error-response.yaml Adds insufficient-scope response.
apps/​api/​api/​openapi/​endpoints/​grants/​query/​queryGrants-error-response.yaml Adds insufficient-scope response.
apps/​api/​api/​openapi/​endpoints/​grants/​createGrant-error-response.yaml Adds insufficient-scope response.
apps/​api/​api/​openapi/​endpoints/​grants/​by_id/​getGrant-error-response.yaml Adds insufficient-scope response.
apps/​api/​api/​openapi/​endpoints/​grants/​by_id/​deleteGrant-error-response.yaml Adds insufficient-scope response.
apps/​api/​api/​openapi/​endpoints/​flows/​submit/​submitFlowStep-error-response.yaml Adds OAuth completion errors.
apps/​api/​api/​openapi/​endpoints/​flows/​session/​getFlowStep-error-response.yaml Adds OAuth flow errors.
apps/​api/​api/​openapi/​endpoints/​flows/​createFlow-error-response.yaml Adds invalid authorization-request response.
apps/​api/​api/​openapi/​endpoints/​flow_definitions/​listFlowDefinitions-error-response.yaml Adds insufficient-scope response.
apps/​api/​api/​openapi/​endpoints/​flow_definitions/​by_id/​getFlowDefinition-error-response.yaml Adds insufficient-scope response.
apps/​api/​api/​openapi/​endpoints/​events/​listEvents-error-response.yaml Adds insufficient-scope response.
apps/​api/​api/​openapi/​endpoints/​events/​by_id/​getEvent-error-response.yaml Adds insufficient-scope response.
apps/​api/​api/​openapi/​endpoints/​deployments/​listDeployments-error-response.yaml Adds insufficient-scope response.
apps/​api/​api/​openapi/​endpoints/​deployments/​createDeployment-error-response.yaml Adds insufficient-scope response.
apps/​api/​api/​openapi/​endpoints/​deployments/​by_id/​rollback/​rollbackDeployment-error-response.yaml Adds insufficient-scope response.
apps/​api/​api/​openapi/​endpoints/​deployments/​by_id/​getDeployment-error-response.yaml Adds insufficient-scope response.
apps/​api/​api/​openapi/​endpoints/​branding/​listBranding-error-response.yaml Adds insufficient-scope response.
apps/​api/​api/​openapi/​endpoints/​branding/​by_id/​getBranding-error-response.yaml Adds insufficient-scope response.
apps/​api/​api/​openapi/​endpoints/​applications/​revisions/​by_id/​getApplicationRevision-error-response.yaml Adds insufficient-scope response.
apps/​api/​api/​openapi/​endpoints/​applications/​query/​queryApplications-error-response.yaml Adds insufficient-scope response.
apps/​api/​api/​openapi/​endpoints/​applications/​by_id/​getApplication-error-response.yaml Adds insufficient-scope response.
apps/​api/​api/​openapi/​components/​schemas/​errors/​flow-auth_request_invalid.yaml Adds generated flow-error schema.
apps/​api/​api/​openapi/​components/​schemas/​errors/​auth-scope_insufficient.yaml Adds generated scope-error schema.
apps/​api/​api/​openapi/​components/​flows/​flow-step.yaml Defines consent payload and actions.
apps/​api/​api/​openapi/​components/​flows/​flow-definition-step.yaml Reserves consent and account-choice names.
apps/​api/​api/​openapi/​components/​flows/​create-flow-request.yaml Documents browser binding and OAuth completion.
apps/​api/​api/​openapi/​components/​examples/​errors/​flow-auth_request_invalid.yaml Adds generated flow-error example.
apps/​api/​api/​openapi/​components/​examples/​errors/​auth-scope_insufficient.yaml Adds generated scope-error example.
apps/​api/​api/​cmd/​gen_openapi_errors/​main.go Generates person-token scope errors.
.changeset/​oauth-sign-in-consent.md Records consent features and breaking changes.
.changeset/​api-person-token.md Records person-token and MCP support.

Review effort: Balanced

Comment on lines +294 to +295
if hasDomain && logged.Code == scopeInsufficientCode {
return http.StatusForbidden, logged, domainErrorDetails(logged)
Comment on lines +61 to +64
if pc.state.AuthRequestID != nil {
if err := r.answerAuthRequest(pc, rendered); err != nil {
return StepResult{}, err
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Not changed in this PR. The handoff and the authorization code are two writes by two services, each in its own transaction, and making them one needs a transaction the flow engine does not span today.

What a failure between the two costs is a repeated sign-in. No code was issued, and the attempt cannot be handed off a second time, so nothing is left that anyone could redeem. An atomic completion is a change to the flow engine's storage and belongs in a PR of its own.


Generated by Claude Code

Comment on lines +41 to +43
if consent == nil {
return StepResult{}, fmt.Errorf("%w: the consent step shows and nothing asks for it", domain.ErrFlowIntegrity())
}
…step whose sign-in ran out

Two findings of the review:

- A token refused for a scope it lacks was told so in the body only. The
  403 now carries `WWW-Authenticate: Bearer error="insufficient_scope"`
  (RFC 6750 §3.1), where an OAuth client looks first.
- Reloading the consent step after the signed-in attempt had expired or
  been handed off answered 500 `flow.integrity`. It is the sign-in running
  out, so it answers `flow.restart_required`, as a submit would.

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

@peintnermax peintnermax left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I reviewed the frontend part (packages/components, packages/config, the Console's /login) against #2795. The widget's handling of the handle and the exchange-before-redirect are what the issue asks for, and the server-side binding check makes the handle safe to carry in the URL.

My main point is the consent step: I'd rather not override the tenant's template, and use the mandatory-gates safety net with a <zl-consent> atom. Details inline. The rest is about tests and the rules in packages/components/AGENTS.md.

// for what would turn the screen into a bare "Allow" button.
const tenantSource =
typeof this.branding?.liquid_template === "string" && this.branding.liquid_template.length > 0
!step.consent &&

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we keep the tenant's template here? Until now branding owns the template for every step, and this is the first exception. A tenant on a custom template gets the bundled card for this one step.

We already solve "a template must not drop this" for required fields and the primary action: patchMandatoryGates runs after every render. A third case in collectMissingAtoms would cover consent: if step.consent is set and the output has no consent summary, build one and insert it. It should go before the first action button, not at the marker, because the marker sits after the actions in all bundled templates.

If the override stays, it is a product decision that should be in an ADR, not only in a code comment.

pressed on the step before lands on a button.
{% endcomment %}
{% if consent %}
<dl class="zl-consent" data-testid="zitadel-consent" tabindex="-1">

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd make this a <zl-consent> atom. As template markup it has no manifest entry, no Storybook story and so skips the a11y gate, and its CSS lives in layout-chrome.css. An atom also gives the safety net (see my comment on renderStep) a tag to detect and one element to build; a class is something a tenant template could reuse on anything. The recipe is in apps/storybook/AGENTS.md.

The consent step's heading names the client that asks; every other
step's may greet the visitor by name.
{% endcomment %}
{% assign heading_name = identity.display_name %}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This puts step-specific knowledge into every template: a tenant template written before this PR passes identity.display_name and would render "Authorize <the user's name>". Could the title's argument be resolved before the template sees it, in stepTexts or on the server, so no template needs the switch?

pressed on the step before lands on a button.
{% endcomment %}
{% if consent %}
<dl class="zl-consent" data-testid="zitadel-consent" tabindex="-1">

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

With the override in renderStep, this block never renders: a project using this file as its liquid_template gets the built-in template on the consent step. minimal/login.liquid was not changed. Either both get the block (if the override goes) or neither needs it.

firstResponse = flow(consentStep);
exchangeStatus = 200;
server.resetHandlers(
http.post("*/flows", async ({ request }) => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

packages/components/AGENTS.md asks for setupMockHandlers() from @zitadel/api-mock, never hand-rolled handlers. The mock API does not know auth_request_id or the consent step yet, so the demos and their e2e lanes cannot exercise this flow. Could the mock learn both, and this spec use it?

expect(text("zitadel-consent-client")).toBe("Acme Reports");
});

it("takes focus on what is asked, so the Enter that sent the password allows nothing", async () => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Focus belongs in the browser project (*.browser.spec.ts) per the testing ladder; jsdom's focus handling is not what a browser does, and this test guards a security property (Enter must not allow the client).

// handoff is exchanged before the browser leaves for the client. A
// refusal carries no handoff and leaves at once. Any other redirect is
// the host's own page, which takes the handoff from the event above.
if (handoffToken && authRequestFromLocation()) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Two things:

  • This block repeats the exchange-then-navigate code of the postSignInUrl branch below. A shared helper would keep the two from drifting.
  • AGENTS.md asks for both demo e2e lanes after a change to maybeCompleteFlow, since each exercises a different SDK middleware. The description says the e2e lanes were not run. Could you run e2e:demo-next and e2e:demo-nuxt?

// The consent step puts focus on what is asked, never on a button: the
// Enter that sent the password must not also be the one that lets a
// client in.
const consent = root.querySelector<HTMLElement>(".zl-consent");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Fine as a rule. If consent becomes an atom, this selector should follow the tag, and the atom should own tabindex and its focus style.

…n-sign-in

# Conflicts:
#	apps/api/internal/mcp/handler.go
#	docs/adrs/092-mcp-server.md
…project's template places

From the frontend review of the sign-in that answers an authorization request.

The consent step was the one step rendered by the built-in template whatever
a project's branding said, with its markup and styles in the template and
the shared stylesheet. It is now a step like any other:

- `<zl-consent>` is an atom, with a manifest entry, a story under the
  accessibility gate and its own styles. The built-in template and both
  ejectable designs place it above the step's two answers.
- A template that renders no summary gets it back before its first button,
  by the safety net that puts back a required field: nobody is asked to
  allow a client they are not shown.
- `consent.title` names the client through `{client}`, which the page fills
  in from the step, so a template that greets the visitor in every title
  needs no switch for this step.
- The handoff is exchanged before the browser leaves by one helper, shared
  by the answer to an authorization request and `post-sign-in-url`.

The mock API learns both ends of it: a test opens a request with
`openAuthRequest(...)`, and a flow started with its handle passes through
the `consent` step and ends in the client's redirect. The component's spec
drives that mock in place of handlers of its own, and the focus test runs in
the browser project.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U
Both take a bearer and a session cookie, so their error lists gain
`auth.scope_insufficient`, as every such operation's does on this branch.

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

This branch was successfully deployed

1 active deployment
Preview — d70c77ea 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.

4 participants