Repository navigation
feat(api): sign in to an OAuth client as its authorization request asks - #3568
Conversation
A browser sends no SameSite=Lax cookie with another site's POST, so the binding cookie limit could not count or expire the cookies it held. The authorization endpoint now answers such a POST, or one with no Sec-Fetch-Site, with a 303 to the same request as a GET, which sends them. A POST from the issuer's own site is unchanged. An authorization request now stays open 15 minutes from the redirect, however long its flow takes. The flow API description, the bundled OpenAPI spec, the generated Go code and ADR 081 (amended 2026-12-02) say so. Adds a server patch changeset. The cross-site test case that carried TODO(#2795) is replaced by same-origin and same-site cases, and a test covers the redirect.
Each flow now has its own cookie, `_zflow_{flow_id}`, in place of one
shared `_zflow`, so two sign-ins in one browser no longer end each
other. A browser keeps at most three flow cookies: starting a flow
deletes the oldest ones the request carried beyond that. A response
whose flow id changes deletes the cookie under the old id.
The step and submit operations name the cookie with a new
`x-zitadel-cookie` extension, documented in the OpenAPI AGENTS.md. The
flow-cookie parameter is removed. A submit without the cookie answers
401 `flow.cookie_invalid`; a GET of another flow's id answers 404
`flow.not_found`.
The bundled spec, the generated Go code and the flow descriptions
follow. The server mounts `api.WithFlowCookies`, and the integration
helper mounts it too.
The flow now reads the request's prompt and login_hint. A login_hint pre-fills the identifier field but is no longer submitted for the user, so a crafted link starts no identifier lookup. prompt=create starts the flow at the project's registration, and prompt=consent adds the consent step for the project's own client too. The prompt is stored with the auth request in migrations 000063 for Postgres, 000067 for Spanner and 000050 for SQLite. The flow service admits the request through AdmitAuthRequest. The OpenAPI descriptions, the bundled spec, the generated Go code, ADR 081 and the flow engine design note follow. Adds a changeset.
When the browser's session cookie holds an active session of the project, signed in to an active user within the request's max_age, and the client needs no consent, an authorization request ends at once in a redirect that carries the code. No handoff_token is issued, since the browser already holds the session. prompt=login and prompt=select_account still ask for a sign-in. prompt=none answers login_required, or consent_required when the client needs consent. The createFlow response carries that terminal step with complete: redirect and sets no flow cookie. The create-flow request description, the createFlow error responses and the flow endpoint description say so. The createFlow error responses also list app.client_not_found, authreq.code_not_issued, clientdoc.invalid, clientdoc.not_admitted, clientdoc.unavailable, dep.not_found, flow.consent_scopes_invalid and sess.not_found. The bundled spec and the generated Go code follow. The integration helper mounts api.WithBrowserSessionCookie. Adds a changeset.
A flow started with auth_request_id now names the OAuth client whose authorization request it answers. Every response carries it as `client`: the client's id, application, name, redirect host, metadata document host and first_party flag. Other flows carry no `client`. The flow is scoped to the request's application instead of the app_id the page hints, and a client of no application hints none. AdmitAuthRequest returns the admitted request with its client, and the flow state keeps that client from the start. NewFlowService takes the client directory to read it. The OpenAPI spec gains the flow-client schema and the client property, and the app_id description changes. The bundled spec and generated Go code follow. ADR 081, the flow engine design note and a changeset say so.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🦋 Changeset detectedLatest commit: a3d4ef6 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 |
There was a problem hiding this comment.
🟡 Changes recommended
Critical flow defects let existing sessions bypass explicitly requested reauthentication and skip account registration, with additional registration-lookup and benchmark-cookie issues unresolved.
4 open issues
What changed in this PR
Implements the server-side OAuth sign-in behavior for customer-hosted login, advancing #2795 and #1425. Authorization requests now shape flows, eligible sessions can answer immediately, and responses identify the requesting client.
Changes:
- Supports request prompts, login hints, session freshness, and silent authorization responses.
- Introduces per-flow cookies and cross-site authorization POST redirects.
- Updates API contracts, clients, tests, documentation, and release notes.
| File | Description |
|---|---|
| tools/bench/k6module/doer.go | Sends journey flow cookies. |
| tools/bench/harness/ops.go | Carries dynamically named flow cookies. |
| tools/bench/harness/ops_test.go | Updates cookie fixtures. |
| tools/bench/harness/fixtures.go | Attaches flow cookies to requests. |
| packages/testing/tests/unit/session.test.ts | Tests per-flow cookie forwarding. |
| packages/testing/src/session.ts | Tracks per-flow cookies. |
| packages/testing/AGENTS.md | Updates cookie guidance. |
| packages/sdk-core/src/__tests__/middleware.test.ts | Updates proxy cookie fixtures. |
| packages/go/api/oas_parameters_gen.go | Removes fixed cookie parameters. |
| packages/components/src/orchestrator/zitadel-login.ts | Adjusts expired-flow recovery. |
| packages/components/src/orchestrator/zitadel-login-sso.spec.ts | Updates recovery expectations. |
| packages/components/src/orchestrator/api-client.ts | Updates cookie comments. |
| packages/components/README.md | Documents per-flow cookies. |
| packages/api/scripts/operations.ts | Exposes operation cookie metadata. |
| docs/design/flowengine/flow-engine.md | Documents request-driven flows. |
| docs/adrs/README.md | Summarizes ADR amendments. |
| docs/adrs/081-customer-hosted-login-and-oidc-provider.md | Records authorization behavior decisions. |
| docs/adrs/073-session-cookie-per-project.md | Records per-flow cookie isolation. |
| apps/docs/content/docs/reference/api/flows/index.mdx | Documents cookie lifecycle. |
| apps/cli/tests/unit/lib/backend/services/operation.test.ts | Updates cookie restriction assertion. |
| apps/cli/src/lib/backend/services/operation.ts | Uses operation cookie metadata. |
| apps/api/internal/storage/stmttest/auth_request_test.go | Tests stored authorization preferences. |
| apps/api/internal/storage/dialect/sqlite/migration/sql/000050_auth_request_prompt.sql | Adds authorization preference columns. |
| apps/api/internal/storage/dialect/sqlite/auth_request.go | Persists authorization preferences. |
| apps/api/internal/storage/dialect/spanner/migration/sql/000067_auth_request_prompt.sql | Adds authorization preference columns. |
| apps/api/internal/storage/dialect/spanner/auth_request.go | Persists authorization preferences. |
| apps/api/internal/storage/dialect/postgres/migration/sql/000063_auth_request_prompt.sql | Adds authorization preference columns. |
| apps/api/internal/storage/dialect/postgres/auth_request.go | Persists authorization preferences. |
| apps/api/internal/service/metrics_test.go | Updates service construction. |
| apps/api/internal/service/flow.go | Admits requests and checks session eligibility. |
| apps/api/internal/service/flow_auth_request.go | Handles consent and silent refusals. |
| apps/api/internal/service/flow_auth_request_test.go | Tests consent and refusal behavior. |
| apps/api/internal/service/client_directory.go | Supplies requesting application IDs. |
| apps/api/internal/oauth/server.go | Wires cross-site POST middleware. |
| apps/api/internal/oauth/client.go | Removes obsolete first-party state. |
| apps/api/internal/oauth/authorize.go | Stores preferences and redirects cross-site POSTs. |
| apps/api/internal/flowengine/state.go | Stores client metadata and login hints. |
| apps/api/internal/flowengine/state_machine.go | Enables immediate authorization responses. |
| apps/api/internal/flowengine/render_test.go | Tests identifier prefilling. |
| apps/api/internal/flowengine/mock/flowengine.mock.go | Adds refusal service mock. |
| apps/api/internal/flowengine/fields.go | Prefills identifiers from hints. |
| apps/api/internal/flowengine/auth_request.go | Answers requests without sign-in. |
| apps/api/internal/flowengine/auth_request_test.go | Tests immediate responses and client retention. |
| apps/api/internal/domain/auth_request.go | Defines request preferences and lifetime. |
| apps/api/internal/api/legacy_flow_path_test.go | Removes fixed-cookie setup. |
| apps/api/internal/api/integration_test/user_migration_test.go | Migrates flow cookie transport. |
| apps/api/internal/api/integration_test/user_create_policy_test.go | Migrates flow cookie transport. |
| apps/api/internal/api/integration_test/sso_submit_flow_test.go | Uses per-flow cookie names. |
| apps/api/internal/api/integration_test/sso_resolution_flow_test.go | Migrates flow cookie transport. |
| apps/api/internal/api/integration_test/sso_providers_flow_test.go | Migrates flow cookie transport. |
| apps/api/internal/api/integration_test/sso_conflict_flow_test.go | Migrates flow cookie transport. |
| apps/api/internal/api/integration_test/sso_callback_flow_test.go | Uses per-flow cookie names. |
| apps/api/internal/api/integration_test/signup_protection_test.go | Migrates signup cookie transport. |
| apps/api/internal/api/integration_test/sign_up_events_test.go | Migrates flow cookie transport. |
| apps/api/internal/api/integration_test/registration_flow_test.go | Migrates registration cookie transport. |
| apps/api/internal/api/integration_test/project_test.go | Extends the flow service stub. |
| apps/api/internal/api/integration_test/policy_test.go | Migrates flow cookie transport. |
| apps/api/internal/api/integration_test/password_flow_test.go | Migrates password-flow cookie transport. |
| apps/api/internal/api/integration_test/passkey_upsell_flow_test.go | Migrates passkey-flow cookie transport. |
| apps/api/internal/api/integration_test/passkey_signup_protection_test.go | Migrates signup cookie transport. |
| apps/api/internal/api/integration_test/passkey_flow_test.go | Updates cookie transport and extraction. |
| apps/api/internal/api/integration_test/oauth_refresh_test.go | Preserves flow cookie names. |
| apps/api/internal/api/integration_test/oauth_client_document_test.go | Preserves flow cookie names. |
| apps/api/internal/api/integration_test/identifier_scope_flow_test.go | Migrates flow cookie transport. |
| apps/api/internal/api/integration_test/helpers/server.go | Wires browser-cookie middleware. |
| apps/api/internal/api/integration_test/helpers/flow.go | Supplies client directory dependency. |
| apps/api/internal/api/integration_test/helpers/client.go | Adds contextual flow-cookie transport. |
| apps/api/internal/api/integration_test/flow_submit_refusal_test.go | Preserves flow cookie names. |
| apps/api/internal/api/integration_test/flow_origin_test.go | Updates cookie helpers and middleware. |
| apps/api/internal/api/integration_test/flow_legacy_path_test.go | Tests legacy routes with named cookies. |
| apps/api/internal/api/integration_test/event_user_filter_test.go | Migrates flow cookie transport. |
| apps/api/internal/api/integration_test/combined_flow_test.go | Migrates combined-flow cookie transport. |
| apps/api/internal/api/integration_test/claim_test.go | Migrates claim-flow cookie transport. |
| apps/api/internal/api/generated/oas_unimplemented_gen.go | Regenerates operation documentation. |
| apps/api/internal/api/generated/oas_server_gen.go | Regenerates handler contract documentation. |
| apps/api/internal/api/generated/oas_parameters_gen.go | Removes fixed-cookie decoding. |
| apps/api/internal/api/generated/oas_handlers_gen.go | Updates generated parameter handling. |
| apps/api/internal/api/flow.go | Applies request preferences and client metadata. |
| apps/api/internal/api/flow_cookie.go | Implements per-flow cookie lifecycle. |
| apps/api/internal/api/error_handler_test.go | Removes obsolete cookie-decoding test. |
| apps/api/internal/api/cookie_secure_internal_test.go | Updates cookie helper calls. |
| apps/api/cmd/server/server.go | Wires services and cookie middleware. |
| apps/api/api/openapi/endpoints/flows/submit/methods.yaml | Declares dynamic submit cookies. |
| apps/api/api/openapi/endpoints/flows/session/methods.yaml | Declares dynamic read cookies. |
| apps/api/api/openapi/endpoints/flows/methods.yaml | Documents immediate completion and cookies. |
| apps/api/api/openapi/endpoints/flows/createFlow-error-response.yaml | Expands creation error contract. |
| apps/api/api/openapi/components/parameters/flow-id.yaml | Documents ID-based cookie naming. |
| apps/api/api/openapi/components/parameters/flow-cookie.yaml | Removes fixed cookie parameter. |
| apps/api/api/openapi/components/headers/set-cookie-flow.yaml | Documents cookie rotation and eviction. |
| apps/api/api/openapi/components/flows/flow-submit-request.yaml | Updates cookie documentation. |
| apps/api/api/openapi/components/flows/flow-response.yaml | Adds requesting-client metadata. |
| apps/api/api/openapi/components/flows/flow-hint.yaml | Documents hint precedence. |
| apps/api/api/openapi/components/flows/flow-client.yaml | Defines requesting-client schema. |
| apps/api/api/openapi/components/flows/create-flow-request.yaml | Documents authorization-driven behavior. |
| apps/api/api/openapi/AGENTS.md | Defines dynamic-cookie extension guidance. |
| .changeset/flow-requesting-client.md | Announces client metadata support. |
| .changeset/flow-cookie-per-flow.md | Announces cookie contract migration. |
| .changeset/authorize-cross-site-post.md | Announces cross-site POST handling. |
| .changeset/auth-request-prompt-login-hint.md | Announces prompt and hint support. |
| .changeset/auth-request-live-session.md | Announces live-session authorization. |
Review effort: Balanced
IAM-marco
left a comment
There was a problem hiding this comment.
Thanks for this, the five parts are easy to follow commit by commit. I am requesting changes for the three comments about who gets a code without a page. The rest is smaller.
Code review
Six comments are inline.
Who gets a code without a page (please look at these first)
- Bug,
service/flow.go: a live session answers the request whateverpurposethe page asked for, so aregisterorreauthpage is skipped. - Bug,
flowengine/auth_request.go: a first-party client without a secret gets a code with no action by the person, also on a loopback redirect, where any local program can receive it. - History note,
service/flow_auth_request.go: aprompt=nonerefusal leaves the request open, so the same request can get an error first and a code later.
Contract and structure
- Comment guidance,
create-flow-request.yaml: "Such a flow" now describes the flow that ends at once, and promises acodeand ahandoff_tokenit does not have. - Guideline note,
api/flow.go: the handler picks theprompt=createdefinition and builds theprompt=noneterminal step, whicharchitecture.mdgives to the service and the engine. - Guideline note,
flow-response.yaml: the API mock sends noclienton a flow started withauth_request_id.
Tally: 6 findings: 2 bugs, 1 history note, 1 comment guidance, 2 guideline notes.
Worst issue: the code for a first-party client without a secret on a loopback redirect.
Ponytail
A review of the branch at 5e6ebd9a6 for three things: code that could be smaller, risky code without a test, and cost under load. It read the callers and the tests, not only the diff. Load assumed: many users and several server processes.
Nine comments are inline. None of them blocks the PR on this axis.
Worth fixing (4)
apps/api/cmd/server/server.go: no test checks that the server's own chain has the two new cookie middlewares.oauth_sign_in_test.go: eight integration subtests repeat a rule that a lower test already proves.service/flow.go:sessionMayAnswerhas a second copy of the "active user" query.domain/auth_request.go:prompt=nonenow stores a row per silent check, and nothing deletes expired rows yet (a note for #3169, no code asked).
Optional (5)
service/flow.go:RefuseAuthRequestcopiesFlowAuthRequests.Refuse.api/flow_cookie.go: two middlewares where one would do.flowengine/auth_request.go: a sign-in without a page reads the same request row four times.oauth_sign_in_test.go: thestartandtokentest helpers are copied.api/flow.go: a third hand copy of the rule for a token the server could not judge.
Tally: 9 findings, 4 worth fixing, 5 optional. About 120 lines could go, most of them tests.
Worst issue: the missing test for the server's middleware chain (comment 1). Without it, sign-in from a live session can stop working on a deployed server while every Go test stays green.
One note on the PR description. The follow-up "The anonymous session Start creates before a live session answers is never used. It expires." no longer matches the code. Start now asks the engine first and creates a session only when a sign-in is needed (
nextgen/apps/api/internal/service/flow.go
Lines 296 to 308 in 5e6ebd9
Not checked: no test or build was run for this review. The TypeScript changes were read as a diff only.
POST /flows for an auth_request_id now reads the browser's session cookie. An active session of the project answers a login whose client needs no consent, so the flow ends in a terminal redirect with the code and no handoff_token or flow cookie. prompt=login, prompt=select_account and prompt=create still show a page, and so does any consent-requiring client or non-login purpose. prompt=none is accepted at /authorize. When no session can answer, the flow ends at the client's redirect URI with login_required, or consent_required when the client needs consent. A prompt=none request that no flow definition resolves gets login_required the same way.
A public client with no secret, answered at a loopback address or a custom scheme, can be presented by any program on the device. Its request now gets the sign-in page even when a session is live. AdmittedAuthRequest carries ClientIdentityAssured, set when the client holds a secret or its answer goes to an https address that is not loopback (RFC 8252 section 8.6). A prompt=none request for such a client ends at login_required, as it does when no session can answer. The OpenAPI description, the bundled spec, the generated Go code and ADR 081 say so, and the changeset is reworded to match. The flow tests cover an unassured client with and without prompt=none.
A refused request stayed open, so a reload of the login page after the person signed in elsewhere could send a code for a state the client had already heard refused. Refusing now expires the request at once, through a new ExpireAuthRequest statement in the Postgres, Spanner and SQLite dialects. A later flow for it is refused with flow.auth_request_invalid. The flow service and the authorization endpoint share the refusal, so both spend the request the same way. The OpenAPI description, the bundled spec, the generated Go code, ADR 081 and the changeset follow. Tests cover the expiry in the statement layer and the refusal in the service.
The handler no longer builds the prompt=none refusal itself. When no definition serves an authorization request, it passes the request to Start without a definition. Start asks the engine's AnswerWithoutSignIn for the refusal, so the refusal and the state it returns come from one place. AnswerWithoutSignIn accepts a nil definition only for a refusal. A request with a live session, or one without prompt=none, is an error. The state names the request's project and client, with no definition to read. AuthRequestRef gains ProjectID, the project the request belongs to, which the engine answers in when no definition serves it. FlowService.RefuseAuthRequest is removed from the interface and the service, along with its handler test fake. The flow engine architecture note describes the new path. Tests cover the engine's refusal and its rejection of other requests, and Start's refusal. The handler test now checks that Start receives the request without a definition.
Move the authorization request, the flow start and the token exchange into signInFixture methods, so the sign-in and live-session tests share one copy. The flow step decodes purpose, fields and actions too. Drop the live-session subtests for max_age, prompt=none, prompt=login, prompt=create, a consent-requiring client, an unknown flow definition and the session count. The service and engine tests cover those rules. The live-session test keeps only what the whole path shows, and its doc comment says so.
IAM-marco
left a comment
There was a problem hiding this comment.
Thanks for the fixes. I rechecked the review comments at a3d4ef6 and the changes I asked for are in.
One thing before merging: the branch conflicts with main, so ci did not run on this commit. Its last run was on 5e6ebd9. Could you please merge main and let ci run?
The conflicting files are:
apps/api/api/openapi/AGENTS.mdapps/api/api/openapi/bundled/openapi.jsonapps/api/internal/service/client_directory.goapps/api/internal/service/flow_auth_request.goapps/api/internal/service/flow_auth_request_test.goapps/cli/src/lib/backend/services/operation.tspackages/api/scripts/operations.ts
Please take care with flow_auth_request.go and client_directory.go. They hold the change that spends a refused request and the Public flag that decides whether a live session may answer.
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>
|
@wim07101993 is attempting to run Vercel CI for a commit to the zitadel team on Vercel, but is not a member of this team.
|


Context
<zitadel-login>showing the requesting client and the SDK reservation release are still open.Summary
The authorization endpoint and
POST /flowsnow answer an authorization request the way it asks, and answer it without a page when the browser is already signed in. Five commits, one per part, to review in order:POSTto the authorization endpoint is answered with a303to the sameGET.SameSite=Laxcookie with another site'sPOST. Without them, the endpoint could not count or expire the binding cookies the browser held.POSTwithoutSec-Fetch-Site. APOSTfrom the issuer's own site is unchanged._zflow_{flow_id}, so two sign-ins in one browser no longer end each other.POST /flowsdeletes the oldest the request carried beyond that.id._zflowcookie parameter leaves the spec. A newx-zitadel-cookieextension names the cookie instead, and@zitadel/api'soperationsexport carries it.<zitadel-login>starts over on a404or410.@zitadel/testing'sseedSessioncarries the new cookie.prompt,max_ageandlogin_hint.POST /flowsadmits the request before it resolves a definition.prompt=createstarts at registration, or signs in when the project has none.login_hintpre-fills the identifier and replaceshint.login_name. It is never submitted for the user, andhint.login_namenow pre-fills too.prompt=consentgets the consent step instead of a refusal.POST /flowsreads the browser's session cookie through a newWithBrowserSessionCookiemiddleware.max_age, and the client must need no consent. Then the first step is the terminalredirectwith the code, with no handoff and no flow cookie.prompt=login,prompt=select_accountand a client that needs consent still sign the person in.prompt=noneis now accepted. When no session can answer, the client getslogin_requiredorconsent_requiredat its redirect URI, and the request stays open.FlowResponse.clientholdsclient_id,application_id,name,redirect_host,document_hostandfirst_party, read once at admission and kept in the flow state.hint.app_idwhen the definition is resolved.flow.auth_request_invalid.Validation
On the rebased branch (on
589027c17):turbo run check-generate --filter=@zitadel/server --onlygo vet ./...andgo test ./internal/...inapps/apigo test -tags sqlite_integration -run 'TestOAuthSignIn|TestSignIn|TestFlow|TestAuthorize' ./internal/api/integration_test/node scripts/check-pr-title.mjsPer part, before the rebase:
go test -tags sqlite_integration ./internal/api/integration_test/(the whole suite)-tags postgres_integration -run 'TestOAuthSignIn|TestSignIn|TestFlow'-tags spanner_integration -run 'TestOAuthSignIn|TestSignIn'auth_requestscolumnsnode scripts/lint-openapi.mjs(0 errors)New end-to-end tests in
oauth_sign_in_test.go:TestOAuthSignInAsTheRequestAsks:login_hint,prompt=consent,prompt=create.TestOAuthSignInFromALiveSession: answered at once, with the code redeemed for a token. Alsomax_age,prompt=nonewith and without a session,prompt=login, andconsent_required.client.Not run:
@zitadel/components,@zitadel/testingand@zitadel/cli(the cookie part). This checkout lacksknip,unplugin-dtsand@lit/task, so CI is the first run.Release notes / changeset
.changeset/authorize-cross-site-post.md:@zitadel/serverpatch..changeset/flow-cookie-per-flow.md:@zitadel/serverand@zitadel/apiminor;@zitadel/components,@zitadel/testingand@zitadel/clipatch..changeset/auth-request-prompt-login-hint.md:@zitadel/serverminor,@zitadel/apipatch..changeset/auth-request-live-session.md:@zitadel/serverminor..changeset/flow-requesting-client.md:@zitadel/serverminor,@zitadel/apipatch.Notes
_zflowcookie parameter is gone from the generated clients. It sends back the_zflow_{flow_id}cookie the last response set.apps/cli/tests/unit/lib/orca/patchers/rule/vite-support.test.tstookmain's version. The cookie part only renamed_zflowin a test thatmainhas since removed.prompt=noneexempt. This matters more now thatprompt=noneis accepted.Startcreates before a live session answers is never used. It expires.clientin<zitadel-login>'s template context and onzitadel-flow-step. That changes the SDKs' event contract, so it comes on its own.🤖 Generated with Claude Code