Skip to content

feat: let people choose which scopes to grant on the OAuth consent screen - #3543

Merged
fforootd merged 9 commits into
mainfrom
feat/consent-scope-choice
Dec 2, 2026
Merged

fforootd merged 9 commits into
mainfrom
feat/consent-scope-choice

Conversation

@fforootd

@fforootd fforootd commented Dec 2, 2026 •

Copy link
Copy Markdown
Member

Context

  • Refs ADR 082 §8 (consent) and ADR 092 open question 10 (which scopes an MCP client asks for).

Connecting an MCP client (Claude, ChatGPT, VS Code) to the platform's /api/v1/mcp gave it a token with all 28 person scopes, user.delete and deployment.write included. The endpoint's challenge names no scope, so the client asks for everything in scopes_supported; the issuer grants what was asked; and the consent step had only Allow and Deny.

Summary

The person now chooses which of the requested scopes to grant, and only reading starts ticked.

Server and API contract

  • The consent step's scopes[] gain group, access (read | change | delete | offline) and selected. access and group follow the naming rule <group>.<verb>: .read reads, .delete deletes, any other verb changes. An API's own declaration of them is to win once applications declare apis.
  • accept names the grant in fields.scopes. It must be a subset of the request and, when the request asks for any API scope, hold one; otherwise 400 flow.consent_scopes_invalid and the step stays. Granting nothing is deny.
  • When the request asks for an API scope, an accept without fields.scopes is refused the same way, so a screen that offered no choice grants nothing the person never saw. A request for no API scope still grants offline_access.
  • The engine checks the grant against the request; IssueCode checks it again and writes the narrowed scopes in the same UPDATE that stores the code (all three dialects). The token response's scope names the grant (a grant of no scope at all has none, and no refresh token); a refresh asking for more stays refused.
  • If the client becomes first-party while the step is open, an accept that names scopes still grants only those; one that names none keeps the request's.
  • New test: every scope our spec declares follows the naming rule.

<zitadel-login>

  • <zl-consent> offers the scopes as native checkboxes grouped by group, with "Read only" and "Everything requested" presets and "Stay connected" (offline_access) as its own toggle, ticked. Its value is the granted scopes; Allow stays disabled until an API scope is ticked.
  • The choice starts closed: one line of what is granted ("Read only · Stay connected"), under it the groups the grant reaches, a line per access ("View: Users, Audit log", "Edit: Teams", "Delete: Users"; every group, however many), and a "Change" button that opens the checkboxes. The person sees which kinds of data they allow without opening the choice; the lines describe Change, so a screen reader hears them before Allow. Allow and Deny follow it in the keyboard order however many scopes are asked for.
  • While Allow waits for an API scope, the choice says why ("Tick at least one permission to allow, or deny."). That line and the granted line are live regions that describe Change, and Enter opens the choice at its first scope instead of doing nothing.
  • A grant the server refuses (flow.consent_scopes_invalid) keeps the consent step with a translated reason, rather than replacing the page with the server's message.
  • The shipped templates (default, centered, minimal) pass the choice. The mandatory gate puts the server's choices into every consent summary a template renders, so a template words and lays out the choice but never decides what is offered or what starts ticked.
  • The component ships no words for any API's scopes. The app that asks for consent words them through locales, as consent.scope.<scope> and consent.group.<group>, like every other login text.

Console: its sign-in passes the Zitadel API's scope texts (28 scopes, 17 groups, en/de/it) through locales. A server test fails a person scope without a line there in all three languages.

API mock: classifies scopes like the server and refuses the grants the engine refuses, an unnamed accept of an API scope included. An action the consent step lacks is 400 flow.invalid_action, as on the server.

Validation

  • go test ./internal/... (apps/api)
  • go test -tags sqlite_integration on ./internal/api/integration_test/ ./internal/api/integration_test/helpers/ ./internal/bootstrap/platform/ ./internal/storage/dialect/sqlite/ ./internal/storage/stmttest/, including a new platform-API case: a token narrowed to user.read reads users and is refused createTeam.
  • turbo run generate --filter=@zitadel/server, then turbo run check-generate --filter=@zitadel/server
  • turbo run lint --filter=@zitadel/server: green except format, which flags internal/flowengine/sso_test.go. This PR doesn't touch that file, and it is unchanged from main.
  • turbo run lint typecheck --filter=@zitadel/components --filter=@zitadel/api-mock --filter=@zitadel/console --filter=@zitadel/storybook
  • vitest --project unit (1099) and --project browser (264) in packages/components, vitest in packages/api-mock (551), turbo run test --filter=@zitadel/console (1190), turbo run test --filter=@zitadel/storybook
  • Not run here: Postgres and Spanner storage tests (no Docker in the container). CI runs them.

Release notes / changeset

  • Changeset: .changeset/oauth-sign-in-consent.md. It is unreleased, so this PR edits it rather than adding one (.changeset/README.md). It lists @zitadel/server, @zitadel/api, @zitadel/components and @zitadel/config, and now says the person chooses the scopes and that an app words its API's scopes in locales.

Notes

https://claude.ai/code/session_0137eGmRq5Pvdwoc568KP9Go


Generated by Claude Code

The consent step offers the requested scopes as a choice: each carries its
resource, what it lets the client do (read, change, delete, offline) and
whether it starts ticked. Reading and staying connected start ticked;
every change and delete takes a deliberate tick.

accept names the granted scopes in fields.scopes. The engine checks them
against the request (a subset, with at least one API scope; granting
nothing is a deny) and the code is issued for them only, in the same write
that stores the code. An accept without fields.scopes grants the
preselected ones.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmRq5Pvdwoc568KP9Go
<zl-consent> offers the step's scopes as native checkboxes, grouped by
resource, with presets (Read only, Everything requested) and staying
connected as a choice of its own. Reading and staying connected start
ticked; every change and delete takes a deliberate tick. Its value is the
granted scopes, which an allow submits as fields.scopes, and allow stays
disabled until an API scope is ticked: granting none is a deny.

Every scope a person's platform token can carry, and its resource, gets a
consent text in en, de and it, and a server test fails a scope without one.
The shipped designs pass the choice, and the mandatory gate gives it to a
template that renders the summary without it. The API mock classifies the
scopes and refuses an allow the engine refuses.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmRq5Pvdwoc568KP9Go
The consent step offers the requested scopes as a choice: reading starts
ticked, changes and deletes take a deliberate tick, staying connected is
its own choice, and granting nothing is a deny. ADR 092, the component
capability map, the design guide's parts and the components README follow;
the pending consent changeset says what the person now chooses.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmRq5Pvdwoc568KP9Go
…claration

The consent step renders what the server sends for whichever API a request
names: each scope's group and access, which an API may declare and which
otherwise follow from the name <group>.<verb>. The wire field resource of a
consent scope is now group, and its name's key consent.group.<group>.

The words for an API's scopes come from the app that asks for consent,
through locales, like every other login text: the login component ships
none. The console brings the Zitadel API's, as a customer's app brings its
own, and the server's tests require them for every scope a person's token
can carry and hold the spec's scope names to the naming rule. ADR 082's
amendment and the pending changeset follow.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmRq5Pvdwoc568KP9Go
Copilot AI balanced review requested due to automatic review settings December 2, 2026 02:15
@vercel

vercel Bot commented Dec 2, 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 2, 2026 4:57am UTC

Request Review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 2, 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-02T02:29:07.750302Z 6946f00 PR opened
ℹ️ 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.

@github-actions

github-actions Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

🦋 Changeset detected

Latest commit: c4a3e08

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

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

The mock bypasses scope validation when fields.scopes is omitted, while the login UI incorrectly blocks requests containing only offline_access, creating inconsistent behavior with the server.

2 open issues
What changed in this PR

Adds selective OAuth consent to Zitadel’s sign-in flow, letting people limit requested permissions before an MCP or other OAuth client receives tokens.

Changes:

  • Validates chosen scopes and stores the narrowed grant with the authorization code.
  • Adds grouped scope checkboxes, presets, an offline-access toggle, and localized console labels.
  • Updates API contracts, generated clients, mocks, tests, and documentation.
File Description
packages/​go/​api/​oas_validators_gen.go Generated consent validation.
packages/​go/​api/​oas_schemas_gen.go Generated consent types and errors.
packages/​go/​api/​oas_json_gen.go Generated consent JSON handling.
packages/​config/​defaults/​branding/​minimal/​login.liquid Adds scope choices to minimal design.
packages/​config/​defaults/​branding/​centered/​login.liquid Adds scope choices to centered design.
packages/​components/​src/​orchestrator/​zitadel-login.ts Submits selections and controls Allow.
packages/​components/​src/​orchestrator/​zitadel-login-auth-request.spec.ts Tests scope selection and submission.
packages/​components/​src/​orchestrator/​templates/​default.liquid Adds default consent controls.
packages/​components/​src/​orchestrator/​mandatory-gates.ts Supplies choices to older templates.
packages/​components/​src/​orchestrator/​mandatory-gates.spec.ts Tests template fallback behavior.
packages/​components/​src/​orchestrator/​locales/​it.ts Italian consent-control labels.
packages/​components/​src/​orchestrator/​locales/​en.ts English consent-control labels.
packages/​components/​src/​orchestrator/​locales/​de.ts German consent-control labels.
packages/​components/​src/​orchestrator/​liquid.ts Registers consent-choice formatting.
packages/​components/​src/​orchestrator/​liquid.spec.ts Tests localized choice formatting.
packages/​components/​src/​orchestrator/​design-templates.spec.ts Tests choices across shipped designs.
packages/​components/​src/​orchestrator/​consent-choices.ts Builds localized choice attributes.
packages/​components/​src/​atoms/​zl-consent.ts Implements checkboxes, presets, and grant value.
packages/​components/​src/​atoms/​zl-consent.spec.ts Tests interactive consent controls.
packages/​components/​src/​atoms/​zl-consent.css Styles grouped scope choices.
packages/​components/​src/​atoms/​index.ts Exports consent choice types.
packages/​components/​src/​atoms/​event-contract.spec.ts Updates consent event expectations.
packages/​components/​README.md Documents selection and localization.
packages/​api-mock/​src/​index.spec.ts Tests invalid consent grants.
packages/​api-mock/​src/​handlers.ts Rejects invalid mock grants.
packages/​api-mock/​src/​fixtures/​login.ts Adds scope metadata to fixtures.
packages/​api-mock/​src/​consent-scope.ts Classifies scopes and validates selections.
docs/​design/​branding/​component-capability-map.md Documents interactive consent capabilities.
docs/​adrs/​092-mcp-server.md Connects MCP authorization to selective consent.
docs/​adrs/​082-oauth-and-oidc-server.md Records scope-selection decisions.
apps/​storybook/​src/​consent.stories.ts Demonstrates selectable consent scopes.
apps/​docs/​content/​docs/​guides/​customize-design.mdx Lists new consent styling parts.
apps/​console/​src/​features/​sign-in/​consent-texts.ts Supplies localized API scope labels.
apps/​console/​src/​features/​sign-in/​components/​sign-in-screen.tsx Passes scope labels into login.
apps/​api/​internal/​storage/​stmttest/​auth_request_test.go Tests persisted scope narrowing.
apps/​api/​internal/​storage/​dialect/​sqlite/​auth_request.go Stores granted scopes with codes.
apps/​api/​internal/​storage/​dialect/​spanner/​auth_request.go Stores granted scopes with codes.
apps/​api/​internal/​storage/​dialect/​postgres/​auth_request.go Stores granted scopes with codes.
apps/​api/​internal/​service/​statement.go Documents scope persistence contract.
apps/​api/​internal/​service/​flow_auth_request.go Passes selections to code issuance.
apps/​api/​internal/​service/​flow_auth_request_test.go Tests grant forwarding.
apps/​api/​internal/​service/​auth_request.go Revalidates grants before code issuance.
apps/​api/​internal/​service/​auth_request_test.go Tests narrowed code issuance.
apps/​api/​internal/​flowengine/​state.go Tracks consented scopes.
apps/​api/​internal/​flowengine/​auth_request.go Builds choices and validates submissions.
apps/​api/​internal/​flowengine/​auth_request_test.go Tests consent defaults and refusals.
apps/​api/​internal/​domain/​flow_errors.go Defines invalid-consent error.
apps/​api/​internal/​domain/​consent_scope.go Defines classification and grant rules.
apps/​api/​internal/​domain/​consent_scope_test.go Tests classification and grant rules.
apps/​api/​internal/​api/​scopes_test.go Checks scope naming and translations.
apps/​api/​internal/​api/​integration_test/​oauth_token_test.go Adapts code issuance calls.
apps/​api/​internal/​api/​integration_test/​oauth_code_test.go Adapts code redemption setup.
apps/​api/​internal/​api/​integration_test/​application_release_test.go Adapts application authorization setup.
apps/​api/​internal/​api/​integration_test/​access_token_test.go Tests narrowed token permissions.
apps/​api/​internal/​api/​generated/​oas_validators_gen.go Generated server consent validation.
apps/​api/​internal/​api/​generated/​oas_schemas_gen.go Generated server consent types.
apps/​api/​internal/​api/​generated/​oas_json_gen.go Generated server JSON handling.
apps/​api/​internal/​api/​flow.go Maps consent metadata and errors.
apps/​api/​api/​openapi/​endpoints/​flows/​submit/​submitFlowStep-error-response.yaml Adds consent error response variant.
apps/​api/​api/​openapi/​endpoints/​flows/​submit/​methods.yaml Documents invalid-grant responses.
apps/​api/​api/​openapi/​endpoints/​flows/​session/​getFlowStep-error-response.yaml Updates flow error catalog.
apps/​api/​api/​openapi/​components/​schemas/​errors/​flow-consent_scopes_invalid.yaml Generated consent error schema.
apps/​api/​api/​openapi/​components/​flows/​flow-submit-request.yaml Documents submitted scope selections.
apps/​api/​api/​openapi/​components/​flows/​flow-step.yaml Defines scope metadata and consent contract.
apps/​api/​api/​openapi/​components/​examples/​errors/​flow-consent_scopes_invalid.yaml Generated consent error example.
apps/​api/​api/​openapi/​bundled/​openapi.json Regenerated API contract bundle.
.changeset/​oauth-sign-in-consent.md Updates customer-facing release notes.

Review effort: Balanced

Comment thread packages/api-mock/src/consent-scope.ts Resolved
fforootd pushed a commit that referenced this pull request Dec 2, 2026
… three tools

A review found the ADR's claim wrong that a client secret a tool returns is
ended by rotating it: only a retry with the request's Idempotency-Key
replaces a secret, and a tool sends no header. The ADR now says what ends
each credential, the operator's reference no longer says such an operation
is never a tool, and the amendment no longer names a guard that only
#3543 adds. createInvitation and createProjectClaim are now
called through their tools against the real API.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U
Review findings on the consent scope choice:

- Allow needs a ticked API scope only when the step offers one: a request
  for offline_access alone, or for nothing, can be allowed again.
- Every copy of the choice a template renders shows one grant, and allow
  follows a choice the template left unnamed.
- A request another flow answered is refused as one
  (flow.auth_request_invalid, auth code not issued), not as a grant outside
  the scopes that flow narrowed it to.
- The API mock refuses an allow without fields.scopes when nothing
  preselected reaches an API, as the engine does, and its conformance
  suite covers flow.consent_scopes_invalid.
- The narrowing test asks for team.write, which createTeam needs, and
  shows the request granted as asked creating the team. New HTTP tests
  submit fields.scopes, redeem the code, and get no refresh token for an
  unticked offline_access; a grant nobody asked for is refused.
- A test holds that scopes named .read reach only operations that read and
  handle no secret.
- <zl-consent> gets its browser spec: the submitted grant, the keyboard on
  checkboxes and presets, form.reset() and a disabled fieldset.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmRq5Pvdwoc568KP9Go
The consent choice starts closed: one line of what is granted ("Read only ·
Stay connected") and a Change button that opens the checkboxes, so Allow and
Deny follow it in the keyboard order however many scopes are asked for.

The login component now puts the server's choices into every consent summary
a template renders, so a template words and lays out the choice but never
decides what is offered or what starts ticked.

When the request asks for an API scope, an accept without `fields.scopes` is
refused with `flow.consent_scopes_invalid`, like an empty one: a screen that
offered no choice grants nothing the person never saw. A request for no API
scope still grants `offline_access`. The API mock refuses the same.

ADR 082's amendment, the components README, the parts table, the capability
map, the changeset and the consent story follow.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmRq5Pvdwoc568KP9Go
main's #3545 serves the flow tests from the shared Flow API mock, whose
submits carry the session token and whose browser specs mount through the
mock fixture. The consent tests here keep their grants and now send both.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmRq5Pvdwoc568KP9Go
While no API scope is ticked, the consent choice says why allow waits
("Tick at least one permission to allow, or deny."). That line and what is
granted are live regions that describe the Change button, so a tick that
changes them is announced. Enter pressed while allow waits opens the choice
at its first scope instead of doing nothing.

A grant the server refuses (`flow.consent_scopes_invalid`) keeps the consent
step, with a translated reason as its error, instead of replacing the page
with the server's message.

The engine honours a named choice when the client became first-party while
the step was open; only an accept that names nothing keeps the request's
scopes. The API mock refuses an action the consent step lacks with
`flow.invalid_action`, as the engine does, and the browser spec again asserts
that the Enter leaned on after the password sends no accept.

The spec describes scope groups and access by name only; an API's own
declarations land with `apis`, as ADR 082's amendment now says, along with
the empty grant's token response.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmRq5Pvdwoc568KP9Go
Closed, the consent choice now names the groups its grant reaches, a line
per access under what is granted: "View: Users, Audit log", "Edit: Teams",
"Delete: Users". Every group is listed, however many, so the person sees
which kinds of data they allow without opening the choice, and the lines
always match what Allow sends. They are a live region and describe the
Change button, so a screen reader hears them before Allow. A scope outside
any group is named by its own line.

Reads, sensitive ones included, stay ticked to start, now that the closed
choice names them. ADR 082's amendment, the components README, the parts
table, the capability map and the changeset say so.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmRq5Pvdwoc568KP9Go
@fforootd
fforootd added this pull request to the merge queue Dec 2, 2026
Merged via the queue into main with commit 5308077 Dec 2, 2026
17 of 18 checks passed
@fforootd
fforootd deleted the feat/consent-scope-choice branch December 2, 2026 05:36
@github-project-automation github-project-automation Bot moved this from Inbox to Done in Engineering Kanban Dec 2, 2026
fforootd pushed a commit that referenced this pull request Dec 2, 2026
…cope

Picks up what landed on main in between: #3541, #3539, #3543 and #3542.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U
fforootd pushed a commit that referenced this pull request Dec 2, 2026
Picks up what landed on main in between: #3538, #3541, #3539 and #3543.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U
fforootd pushed a commit that referenced this pull request Dec 2, 2026
The user decided that the CLI, the API and MCP matter more than the Console
for creating a PAT. So a person's OAuth token may create one with a scope the
consent step never preselects, holding no scope that token lacks; a PAT still
never creates one, and the creating client is recorded. Scope choice on
consent is on main (#3543), which the first draft missed.

A PAT is now an opaque 256-bit secret stored as its SHA-256, with its record
id and a checksum in the token, so it depends on no key and a copy of the
table holds nothing usable. The 90-day limit is to become a policy later.

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

This branch was successfully deployed

1 active deployment
Preview — c4a3e08b Deployed Dec 2, 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