Repository navigation
Conversation
POC for platform-project OAuth: authorization codes and refresh tokens are single-use records in the tokens table (oidc_access_token rows keyed by the grant in oidc_session_id), so a consume must report whether it found the row, and reuse detection revokes the whole grant. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An OAuth 2.1 authorization server for the platform project, behind platform.oauth.enabled: one app declared in code (the CLI as a public first-party client, the platform API and /mcp as its APIs, client ID metadata documents and stateless dynamic registration for MCP clients), EdDSA JWT access tokens with one audience each (RFC 8707), rotating refresh tokens with reuse detection, sign-in through the console's login, a minimal consent page for third parties, and an /mcp stub with a whoami tool. The API takes the access token as ADR 053 §5's user bearer on the operations a console session may call, and getMyUser accepts it. A proof of concept to learn from, not a merge candidate. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…erver (POC) zitadel login signs a developer in to a server with the authorization code flow, PKCE (S256) and a loopback redirect on a free port, after discovering the platform API's protected-resource metadata and its authorization server's metadata. The tokens live in the CLI's user config directory, owner-only. whoami asks GET /users/me with the token; logout revokes the refresh token and forgets the sign-in. deployment list falls back to the developer's sign-in when no project secret resolves, acting as the developer through ADR 053's grants. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Unit tests for the POC's protocol rules at the lowest layer that holds them: PKCE and redirect matching in internal/oauth, the user bearer's principal in the security handler, the code exchange, audience and refresh rotation against a real SQLite database, and the CLI's loopback sign-in and token store against a fake authorization server. SKILL.md and the command reference describe login, whoami and logout. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
What the POC built and ran end to end (the CLI and Claude Code against one built-in app), what worked, what was missing, and what the identity model in #2445 got right or wrong. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
v4 lost codes through a loopback redirect check that decoded redirect_uri twice and redirected to the once-decoded value. Here the request decodes it once and ParseRedirectTarget parses it once, and the value must now be its own canonical form with no '#' at all, so the URL checked is byte for byte the URL the browser is sent to. Tests cover v4's payload encoded once and twice, the redirect's Location, and the payload joins the shared redirect-target corpus. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ly spec on one getMyUser now also takes the platform access token, so the api spec's example of an operation only a session authenticates is getMySession. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🦋 Changeset detectedLatest commit: 4b55f9e The changes in this PR will be included in the next version bump. This PR includes changesets to release 24 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 |
…rom the console's domain
The platform project's issuer is now the domain the console is served on,
which it shares with the server in the cloud and on a self-hosted server.
Its metadata sits at that domain's root, and its endpoints stay under
/oauth/{project_id}/. ADR 081 §5 carves the platform project out of "the
server's own origin is never an issuer".
zitadel/oidc v3.51.16's op.Server now answers token, revocation and JWKS:
it routes them, parses forms and client credentials, and encodes errors.
Authorize stays this package's, since the library renders the errors
VerifyAuthRequest returns, leaves iss off its error redirects, and has no
resource parameter.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Main moved the Go module into apps/api (#2271), generates the API stubs into apps/api/internal/api/generated (#2273), and returns a wrapped handler from buildHTTPMux. So the oauth package moves to apps/api/internal/oauth, and its routes mount inside buildHTTPMux behind the API's chain, which also maps the loopback session cookie onto __Host-zitadel_session (#2488). The CLI's login commands declare their next steps in the typed next field (#2523), pass the command's abort signal to the API client, and keep no sign-in when the CLI has no config directory. login, whoami and logout follow main's skills in the Getting started group. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…een it Dynamic registration and client metadata documents accept any https redirect URI, and authorize sent some failures there before anyone signed in, such as an unsupported response_type, or login_required for prompt=none. That made the server a redirector for phishing (RFC 9700 §4.11.2; CodeQL #41). Such a failure now goes back only to a first-party client or a loopback URI, and the error page answers the rest. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The API moved under /api/v1 (ADR 077), so the platform API's identifier, the token's aud, is <base>/api/v1, and its protected-resource metadata sits at /.well-known/oauth-protected-resource/api/v1 (RFC 9728 §3.1). The CLI looks there and checks that the document names that resource (RFC 9728 §3.3). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… identity model ADR 081 §5's carve-out now names server.public_base's origin, so the console's other origins (server.console_origins) never mint an issuer. The POC findings link the identity model on main, call the records consents, take the model's answer on how a registration finds its app, drop the third row of server-declared apps now that the platform project deploys a release, and list the cloud's vercel.json rules and the PAT scheme among the follow-ups. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…evoke them
A consent records that a user let a client use some of an API's scopes
(ADR 082 §8). It is transient data stored like a session: a consents row in
the three dialects, whose deadline each use moves, never past
platform.oauth.consent_lifetime (90 days by default; ADR 072's model). The
codes and refresh tokens issued under it are tokens rows that name it as
their oidc_session_id, and it replaces the POC's grant ids.
- A third-party client is asked for consent again only for a scope the user
did not agree to, or on prompt=consent. A first-party client is never
asked, but gets a consent too, so the user sees it among connected apps.
- Revoking a refresh token (RFC 7009) ends that sign-in alone. A replayed
code or refresh token revokes every token of its consent.
- GET /users/me/consents lists a user's live consents, newest first, and
DELETE /users/me/consents/{consent_id} revokes one with its tokens, both
on the session cookie.
- consent.given and consent.revoked are audit events, written in the
transaction that gives or revokes the consent.
- A client_id longer than 1024 characters names no client, since a
consent's unique key holds it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nsent step The authorization endpoint no longer signs the user in or renders consent itself (ADR 081 §8–§11). It seals the validated request into an opaque handle, binds it to the browser with a cookie of its own, and sends the browser to the console's /login?auth_request=<handle>. POST /flow opens the request with that cookie, and the flow answers it: - It ends in a redirect to the client with the code, state and iss (or the error), whatever the definition's terminal step says, and keeps its handoff so the page keeps the session. - A third-party client, or prompt=consent, gets the reserved consent step after the sign-in; accept and deny are its actions. - A live session answers at once, under the consent step when needed and without a handoff; prompt=login signs in again, prompt=none shows no step. - Flow definitions can no longer name a step consent or account_choice. Every response of such a flow names the client. The POC's server-rendered consent page, its POST /consent and the /oauth/continue route are gone. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… its consent step The widget reads ?auth_request= from the page URL and sends it as auth_request_id on every POST /flow, restarts included (ADR 081 §8). A flow that answers a request names its client on every response, which the template context and zitadel-flow-step now carry. - The consent step shows the client's name beside the host it returns to, the API it would call and a line per scope (a scope without a text shows its name), with Allow and Deny. Focus does not land on Allow by itself. - Such a flow ends in a redirect to the client: the widget exchanges the handoff first, so the session stays on this origin, and navigates even when the exchange fails. Flows without a client redirect as before. - flow.auth_request_invalid reads as the catalog's text. The console's /login keeps auth_request in the URL and renders the widget for a live session too, so the flow can answer for it (Console ADR 0003). The mock API, the centered and minimal designs and Storybook learn the step. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…auth-415a8f # Conflicts: # apps/cli/src/lib/oclif/environment-command.ts
|
I went through this against ADR 081/082, #1283 and the #1425 epic, and wrote up where it fits and where it differs: #2860 (the note). Worth keeping as built: the authorize/back-channel split, the sealed request with a per-request binding cookie, consent as an engine-inserted step, one audience per token, and the redirect matcher. Questions before this moves on:
Separately: #2788 to #2801 describe much of what this PR and #2452 already built, under |
A code exchange or a refresh read the user only to see whether they still existed, so a user whose owning team was deactivated, and who can no longer sign in, kept getting access tokens for as long as the consent lived. Every status but active now ends the consent's tokens, as a deleted user's already did. The metadata also stops listing openid: the server issues no ID token yet (#2801), and a client such as Claude Code asks for every scope listed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
peintnermax
left a comment
There was a problem hiding this comment.
Review against the design note in #2860. I read the oauth package, the flow authorization code, the security handler, the consent service and the CLI's sign-in code. Storage dialects, widget and tests I did not read line by line, and nothing below was reproduced by running it.
What I'd keep as it is: the redirect matcher, the sealed request with its per-request binding cookie, PKCE checked before the code is redeemed (so a replay without the verifier revokes nothing), the kind and project checks in unseal, and refresh checking that the user is still active (that answers my earlier question 7).
Bugs worth fixing before this moves on
- Concurrent CLI refresh signs the developer out everywhere.
developerAccessToken(apps/cli/src/lib/login/flow.ts) has no lock. Two commands running in parallel both present the same refresh token; the second is treated as a replay and every token of the consent is revoked. Agents run commands in parallel, so this will happen. A lock file around the refresh, or a short grace window for the previous token on the server, would close it. - A metadata-document outage is answered as
invalid_client.documentCache.loadwraps a failed fetch aserrUnknownClient, so a refresh from a CIMD client fails with 401 while the client's host is briefly down, and the client drops its token.internal/AGENTS.mdasks that "could not decide" never becomes a refusal. Serving the stale entry on a failed refetch would do. - The refresh token is rotated before the access token is minted (
issueTokens). A failure afterRotateanswers 500 with the old token already spent; the retry then revokes the whole consent. Mint first, or do both in one step. - The metadata-document cache is unbounded, and failures are not cached. An unauthenticated
/authorizewith anhttps://client_id triggers a fetch each time. It needs a size bound, a negative cache and a per-host limit before the switch is turned on anywhere public. - Narrowing the scope on a refresh is permanent.
issued.Scope = requestedalso goes into the rotated refresh token. RFC 6749 §6 keeps the refresh token's scope; only the access token should narrow. - An oversized
statestill reacheshandOff. The length check runs late, and its own failure path passes the long state on, so the handle and the flow cookie exceed what a browser keeps. Check it first and drop it from the error hand-off. - Any 4xx on refresh deletes the stored sign-in in the CLI, a 429 or
invalid_targetincluded. Onlyinvalid_grantshould. - Binding cookies accumulate on
Path=/for ten minutes per request and are cleared only when a flow terminates. Repeated requests can push headers over limits on the console's origin. A narrower path, or a cap, would help. - The CLI accepts a callback without
issalthough the metadata advertises it. RFC 9207 §2.4 wants it refused. - Redirect targets are re-parsed with
url.Parseinauthorize.goand re-encoded withQuery().Encode(), whereinternal/AGENTS.mdasks forhttputil.ParseRedirectTargetonly. The re-encoding also means the browser is not sent byte for byte to the checked URL when a registered URI has a query.
Design points, from #2860
- One project.
Serverholds one project id, one issuer and the console path, and/mcpsits in the same package. #2793 asks for the issuer and project from the request. - Scopes are not enforced on the platform API.
HandleOAuth2builds the scope context from the user alone;UserBearercarries no scope. Fine while only the CLI gets these tokens, but it has to change before a third party does. resourceis required, which the epic's first scope cannot satisfy.openidis advertised with no ID token.- Open registration on the console's origin conflicts with ADR 082 §9's login-only rule. I'd keep both switches off until that is settled.
- The first-party skip. With a live console session, any page can navigate the browser into issuing a code for
clito a loopback port with no interaction. A consent once per device would close it.
Happy to go through any of these on a call.
From the review of #2451: - A client ID metadata document whose host cannot answer is served as it was last read, for up to an hour; without one the answer is 503, never invalid_client, so a client keeps its tokens. A refusal is remembered for a minute, concurrent requests share one fetch, and the cache holds 1,024 documents, 32 per host. - A refresh mints the access token and resolves the sealing key before it spends the refresh token, so a failed answer leaves the client a token to retry with, not a replay that ends the consent. - Narrowing the scope on a refresh narrows the access token only; the next refresh token keeps the scope it had (RFC 6749 §6). - An oversized state is checked first and left out of the error, so neither the handle nor the flow's cookie carries it. - A browser with five unfinished requests has their binding cookies cleared as the next one is set. - Stored redirect URIs are parsed with httputil.ParseRedirectTarget only, and the answer's parameters follow the registered query, which is no longer decoded and encoded again. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rant From the review of #2451: - Runs refresh a sign-in one at a time, under a lock file beside the stored sign-ins, and one that waited uses the token the run before it stored. Two agents' commands presented one refresh token at once, and the server read the second as a replay and revoked the consent. - Only invalid_grant forgets the sign-in. A 429, invalid_target, invalid_client, a 5xx or no answer keeps it for a later run, and a 429 is E_NETWORK, as a 5xx is. - The callback must name the discovered issuer as iss when the metadata promises it, and an error from another issuer is not trusted either (RFC 9207 §2.4). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| return Client{}, errUnknownClient | ||
| } | ||
| req.Header.Set("Accept", "application/json") | ||
| resp, err := c.fetch.Do(req) |
A review against the issues, the ADRs and the code found claims that had gone stale and contradictions that live in the ADRs and issues rather than in the note. The note now: - corrects the PKCE and iss conflict (only #2795 and the ADRs still require them), the library's authorize, and openid in #2451's metadata; - lists six decisions with their owners: a stored issuer, the response to a request without resource, registration as a project switch, the sealed request as an ADR 081 amendment, prompt=login and max_age, and what must hold before the platform project's issuer goes on; - moves the ID token and discovery into the first scope's server step and gates the platform project on those preconditions; - adds the cloud origin shared with the website, the platform issuer following public_base, sign-out, audit, limits and key rotation. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Consent is a step inside the one flow that answers the authorization request, not a round trip of its own; the note now walks through it, what a later request and a revocation do, and that #2451's step is all or nothing. Stripe's MCP consent stands for the other design, a per-resource selection, and what Zitadel would need for it. Open question 12 asks whether a user may allow part of a request. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Name #2451's consent events and the gaps that remain, separate the published test kit from the private API mock and its license, record the agreed login approach in the first-scope steps, and make the audit and limit criteria an explicit task of step 3. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
The pieces a person's token on /mcp needs were built once in the closed prototype #2451, are read against the epic in #2860, and public clients are being built again in #3409. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U
Summary
Zitadel's own OAuth for the
zitadelCLI and MCP clients, built to work the way a customer's authorization server will (ADR 081, ADR 082, the identity model): the platform project is a project like any other, so an agent using Zitadel's API or MCP server follows the same rules as any app. It began as a proof of concept, whose findings set the plan below. It was built out in steps, all of which are in.Stacked on #2452 (stack #2694): this PR's base is #2452's branch, whose apps, client registrations and
AppDirectorythe last step reads.What the branch does now:
apps/api/internal/oauth, behindplatform.oauth.enabled). The issuer isserver.public_base's origin, the domain the console shares with the server, under ADR 081 §5's new carve-out for the platform project. RFC 8414 metadata sits at the root and under/oauth/{project_id}/, and RFC 9728 metadata sits at each API's path (/.well-known/oauth-protected-resource/api/v1). zitadel/oidc'sop.Serveranswers token, revoke and JWKS; authorize and registration stay ours, because its authorize path has noresource, noisson errors, and renders errors it should redirect.<zitadel-login>(ADR 081 §8–§11), the way a customer's login app will answer its own authorization server:<console>/login?auth_request=<handle>. A cookie set for each request binds it to that browser.POST /flow. The flow keeps the request in its sealed cookie, so there is noauth_requeststable; the worst case fills 3.3 KB of the cookie's 4 KiB, and a test holds it there.code,stateandiss(or the error), whatever its definition's terminal step says. The widget first exchanges the handoff, so the console keeps the session.prompt=consent, gets the reservedconsentstep after the sign-in: the client's name, the host it returns to, the API and a line per scope, with Allow and Deny.prompt=loginsigns in again, andprompt=nonenever shows a step.consentoraccount_choice. The POC's server-rendered consent page and its/login?next=route are gone.AppDirectory, the way a customer's authorization server will find them. Thezitadelapp is a built-in app the directory serves beside the platform project's stored apps: clientcli(public, first party, loopback on any port), APIsplatform(aud=<base>/api/v1) andmcp, and registration through client ID metadata documents and RFC 7591.POST /registerwrites a client registration (dcr_…) instead of a sealed client id. Its first authorization request joins it to the app whose API it names, and it is held to that app. The consents implementClientRegistrationConsents: a live consent keeps a registration past its hour, and deleting one deletes its consents and their tokens.consentpolicy andgrant_typesdecide the consent step and the grants.resource, and a scope the API does not define isinvalid_scope, as agreed with feat: add apps with their OAuth clients and APIs, and zitadel apps create #2452. Confidential clients wait for client authentication at the token endpoint.consentstable, all three dialects): one per user, client and API, stored like a session. A third-party client asks again only for a scope the user has not agreed to, or onprompt=consent. The CLI is never asked but gets one too, so it shows among the user's connected apps. A consent lastsplatform.oauth.consent_lifetime(90 days) at most, and ends sooner when its refresh token goes unused. Revoking it ends every token issued under it; signing out on one machine ends only that sign-in.GET /users/me/consentsandDELETE /users/me/consents/{consent_id}, withconsent.givenandconsent.revokedaudit events.flow.auth_request_invalidin the login) instead of going to a non-loopback redirect URI (RFC 9700 §4.11.2).pat, andoauth2becomes the platform project's authorization code flow: a person's token, acting with their grants (ADR 053 §5). Every operation that takespattakesoauth2too, except the app plane (auth attempts, challenges, handoffs, session create and exchange, the claim, passkey registration); a test walks the spec to hold that. Both schemes readAuthorization: Bearer, so each handler skips the other's tokens. For a person,POST /projects/querylists the projects they may act on. The generated Go client'sSecuritySourcegainsPat./mcp: a Streamable HTTP stub with awhoamitool; it answers 401 withresource_metadata.zitadel login,whoamiandlogout, which find the server from the API's RFC 9728 metadata. Every project command then acts as the developer, unless the run names a secret: a secret in the process environment,--env-fileor a non-development environment's files wins; then the sign-in; then the secret setup stored (.env.local,.env.development.local,.zitadel/secret, which setup all writes).--credential project|loginforces one, the envelope'scredentialnames it, and a refused credential is never retried with the other.previewandclaimkeep the secret.zitadel apicalls what a person's token may call as the developer.Validation
go test ./...inapps/api, and the SQLite lane (go test -tags sqlite_integration ./...), after every commit.internal/storage/stmttestand the API integration suite, against a local Postgres 18 (ZITADEL_TEST_POSTGRES_URL).moon run server:lint server:vet server:format server:openapi, andmoon run server:check-generate-prunedon its own.vitest runinapps/cli) andmoon run workspace:check -- --only release.moon run components:test components:typecheck api-mock:test api-mock:typecheck console:test console:typecheck storybook:typecheck storybook:test config:test sdk-core:test sdk-core:typecheckand those projects'lint; thenmoon run components:build e2e:demo-next-mock e2e:demo-nuxt-mock.zitadel loginwith the console already signed in: straight back to the CLI, signed in as the operator.zitadel loginwithprompt=login: the email and password steps, thenPOST /sessions/exchange, then back to the CLI.access_deniedwithstateandiss.GET /users/me/consentslists the CLI and the agent.projects list(the developer's project, not the platform's),deployment list,events listandvariable listwithcredential: login, a variable written with the stored token,--credential loginover a secret in the environment,--credential projectwith none (the error names the variable), and the token refused oncreateAuthAttempt(401).moon run cli:typecheck cli:lint cli:test(6,039 tests),go test ./...and the SQLite lane,go veton every build tag,moon run docs:typecheck docs:lint.stmttestsuites (one active key per algorithm,ListSigningKeys) on SQLite and Postgres 18, the key service's minting and race, and the token endpoint, JWKS andVerifyfor RS256, ES256 and forged tokens.go test ./..., the SQLite lane andgo veton every tag;moon run server:generate api:generate cli:typecheck cli:lint cli:test api:test api:typecheck config:test config:typecheck docs:typecheck docs:lint docs:generate. Two CLI proxy tests timed out minting their certificate under the full run and passed on their own.internal/storage/...andinternal/api/integration_test/...(835 tests).Release notes / changeset
.changeset/platform-oauth-login.md(@zitadel/climinor,@zitadel/serverminor):zitadel login,whoamiandlogout, every project command as the developer and--credential, the platform project's authorization server behindplatform.oauth.enabledwith sign-in through the console, RS256 access tokens and a cacheable JWKS, consents and their lifetime, and the two me endpoints..changeset/login-consent-step.md(@zitadel/components,@zitadel/sdk-core,@zitadel/config,@zitadel/api,@zitadel/server, all minor):<zitadel-login>answers an authorization request, with its consent step;clientonzitadel-flow-stepand on flow responses; the reserved step names..changeset/api-person-token.md(@zitadel/server,@zitadel/api, minor): a person's token on every operation but the app plane, thepatscheme besideoauth2(the Go client'sSecuritySourcegainsPat),loginin the operation list, a person's projects.Notes
000041and000042, SQLite000028and000029, Spanner000045and000046, after feat: add apps with their OAuth clients and APIs, and zitadel apps create #2452's. The branch's cloud preview database recorded this PR's migrations under the old numbers, so it skips feat: add apps with their OAuth clients and APIs, and zitadel apps create #2452's: drop it and redeploy the preview before relying on it./.well-known/oauth-*,/oauth/…and/mcpreach the website there. Thevercel.jsonrule comes when the feature ships (ADR 081 §6), so scanners don't wake the server's function before then.(project_id, oidc_session_id)index ontokens, batched deletes on Spanner, the token's scopes as the intersection of roles and consented scopes, one_zflowcookie per flow (two requests in one browser's tabs still share it),login_hint,prompt=create,max_ageand account choice, and an end-to-end lane through the console.🤖 Generated with Claude Code