Repository navigation
feat(api): keep an OAuth client connected with refresh tokens, and serve clients that hold no secret - #3495
Conversation
…and narrow it by policy Decided on 2026-12-01. ADR 082 §9 kept both registration paths off by default and asked for a login-only issuer. For the platform project's issuer, which is what an agent connects to, a client that presents a client ID metadata document is now admitted by default, and an operation policy narrows which. §9 lists what no policy switches off for a client nobody vouched for: consent on every request, both hosts on the consent screen, tokens and refresh tokens that end with the session, and a fetch held to public addresses. A customer project stays opt-in, and dynamic registration still needs a login-only issuer. ADR 091 §8 lists what a client still needs, from what today's clients require: client documents, clients without a secret, refresh tokens, iss on every answer, and the cloud's routes. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U
…ld no secret A request that is granted offline_access is answered with a refresh token beside the access token. The scope is granted to a client whose grant_types list refresh_token, and the issuer's metadata lists it, with the refresh token grant and the `none` authentication method. A grant keeps one row for all its refresh tokens: the id of the current token and of the one it replaced. The token a rotation replaced is answered once more for a minute, with the token that replaced it; any older one ends the grant. A grant ends with the session it was given in, with its user, and when its issuer's authorization server is off. What the grant is for is sealed in the token with the project's token key, and read as a refresh token only when that key sealed it as one. A refresh resolves the newest deployment to the issuer of its token, which is where a declared client's secret is checked. A public client must send a PKCE challenge, returns to a loopback address on any port, and exchanges its code and refreshes with its client ID alone. A token request may name the resource of its grant again and no other. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U
…nected Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U
…r changeset ADR 037 gains the minute in which a replaced refresh token is answered again, and the one row a grant keeps. ADR 082 §7 says what a refresh checks. ADR 091 §8 moves refresh tokens and secretless clients to what is built, and names what still keeps a client out. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🦋 Changeset detectedLatest commit: 645b980 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 |
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. |
There was a problem hiding this comment.
🟡 Changes recommended
Grace retries can restore scopes dropped during refresh-token rotation, while disabled-issuer refresh rejection leaves grants reusable after re-enablement instead of revoking them.
2 open issues
What changed in this PR
This PR extends the OAuth sign-in flow with session-bound refresh tokens and endpoint support for clients without secrets, preparing the platform’s MCP authorization flow for persistent connections.
Changes:
- Adds refresh-token issuance, rotation, retry grace, revocation, and storage across PostgreSQL, SQLite, and Spanner.
- Supports public clients with mandatory PKCE, advertises OAuth capabilities, and validates token-request resources.
- Updates consent translations, audit contracts, generated clients, documentation, and tests.
| File | Description |
|---|---|
packages/go/api/oas_validators_gen.go |
Validates the new resource-mismatch reason. |
packages/go/api/oas_schemas_gen.go |
Updates generated event types and comments. |
packages/go/api/oas_json_gen.go |
Decodes the new event reason. |
packages/components/src/orchestrator/locales/it.ts |
Adds Italian offline-access consent text. |
packages/components/src/orchestrator/locales/en.ts |
Adds English offline-access consent text. |
packages/components/src/orchestrator/locales/de.ts |
Adds German offline-access consent text. |
docs/design/api/events-catalog.md |
Documents refresh-grant audit events. |
docs/adrs/092-mcp-server.md |
Updates MCP authorization implementation status. |
docs/adrs/082-oauth-and-oidc-server.md |
Records refresh and client-admission decisions. |
docs/adrs/047-dialect-id-generation.md |
Registers the refresh-grant ID prefix. |
docs/adrs/037-token-lifecycle.md |
Defines rotation grace and grant storage. |
apps/docs/content/docs/guides/enable-oauth.mdx |
Updates the discovery document example. |
apps/api/internal/storage/stmttest/schema_nullability_test.go |
Checks refresh-grant column nullability. |
apps/api/internal/storage/stmttest/refresh_grant_test.go |
Tests grant persistence across dialects. |
apps/api/internal/storage/dialect/sqlite/statement.go |
Registers SQLite grant statements. |
apps/api/internal/storage/dialect/sqlite/refresh_grant.go |
Implements SQLite grant persistence. |
apps/api/internal/storage/dialect/sqlite/migration/sql/000049_refresh_grants.sql |
Creates SQLite grant storage. |
apps/api/internal/storage/dialect/spanner/statement.go |
Registers Spanner grant statements. |
apps/api/internal/storage/dialect/spanner/refresh_grant.go |
Implements Spanner grant persistence. |
apps/api/internal/storage/dialect/spanner/migration/sql/000066_refresh_grants.sql |
Creates Spanner grant storage. |
apps/api/internal/storage/dialect/postgres/statement.go |
Registers PostgreSQL grant statements. |
apps/api/internal/storage/dialect/postgres/refresh_grant.go |
Implements PostgreSQL grant persistence. |
apps/api/internal/storage/dialect/postgres/migration/sql/000062_refresh_grants.sql |
Creates PostgreSQL grant storage. |
apps/api/internal/service/statement.go |
Defines refresh-grant storage operations. |
apps/api/internal/service/session.go |
Deletes refresh grants on session revocation. |
apps/api/internal/service/refresh_grant.go |
Implements refresh lifecycle and token issuance. |
apps/api/internal/service/mocks/service.mock.go |
Adds generated grant-storage mocks. |
apps/api/internal/service/auth_request.go |
Issues refresh tokens during code redemption. |
apps/api/internal/service/auth_request_test.go |
Tests resource validation and updated redemption results. |
apps/api/internal/oauth/token.go |
Adds refresh exchange and public-client authentication. |
apps/api/internal/oauth/token_test.go |
Tests token responses and public clients. |
apps/api/internal/oauth/server.go |
Wires refresh storage and metadata scopes. |
apps/api/internal/oauth/refresh_test.go |
Tests refresh endpoint behavior and errors. |
apps/api/internal/oauth/metadata.go |
Advertises refresh grants, scopes, and none authentication. |
apps/api/internal/oauth/metadata_test.go |
Tests expanded discovery metadata. |
apps/api/internal/oauth/client.go |
Adds public-client behavior and refresh context. |
apps/api/internal/oauth/authorize.go |
Grants offline access and requires public-client PKCE. |
apps/api/internal/oauth/authorize_test.go |
Tests offline access and public-client authorization. |
apps/api/internal/domain/refresh_grant.go |
Defines grants, sealed tokens, and reuse rules. |
apps/api/internal/domain/refresh_grant_test.go |
Tests token sealing and rotation-grace classification. |
apps/api/internal/domain/event_payload.go |
Adds resource mismatch and updates client-ID comments. |
apps/api/internal/domain/auth_request.go |
Defines the resource-mismatch error. |
apps/api/internal/domain/application.go |
Adds public-client identification. |
apps/api/internal/api/integration_test/oauth_sign_in_test.go |
Adds a refresh-capable client fixture. |
apps/api/internal/api/integration_test/oauth_refresh_test.go |
Exercises refresh lifecycle over HTTP. |
apps/api/internal/api/integration_test/oauth_metadata_test.go |
Checks expanded discovery capabilities. |
apps/api/internal/api/integration_test/oauth_code_test.go |
Adapts code-redemption assertions. |
apps/api/internal/api/integration_test/helpers/oauth.go |
Wires the refresh service into integration tests. |
apps/api/internal/api/integration_test/access_token_test.go |
Adapts access-token issuance helpers. |
apps/api/internal/api/generated/oas_validators_gen.go |
Validates the new event reason. |
apps/api/internal/api/generated/oas_schemas_gen.go |
Updates generated server event types and comments. |
apps/api/internal/api/generated/oas_json_gen.go |
Decodes the resource-mismatch reason. |
apps/api/internal/api/error_handler_test.go |
Registers OAuth-only error exclusions. |
apps/api/cmd/server/server.go |
Wires the production refresh service. |
apps/api/api/openapi/endpoints/events/payloads/auth-token-issued-payload.yaml |
Documents client IDs on refresh-issued tokens. |
apps/api/api/openapi/endpoints/events/payloads/auth-request-exchange-failed-payload.yaml |
Adds the resource-mismatch event reason. |
apps/api/api/openapi/components/schemas/errors/refresh-token_invalid.yaml |
Adds the generated invalid-refresh schema. |
apps/api/api/openapi/components/schemas/errors/refresh-scope_not_granted.yaml |
Adds the generated refresh-scope error schema. |
apps/api/api/openapi/components/schemas/errors/authreq-resource_mismatch.yaml |
Adds the generated resource-mismatch schema. |
apps/api/api/openapi/components/examples/errors/refresh-token_invalid.yaml |
Adds the generated invalid-refresh example. |
apps/api/api/openapi/components/examples/errors/refresh-scope_not_granted.yaml |
Adds the generated refresh-scope error example. |
apps/api/api/openapi/components/examples/errors/authreq-resource_mismatch.yaml |
Adds the generated resource-mismatch example. |
apps/api/api/openapi/bundled/openapi.json |
Refreshes the bundled event contract. |
.changeset/oauth-refresh-tokens.md |
Records release notes and compatibility changes. |
Review effort: Balanced
| next := *token | ||
| next.Scopes = granted | ||
| next.TokenID = grant.TokenID |
There was a problem hiding this comment.
Not changed in this PR. A grant's scopes travel in its sealed refresh token and the grant row holds no scope list, so a grace retry has only the previous token's scopes to narrow. Storing the ceiling on the row is a schema change in all three dialects, which is more than this review round should carry.
The sequence needs a scope to leave the API's defined scopes and return within the one-minute grace. For the platform API that list is built into the server, so it takes two server versions answering the same grant within that minute, for example during a rolling deploy of a release that removes a scope. The scope that returns is one the person consented to and the older version still defines. Noted as a follow-up.
Generated by Claude Code
| case !settings.Enabled: | ||
| return nil, "", oidc.ErrInvalidGrant().WithDescription("the refresh token is invalid, expired or already used"). | ||
| WithParent(errors.New("the authorization server is off at the grant's issuer")) |
There was a problem hiding this comment.
Kept as it is, and the record corrected instead: ADR 092 now says that no refresh is answered while the issuer's authorization server is off, and that the grant is not deleted then.
Whether turning the switch off should end every grant for good is a product decision that I have left to the PR author: a server started once without the setting would otherwise sign every client out for good. Until then the grant still ends with its session and with its own lifetime.
Generated by Claude Code
…orization server is off The MCP record said the grant ends. The token endpoint refuses the refresh and deletes nothing, so the grant is answered again if the server is turned back on before its session ends. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U
…tokens # Conflicts: # docs/design/api/events-catalog.md # packages/components/custom-elements.json


Context
Summary
A client of the platform project's issuer keeps its grant alive with refresh tokens, and the endpoints serve a client that holds no secret. Nothing changes for a server that leaves
oauth.enabledoff, which is the default.Refresh tokens
offline_access. A client whosegrant_typeslistrefresh_tokenasks for the scope, the consent step shows it ("Keep access until your session ends"), and the code is exchanged for a refresh token beside the access token. The metadata lists the scope and the grant, since clients ask for it only then.grant_type=refresh_tokenanswers a new access token and the refresh token that replaces the one presented. The token that was just replaced is answered once more for a minute, with the token that replaced it: clients repeat a refresh after a lost response, and processes that share a grant refresh at the same moment. Any older token ends the grant for every holder.refresh_grantsholds the id of the current token and of the one it replaced. What the grant is for is sealed in the token with the project's token key, and read as a refresh token only when that key sealed it as one: a session token is none, and a refresh token is no bearer for the API.invalid_grant.resourceis checked at the token endpoint. A token request may name the resource of its grant again and no other (invalid_target).Clients that hold no secret
type: public) authenticates withnone: it exchanges its code and refreshes with its client ID alone, and the metadata listsnoneamong the authentication methods.Validation
Run in
apps/apiunless noted:go vet ./..., and with-tags sqlite_integrationon the integration packagesgo test ./... -count=1go test -tags sqlite_integration ./internal/api/integration_test/... ./internal/storage/stmttest/... -count=1ZITADEL_TEST_POSTGRES_URL):go test -tags postgres_integration ./internal/api/integration_test/ ./internal/storage/stmttest/ -count=1node scripts/go-lint.mjs,turbo run check-generate openapi --filter=@zitadel/server,node scripts/check-adrs-index.mjsandpnpm run check-openapi-rules(repo root)turbo run lint typecheck --filter=@zitadel/components, and the components' unit project (repo root)full-prpassed on this PR's last commit while it was part of feat(api): serve an OAuth client that presents its client ID metadata document #3488.TestOAuthRefreshKeepsAGrantAliveruns it over HTTP from end to end: rotation, a repeated token, a reused one, a session that ends.The browser run that exercised refresh tokens used a client with a metadata document; it is described in #3488.
Not run: the Spanner lane locally (it has the new
refresh_grantsmigration and statements), and the e2e lanes.After an automated review, one more commit, which changes ADR 092 only: it said a grant ends when its issuer is turned off, and the code refuses the refresh without deleting the grant.
Release notes / changeset
.changeset/oauth-refresh-tokens.md— the OAuth server issues and rotates refresh tokens (@zitadel/server,@zitadel/api,@zitadel/components)Notes
resourcethat is not its grant's, where it ignored the parameter.refresh_grantsis new (Postgres000062, SQLite000049, Spanner000066). feat: add public OAuth clients with origins and private-use redirects #3409 may claim the same numbers; whichever merges later renumbers.session.default_ttlmoves that for every session.type: public,none, PKCE required), and leavesapplication.jsonatconfidential. The two will conflict inoauth/client.go,oauth/token.goanddomain/application.go, in lines that say the same.authreq.resource_mismatch,refresh.token_invalid,refresh.scope_not_granted. The first is also a newreasonofauth.request.exchange.failed.auth.token.issuedandauth.token.revokedalso record a refresh, a grant that starts and a grant that ends, the last two with the entityrefresh_grant(docs/design/api/events-catalog.md).https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U
Generated by Claude Code