Repository navigation
feat(api): remember a person's OAuth consent, and let them list and revoke it - #3574
Conversation
Amend ADR 082 (Proposed): a consent is remembered per person, client and API. A client whose identity is assured (a secret, or an https answer) skips the step for what it was granted; a client that returns to a loopback address or a private-use scheme is asked each time with the last choice ticked. Scopes of operations that return a credential are never remembered. A person lists and revokes their consents, and a revoke ends the client's refresh grants. ADR 092 points to it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmUEzNb3SNs7Rj5USYf
…rompt A consents table in the three dialects, one row per person, client and API (ADR 082, amendment of 2026-12-02): the scopes the person granted and the ones they declined, a digest of the client, the session and time of the last answer, and an expiry. Revoking one deletes it and the client's refresh grants for the person in one transaction. The authorization request keeps its prompt for the flow to read. stmttest covers the statements on every dialect, and ADR 047 registers the consent prefix. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmUEzNb3SNs7Rj5USYf
…o the policy work A remembered consent holds the person's answer for every scope offered, yes or no, so a client that asks for everything skips the step once the person answered, and is issued the scopes answered yes. A scope that is never remembered no longer forces the step: a skip does not issue it. A declined scope is asked for again with prompt=consent after the API's auth.scope_insufficient refusal. How long a consent lasts, and whether use renews it, is left open for the policy work; the me operations become two tools once #3559 lands. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmUEzNb3SNs7Rj5USYf
… with it The consent step stores the person's answer, granted or declined per scope offered (ADR 082, amendment of 2026-12-02). On the next request a client whose identity is assured (a secret, or an https answer off the person's device) skips the step when every scope asked was answered, and its code carries the scopes answered yes. A client that holds no secret and returns to a loopback address or a private-use scheme sees the step each time, ticked as the person last answered. A new scope, a changed client, prompt=consent or an expired consent shows the step. Scopes of operations that return a credential are never remembered. The authorization endpoint keeps the request's prompt for the flow. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmUEzNb3SNs7Rj5USYf
listMyConsents (GET /users/me/consents) lists what the signed-in person
consented to OAuth clients doing, the last answered first, with the
scopes granted and declined and when the consent expires.
revokeMyConsent (DELETE /users/me/consents/{consent_id}) deletes one
and ends every refresh token its client holds for the person, so the
client is asked again at its next sign-in (ADR 082, amendment of
2026-12-02). Both take the session cookie, like the other me
operations, so the MCP endpoint offers neither as a tool.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmUEzNb3SNs7Rj5USYf
The Enable OAuth guide says which clients are asked once and which every time, and how a person lists and revokes a consent. ADR 082's amendment says the me operations take the session cookie until #3559 lets them take a person's token. The changeset covers the three code pieces. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmUEzNb3SNs7Rj5USYf
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmUEzNb3SNs7Rj5USYf
main renumbered the migrations (#3551) and marks a person's own operations x-zitadel-self (#3559, #3560). listMyConsents takes the mark and a person's token with user.read; revokeMyConsent takes the mark and stays with the session cookie, as revokeMySession does. Generated files regenerated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmUEzNb3SNs7Rj5USYf
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmUEzNb3SNs7Rj5USYf
Amend ADR 082 (Proposed): a consent is remembered per person, client and API. A client whose identity is assured (a secret, or an https answer) skips the step for what it was granted; a client that returns to a loopback address or a private-use scheme is asked each time with the last choice ticked. Scopes of operations that return a credential are never remembered. A person lists and revokes their consents, and a revoke ends the client's refresh grants. ADR 092 points to it. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmUEzNb3SNs7Rj5USYf
…o the policy work A remembered consent holds the person's answer for every scope offered, yes or no, so a client that asks for everything skips the step once the person answered, and is issued the scopes answered yes. A scope that is never remembered no longer forces the step: a skip does not issue it. A declined scope is asked for again with prompt=consent after the API's auth.scope_insufficient refusal. How long a consent lasts, and whether use renews it, is left open for the policy work; the me operations become two tools once #3559 lands. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmUEzNb3SNs7Rj5USYf
Brings in main with personal access tokens (#3563), so PR 2 can stack on the ADR's branch. A scope granted only on the consent step (personal_access_token.create, domain.ConsentRequired) is never remembered and always shows the step, to a first-party client too; the ADR says so. Generated files regenerated; sets_test lists both the token tools and listMyConsents. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmUEzNb3SNs7Rj5USYf
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
The red Vercel (cloud) check is not caused by the code: Earlier pushes to this branch migrated that database when the consents migration was Fix: drop that one preview database, as Generated by Claude Code |
🦋 Changeset detectedLatest commit: 7c57e3c 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 |
…odes on revoke From review of #3574: - A consent given to a client before its document changed is no consent: its answers neither tick the step nor carry over into what the person answers the changed client. - Revoking a consent also deletes the client's authorization requests for the person that hold an unredeemed code, in the same transaction on all three dialects, so a code issued before the revoke buys no token after. - Only a redirect off the person's device assures a public client: a trailing dot, localhost subdomains, the unspecified address and numeric IPv4 forms (127.1, 2130706433, 0x7f.1) count as the device. The check is the consent rule's own; IsLoopbackOrigin is unchanged for its other callers. - Tests for each, and for the first-party answer that stores nothing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmUEzNb3SNs7Rj5USYf
…on the device, end consents on a password reset The user's decisions on #3574's review (D1-D3): - A request that names a scope a consent never remembers (one that returns a credential, or is granted only on the step) shows the step, ticked as answered: a skip never leaves out a scope the request named. An ask-everything client therefore sees the step at every sign-in; the ADR says so and leaves a scope of their own for those operations open, and no longer leans on prompt=consent as MCP's step-up. - A client whose identity is not assured starts with no delete scope ticked, whatever the person answered before. - setUserPassword, the reset by which a person gets back a lost account today, revokes every consent of theirs in the same transaction, with each client's refresh grants and unredeemed codes. The ADR records that a future self-service recovery must do the same, and a Console revoke surface as a condition before the skip is on for the hosted cloud. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmUEzNb3SNs7Rj5USYf
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmUEzNb3SNs7Rj5USYf
listMyConsents and revokeMyConsent are a person's own operations, on their own credential (revoking on their session only); the CLI's api-coverage test listed them as neither called nor explained. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmUEzNb3SNs7Rj5USYf
The amendment as the code's pull request now has it: a consent given to a client whose registration has changed counts as none; a revoke also ends the client's unredeemed codes; a request that names a scope that is never remembered always shows the step, so a client that asks for every listed scope is asked each time; delete scopes start unticked on the person's device; a password set ends the person's consents; and what a password set ends, like a consent's lifetime, is left to the policy work. A person reaching revoke from the Console is a condition before the skip is switched on for the hosted cloud. The text was written in the session https://claude.ai/code/session_0137eGmUEzNb3SNs7Rj5USYf and is taken from its branch unchanged. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U
…onsent Brings in main at eaced99 (#3552, #3562, #3564). The CLI's api-coverage test keeps only the two consent operations as not called: the personal access token commands now call theirs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmUEzNb3SNs7Rj5USYf
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. |
The ADR text it carries is on this branch through claude/remembered-consent-adr. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmUEzNb3SNs7Rj5USYf
…ndex Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmUEzNb3SNs7Rj5USYf
Brings in #3570 (a password set ends personal access tokens). The consent Spanner migrations sit behind its 000069 as 000070 and 000071. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmUEzNb3SNs7Rj5USYf
There was a problem hiding this comment.
🟡 Changes recommended
Critical consent and revocation races can leave refresh grants active after revocation or restore declined scopes, and hosted-cloud consent skipping lacks the required Console revocation path.
6 open issues
Gate hosted-cloud consent skipping until Console revocation exists · New Pin the displayed client digest in consent flow state · New Prevent concurrent consent answers from restoring declined scopes · New Serialize consent handling and code issuance with revocation · New Ensure revocation sees grants created during code redemption · New Document insufficient-scope response with shared error schema · New
What changed in this PR
Implements remembered OAuth consent from ADR 082 across the server, storage, and API clients.
Changes:
- Stores scope choices for 90 days, with client-dependent skipping and preselection.
- Adds consent listing, session-only revocation, and password-set cleanup.
- Adds three-dialect migrations, regression tests, generated API support, and documentation.
| File | Description |
|---|---|
packages/go/api/oas_validators_gen.go |
Generates consent response validation. |
packages/go/api/oas_security_gen.go |
Adds consent operation authentication metadata. |
packages/go/api/oas_response_decoders_gen.go |
Decodes consent operation responses. |
packages/go/api/oas_parameters_gen.go |
Adds consent request parameters. |
packages/go/api/oas_operations_gen.go |
Registers consent operations. |
packages/go/api/oas_interfaces_gen.go |
Adds consent response interfaces. |
docs/adrs/047-dialect-id-generation.md |
Registers the consent ID prefix. |
apps/docs/content/docs/guides/enable-oauth.mdx |
Explains remembered consent and revocation. |
apps/cli/tests/unit/cli/commands/api-coverage.test.ts |
Documents CLI consent-operation exclusions. |
apps/api/internal/storage/stmttest/schema_nullability_test.go |
Checks new column nullability. |
apps/api/internal/storage/stmttest/consent_test.go |
Tests consent persistence and revocation. |
apps/api/internal/storage/stmttest/auth_request_test.go |
Tests prompt persistence. |
apps/api/internal/storage/dialect/sqlite/statement.go |
Wires SQLite consent statements. |
apps/api/internal/storage/dialect/sqlite/migration/sql/000053_consents.sql |
Adds SQLite consent storage and indexes. |
apps/api/internal/storage/dialect/sqlite/migration/sql/000052_auth_request_prompt.sql |
Adds SQLite prompt storage. |
apps/api/internal/storage/dialect/sqlite/consent.go |
Implements SQLite consent operations. |
apps/api/internal/storage/dialect/sqlite/auth_request.go |
Persists authorization prompts in SQLite. |
apps/api/internal/storage/dialect/spanner/statement.go |
Wires Spanner consent statements. |
apps/api/internal/storage/dialect/spanner/migration/sql/000071_consents.sql |
Adds Spanner consent storage and indexes. |
apps/api/internal/storage/dialect/spanner/migration/sql/000070_auth_request_prompt.sql |
Adds Spanner prompt storage. |
apps/api/internal/storage/dialect/spanner/consent.go |
Implements Spanner consent operations. |
apps/api/internal/storage/dialect/spanner/auth_request.go |
Persists authorization prompts in Spanner. |
apps/api/internal/storage/dialect/postgres/statement.go |
Wires PostgreSQL consent statements. |
apps/api/internal/storage/dialect/postgres/migration/sql/000066_consents.sql |
Adds PostgreSQL consent storage and indexes. |
apps/api/internal/storage/dialect/postgres/migration/sql/000065_auth_request_prompt.sql |
Adds PostgreSQL prompt storage. |
apps/api/internal/storage/dialect/postgres/consent.go |
Implements PostgreSQL consent operations. |
apps/api/internal/storage/dialect/postgres/auth_request.go |
Persists authorization prompts in PostgreSQL. |
apps/api/internal/service/user.go |
Ends consents when setting passwords. |
apps/api/internal/service/statement.go |
Defines consent storage contracts. |
apps/api/internal/service/mocks/service.mock.go |
Generates consent statement mocks. |
apps/api/internal/service/flow_engine.go |
Injects never-remembered scope lookup. |
apps/api/internal/service/flow_auth_request.go |
Implements consent remembering and skip decisions. |
apps/api/internal/service/flow_auth_request_test.go |
Extends consent service test fixtures. |
apps/api/internal/service/flow_auth_request_remembered_test.go |
Tests remembered-consent rules. |
apps/api/internal/service/consent.go |
Implements listing, revocation, and password cleanup. |
apps/api/internal/service/consent_test.go |
Tests pagination and missing consents. |
apps/api/internal/service/client_directory.go |
Computes client identity digests. |
apps/api/internal/service/client_directory_test.go |
Tests client digest changes. |
apps/api/internal/oauth/authorize.go |
Stores recognized prompt values. |
apps/api/internal/oauth/authorize_test.go |
Tests prompt filtering and storage. |
apps/api/internal/mcp/sets_test.go |
Includes consent listing in tool expectations. |
apps/api/internal/flowengine/auth_request.go |
Supports remembered grants and preselection. |
apps/api/internal/flowengine/auth_request_test.go |
Tests skipping and selected scopes. |
apps/api/internal/domain/consent.go |
Defines consent lifetime and scope merging. |
apps/api/internal/domain/consent_test.go |
Tests consent domain rules. |
apps/api/internal/domain/auth_request.go |
Adds authorization prompt state. |
apps/api/internal/api/security.go |
Registers consent authentication rules. |
apps/api/internal/api/security_access_token_test.go |
Checks consent listing scope requirements. |
apps/api/internal/api/scopes.go |
Finds credential-returning operation scopes. |
apps/api/internal/api/scopes_test.go |
Tests never-remembered scope discovery. |
apps/api/internal/api/integration_test/oauth_sign_in_test.go |
Explicitly requests consent in existing tests. |
apps/api/internal/api/integration_test/oauth_remembered_consent_test.go |
Tests remembering, revocation, and password cleanup. |
apps/api/internal/api/integration_test/oauth_refresh_test.go |
Explicitly requests consent for refresh tests. |
apps/api/internal/api/handler.go |
Initializes the consent service. |
apps/api/internal/api/generated/oas_validators_gen.go |
Generates server consent validation. |
apps/api/internal/api/generated/oas_unimplemented_gen.go |
Generates consent handler stubs. |
apps/api/internal/api/generated/oas_server_gen.go |
Extends the server handler contract. |
apps/api/internal/api/generated/oas_security_gen.go |
Generates consent security metadata. |
apps/api/internal/api/generated/oas_response_encoders_gen.go |
Encodes consent operation responses. |
apps/api/internal/api/generated/oas_parameters_gen.go |
Decodes consent request parameters. |
apps/api/internal/api/generated/oas_operations_gen.go |
Registers server consent operations. |
apps/api/internal/api/generated/oas_interfaces_gen.go |
Adds server consent response interfaces. |
apps/api/internal/api/error_handler.go |
Routes consent domain errors. |
apps/api/internal/api/consent.go |
Implements consent HTTP handlers. |
apps/api/internal/api/authz_ungated_contract_internal_test.go |
Registers consent self-service operations. |
apps/api/cmd/server/server.go |
Wires platform never-remembered scopes. |
apps/api/api/openapi/openapi-spec.yaml |
Registers consent endpoint paths. |
apps/api/api/openapi/endpoints/users/me/consents/methods.yaml |
Defines the consent listing contract. |
apps/api/api/openapi/endpoints/users/me/consents/listMyConsents-error-response.yaml |
Generates listing error responses. |
apps/api/api/openapi/endpoints/users/me/consents/list-my-consents-response.yaml |
Defines paginated consent responses. |
apps/api/api/openapi/endpoints/users/me/consents/consent.yaml |
Defines the public consent schema. |
apps/api/api/openapi/endpoints/users/me/consents/by_id/revokeMyConsent-error-response.yaml |
Generates revocation error responses. |
apps/api/api/openapi/endpoints/users/me/consents/by_id/methods.yaml |
Defines session-only consent revocation. |
apps/api/api/openapi/components/schemas/errors/consent-not_found.yaml |
Generates the missing-consent error schema. |
apps/api/api/openapi/components/schemas/consent-id.yaml |
Defines consent ID validation. |
apps/api/api/openapi/components/parameters/consent-id.yaml |
Defines the consent path parameter. |
apps/api/api/openapi/components/examples/errors/consent-not_found.yaml |
Generates a missing-consent error example. |
.changeset/oauth-remembered-consent.md |
Adds customer-facing release notes. |
Review effort: Balanced
| if assured && !promptsConsent(request.Prompt) && !slices.ContainsFunc(request.Scopes, never) { | ||
| if granted, ok := remembered.Answered(request.Scopes, never); ok { | ||
| consent.Remembered, consent.Granted = true, granted | ||
| return consent, nil |
| UserID: in.UserID, | ||
| ClientID: request.ClientID, | ||
| Resource: request.Resource, | ||
| ClientDigest: client.Digest, |
| consent.Scopes, consent.Declined = domain.RememberConsent(previous, request.Scopes, in.Scopes, never) | ||
| if err := a.db.Statements().PutConsent(ctx, consent); err != nil { |
| if in.Answered && request.CodeHash == "" { | ||
| if err := a.remember(ctx, in, request); err != nil { | ||
| return "", err | ||
| } |
| `DELETE FROM zitadel_nextgen.refresh_grants AS g USING revoked AS r` + | ||
| ` WHERE g.project_id = r.project_id AND g.user_id = r.user_id AND g.client_id = r.client_id` + | ||
| `), unredeemed AS (` + | ||
| `DELETE FROM zitadel_nextgen.auth_requests AS a USING revoked AS r` + | ||
| ` WHERE a.project_id = r.project_id AND a.user_id = r.user_id AND a.client_id = r.client_id AND a.code_hash IS NOT NULL` + |
| description: The session belongs to a different project than `project_id`. | ||
| content: | ||
| application/json: | ||
| schema: | ||
| $ref: ../../../../components/schemas/errors/sess-project_mismatch.yaml |
Resolve the overlap with remembered consent (#3574): keep main's prompt column, stored space-separated, and move this branch's max_age and login_hint migration after main's. A first-party client is asked for consent on prompt=consent or a scope that always needs it, one rule decides whether a client's identity is assured, and a live session answers with a consent the person already gave. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>


Context
Summary
A person who connected an agent was asked the same consent question every time it signed them in. The OAuth server now remembers the answer.
resource), with the person's answer per offered scope (granted or declined), a digest of the client, the session, and a 90-day expiry that use does not renew.httpsredirect that does not lead back to the person's device) skips the step when every requested scope was answered and at least one API scope granted. The code carries the granted scopes only.localhost, a private-use scheme) sees the step every time, ticked as last answered, except that scopes with delete access start unticked. The server setsselected; the login component is unchanged.prompt=consent, or an expired consent. A consent given to a client whose registration has since changed counts as no consent: nothing is pre-ticked or carried over from it.x-zitadel-returns-secret, andpersonal_access_token.create. A skip never leaves out a scope the request named, and never issues one of these. So a client that asks for every scope the metadata lists, as MCP clients do, sees the step at every sign-in, ticked as answered, until credential-returning operations have a scope of their own.listMyConsentstakes the session cookie or a person's token withuser.read, so it is one more MCP tool (92 on a plain URL).revokeMyConsentis session-only, likerevokeMySession, so one client's token cannot revoke another client's consent. Revoking ends all of that client's refresh grants and unredeemed codes for the person.setUserPasswordends the person's consents, in the same transaction as the password write, as a revoke of each would: it is the only way a lost account is recovered today.prompt=consent, since they exercise the step itself.000065/000066, Spanner000070/000071, SQLite000052/000053.Validation
Run by the writing session on the tree of head
7c57e3c:go test ./...inapps/api(the threeTestBuildHTTPMux*incmd/serverfail there and on main: the console is not built in that container).go test -tags sqlite_integration ./internal/api/integration_test/ ./internal/storage/stmttest/, and the same two packages with-tags postgres_integrationagainst a local PostgreSQL 16.go vetwith the spanner tag. The Spanner lane was not run (no emulator).node scripts/go-generate.mjs --check,check-openapi-rules,lint-openapi(pre-existing warnings only).Release notes / changeset
.changeset/oauth-remembered-consent.md(@zitadel/server,@zitadel/api, minor): the OAuth server remembers consent for 90 days; web clients are asked once, clients on the person's device each time with the last answer ticked; a person lists and revokes their consents.Notes
3a2803745. The reviewer found no path where a skip issues a scope the person did not grant to that client, and no cross-user, cross-project or cross-API use of a consent. Its four findings are fixed, each with a test that fails without the fix: a changed client inherited the old client's answers; a code issued just before a revoke still bought a refresh token; two rules had no test; odd spellings of a loopback host counted as assured. Three design points it raised were decided by the owner and are built: the never-remembered scopes always show the step, delete scopes start unticked on the device, and a password reset ends consents.delegation_id; keying by API rather than by the identifier the request named (the platform API has two).https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U
Generated by Claude Code