Repository navigation
feat: sign in from the CLI, and create personal access tokens with it - #3564
Conversation
…platform ADR 095 is the record ADR 094 §5 waits for before a PAT is admitted. A PAT belongs to a person homed in the platform project and acts as them, capped by its scopes, on the operations a person's token reaches. It expires within 90 days, is created only from a Console session, and is listed and revoked by its owner. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmS8uCXd1d5jCxWaiSf
The user decided that the CLI, the API and MCP matter more than the Console for creating a PAT. So a person's OAuth token may create one with a scope the consent step never preselects, holding no scope that token lacks; a PAT still never creates one, and the creating client is recorded. Scope choice on consent is on main (#3543), which the first draft missed. A PAT is now an opaque 256-bit secret stored as its SHA-256, with its record id and a checksum in the token, so it depends on no key and a copy of the table holds nothing usable. The 90-day limit is to become a policy later. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmS8uCXd1d5jCxWaiSf
Creating a PAT is a marked call with a scope of its own, so ADR 094 §5's rule fits it: the scope is the gate, and the MCP endpoint asks where the client can answer once it asks about marked calls at all. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmS8uCXd1d5jCxWaiSf (cherry picked from commit c757ba5)
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmS8uCXd1d5jCxWaiSf (cherry picked from commit bef352c)
The CLI signs in to the platform issuer with "<issuer>/cli-client.json" as its client ID. The issuer serves that document, and the client directory answers that one URL from memory instead of fetching it, so the CLI signs in to a local or self-hosted server with no outside host. The document is read like any client's: a public client with a loopback redirect and PKCE, never first-party, so the person sees the consent step. It is served on the platform issuer only, where oauth.client_documents is on, and is not held to oauth.client_document_hosts, which names whose documents may be fetched. Every other URL on the server's own origin still names no client. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmS8uCXd1d5jCxWaiSf (cherry picked from commit 71f5457)
PATs are off until personal_access_tokens.enabled switches them on, since they do open a bearer path a server without OAuth did not have, and §7 no longer says otherwise. The create scope is never granted without the consent step, and the MCP endpoint asks before a PAT is created where the client can. A person holds at most 50 live PATs. The risks now name the audience a PAT leaves and the Console session that outlives recovery, with the options and a recommendation for the latter. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmS8uCXd1d5jCxWaiSf (cherry picked from commit 93677b0)
A person homed in the platform project creates a PAT with createMyPersonalAccessToken (POST /users/me/personal_access_tokens), lists and revokes their own with listMyPersonalAccessTokens and revokeMyPersonalAccessToken, from a Console session, an access token issued for them, or (to list and revoke) a PAT (ADR 095). A PAT reads zpat_<id>_<secret><checksum>: a 256-bit random secret whose SHA-256 the tokens record keeps, found by the record id and compared in constant time; a wrong checksum is refused before any read. The API and the MCP endpoint take it on the operations an access token issued for a person reaches, through the same gate: its owner is the principal, its scopes a ceiling on the owner's grants at each call, and a refusal names the scope. It expires within 90 days and stops while its owner is not active. Creating one with an access token needs personal_access_token.create, which consent never preselects; the PAT holds no scope that token lacks and records its client. A PAT never creates one. Events of a PAT's calls name the owner as a human actor, the PAT as token_id and pat_shared as delegation_type. tokens gains name, secret_hash and client_id in the three dialects. The MCP tool list budget is raised by the three tools' 3,700 bytes until the change that makes room in it lands. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmS8uCXd1d5jCxWaiSf (cherry picked from commit 442a041)
…client A first-party client is asked no consent, so it would be granted personal_access_token.create unasked, and with it a credential that outlives its grant. The scope is now granted only on the consent step, whoever the client is. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmS8uCXd1d5jCxWaiSf (cherry picked from commit edec824)
…ault PATs were served wherever the platform project is, outside oauth.enabled, so a server that took no person's bearer before would take a PAT after. personal_access_tokens.enabled (NEXTGEN_PERSONAL_ACCESS_TOKENS_ENABLED) now switches them on, off by default as oauth.enabled is. Off, the three operations answer not_implemented and a zpat_ bearer is refused as an unknown one. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmS8uCXd1d5jCxWaiSf (cherry picked from commit 55f1699)
…pired A credential that is only ever added to is one nobody reviews. Creating a 51st live PAT is refused with tkn.pat_invalid until the person revokes one. Expired rows stay until a purge, which is a follow-up, and are not counted. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmS8uCXd1d5jCxWaiSf (cherry picked from commit 234fa22)
A PAT leaves the audience of the token that created it: a token issued for the MCP endpoint creates one through the endpoint, and the PAT then answers on the API directly, where the endpoint's questions do not reach. createMyPersonalAccessToken is now marked x-zitadel-asks: the endpoint asks the person where the client can ask them, and sends the call where it cannot, its own scope, ticked on purpose, being the gate (ADR 094 §5). The tool says so, at 84 bytes, which the list budget's raise now counts. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmS8uCXd1d5jCxWaiSf (cherry picked from commit 3b94cf2)
The endpoint now asks before createMyPersonalAccessToken where the client can ask, so the agent's client in the integration test answers as its person would, and the test holds that the person was asked. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmS8uCXd1d5jCxWaiSf (cherry picked from commit 6cc66fb)
A project secret's scopes cover the three operations on a person's own PATs, so the MCP endpoint listed them as tools that could only be refused. No secret is anyone's person: Covers now passes them over for a secret. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmS8uCXd1d5jCxWaiSf (cherry picked from commit 4d64c49)
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmS8uCXd1d5jCxWaiSf (cherry picked from commit 6108cd1)
A PAT is persisted only with its secret's hash, and the Postgres dialect's own token test still created one without it, which the Postgres lane refused. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmS8uCXd1d5jCxWaiSf (cherry picked from commit 5c38672)
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmS8uCXd1d5jCxWaiSf (the ADR part of commit 36bd497ba2, whose renames of CLI files belong to the CLI change)
…-access-tokens-cli-base
… claude/personal-access-tokens-cli-base
… from the API mock The mock answers createMyPersonalAccessToken, listMyPersonalAccessTokens and revokeMyPersonalAccessToken for the bearer that sent them, as the server answers a person's own, and refuses what the server refuses: no credential, a PAT creating a PAT, the create scope, an expiry past 90 days. It also serves the MCP endpoint's protected-resource metadata and the platform issuer's metadata, which `zitadel login` reads to find where to sign in. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmS8uCXd1d5jCxWaiSf (cherry picked from commit c29d3da)
`zitadel login` signs a person in to a server's platform issuer in their browser: the authorization code flow with PKCE and a loopback redirect, as the client whose document the issuer serves at <issuer>/cli-client.json. The person consents on the server's own page, where only reads start ticked. The link is printed for an agent to hand on, and a browser opens unless --no-open. The sign-in is kept per server in the CLI's config directory, mode 0600, and refreshed under a lock so no two runs present one refresh token. `zitadel pat create|list|revoke` act as the signed-in person: create holds the token to the scopes the sign-in holds and to 90 days, and prints it once. `zitadel logout` forgets the sign-in; the server has no endpoint that ends the grant yet, so it says so. The sign-in's OAuth requests go through one file, which the no-raw-fetch rule allows: they are no operation of the API and carry none of its credentials. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmS8uCXd1d5jCxWaiSf (cherry picked from commit 6bfeaef)
The API reference shows the command behind each operation, and the CLI's coverage test holds every operation to a command that calls it: the three personal access token operations now name pat create, pat list and pat revoke, which call them through the person's own sign-in. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmS8uCXd1d5jCxWaiSf (cherry picked from commit 6da0484)
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmS8uCXd1d5jCxWaiSf (cherry picked from commit 36bd497)
…does The CLI names a command's noun after the collection the API lists, and answers to its plural: the list operation returns personal_access_tokens, so the commands are personal-access-token create, list and revoke, and answer to personal-access-tokens too. The topic gets its description in root help, which the longer noun widens. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmS8uCXd1d5jCxWaiSf (cherry picked from commit 609f1ee)
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🦋 Changeset detectedLatest commit: 1628c1b 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. |
…-api main chose tool sets by URL (#3555): the catalog keeps this branch's asksWhereItCan beside main's tags, and the one budget on the tool list gives way to main's three checks. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U
main holds this branch's base, ADR 095, as one squash commit (#3548). Its tree is the base's final head merged with the main before it, which this branch already holds, so the squash is recorded as merged and nothing changes. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U
main gained a person's own reads (#3559), the client secret's rotation (#3561), the session type (#3551) and the CLI's client document (#3558). The personal access token migrations move behind the session type's (Postgres 64, Spanner 68, SQLite 51). A secret is refused on a person's own reads and on their personal access tokens alike, and the server's code is generated again from the merged spec. The tool-set tests expect the three token tools in the users set. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U
The spec marks createMyPersonalAccessToken, listMyPersonalAccessTokens and revokeMyPersonalAccessToken x-zitadel-self, as it marks a person's own reads: the CLI, which holds a project secret, refuses them with its own reason, and the docs show a token issued for the person in their samples. The API passes a secret over on them before it is looked at, as on a person's own read, so the request is answered as one that sent no bearer. They stay a class of their own in the contract tests, since they name no project. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U
main gained a person's own sessions (#3560). The server's code is generated again from the merged spec, the tool-set tests expect both changes' tools in the users set, and ADR 092's measured figures count the three token tools: 91 on a plain URL, and 52 tools, 68,271 bytes, on the list a default consent yields. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U
The API's branch took main: the three token operations are marked a person's own (x-zitadel-self) beside this branch's x-zitadel-cli, the client directory is main's, which names first-party clients and answers the CLI's client, and the bundled spec is generated again. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U
main holds this branch's bases as squash commits: the personal access token API (#3563), and before it ADR 095 (#3548) and the CLI's client document (#3558). The token API's squash has the tree of its branch's final head, which this branch already holds, so it is recorded as merged and nothing changes. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U
There was a problem hiding this comment.
🟡 Changes recommended
Login writes and logout bypass the refresh lock, allowing concurrent refreshes to overwrite the selected account or restore credentials after logout.
3 open issues
What changed in this PR
Adds browser-based CLI sign-in and personal access token management, building on the platform’s OAuth client and token API.
Changes:
- Adds login, logout, protected credential storage and token refresh.
- Adds personal access token creation, listing and revocation.
- Updates mocks, tests, API command mappings and documentation.
| File | Description |
|---|---|
| packages/api-mock/src/spec-conformance.spec.ts | Tests token routes. |
| packages/api-mock/src/platform-handlers.ts | Mocks tokens and OAuth discovery. |
| packages/api-mock/src/__tests__/spec-exceptions.ts | Registers discovery exceptions. |
| biome-plugins/no-consent-bypass.grit | Allows sign-in HTTP requests. |
| apps/docs/content/docs/guides/personal-access-tokens.mdx | Documents CLI token creation. |
| apps/cli/tests/unit/lib/sign-in/sign-in.test.ts | Tests sign-in lifecycle. |
| apps/cli/tests/unit/cli/commands/personal-access-token/revoke.test.ts | Tests token ID validation. |
| apps/cli/tests/unit/cli/commands/personal-access-token/create.test.ts | Tests creation flags. |
| apps/cli/tests/unit/cli/commands/help.test.ts | Updates root help expectations. |
| apps/cli/tests/unit/cli/commands/api-coverage.test.ts | Tracks token command coverage. |
| apps/cli/tests/unit/__snapshots__/index.test.ts.snap | Records new command flags. |
| apps/cli/tests/integration/personal-access-token-revoke.spec.ts | Covers revocation behavior. |
| apps/cli/tests/integration/personal-access-token-list.spec.ts | Covers listing behavior. |
| apps/cli/tests/integration/personal-access-token-create.spec.ts | Covers creation behavior. |
| apps/cli/tests/integration/logout.spec.ts | Covers logout behavior. |
| apps/cli/tests/integration/login.spec.ts | Covers login links and timeout. |
| apps/cli/tests/helpers/project.ts | Adds signed-in test fixtures. |
| apps/cli/tests/helpers/platform.ts | Adds hostile token responses. |
| apps/cli/src/lib/sign-in/tokens.ts | Handles token exchange and revocation. |
| apps/cli/src/lib/sign-in/store.ts | Stores credentials and coordinates refresh. |
| apps/cli/src/lib/sign-in/pkce.ts | Generates PKCE and state values. |
| apps/cli/src/lib/sign-in/loopback.ts | Receives browser callbacks. |
| apps/cli/src/lib/sign-in/index.ts | Coordinates the sign-in lifecycle. |
| apps/cli/src/lib/sign-in/http.ts | Sends bounded OAuth requests. |
| apps/cli/src/lib/sign-in/discovery.ts | Discovers issuer endpoints and scopes. |
| apps/cli/src/lib/backend/services/personal-access-token.ts | Wraps token API operations. |
| apps/cli/src/lib/backend/index.ts | Exports the token service. |
| apps/cli/src/index.ts | Registers new commands. |
| apps/cli/src/cli/commands/signed-in.ts | Supplies person-authenticated services. |
| apps/cli/src/cli/commands/personal-access-token/revoke.ts | Implements confirmed revocation. |
| apps/cli/src/cli/commands/personal-access-token/list.ts | Implements paginated listing. |
| apps/cli/src/cli/commands/personal-access-token/id.ts | Validates token IDs. |
| apps/cli/src/cli/commands/personal-access-token/create.ts | Implements scoped token creation. |
| apps/cli/src/cli/commands/logout.ts | Implements local sign-out. |
| apps/cli/src/cli/commands/login.ts | Implements browser sign-in. |
| apps/cli/src/cli/commands/bases.ts | Adds person-command bases. |
| apps/cli/skills/zitadel-cli/SKILL.md | Documents agent-facing behavior. |
| apps/cli/README.md | Updates generated command documentation. |
| apps/cli/package.json | Declares the token command topic. |
| apps/cli/command-reference.json | Updates generated command reference. |
| apps/api/api/openapi/endpoints/users/me/personal_access_tokens/methods.yaml | Maps create and list commands. |
| apps/api/api/openapi/endpoints/users/me/personal_access_tokens/by_id/methods.yaml | Maps the revoke command. |
| apps/api/api/openapi/bundled/openapi.json | Updates bundled command mappings. |
| .changeset/cli-login-and-pats.md | Adds CLI release notes. |
Review effort: Balanced
| }); | ||
| } | ||
| const signIn = stored(authorization, clientId, answer.tokens, new Date()); | ||
| await this.store.write(this.server, signIn); |
| * @returns What was forgotten, and whether the server confirmed the revocation. | ||
| */ | ||
| async forget(): Promise<{ removed: StoredSignIn | undefined; revoked: boolean }> { | ||
| const removed = await this.store.remove(this.server); |
| ]; | ||
| // No browser opens from a spec: a sign-in link is only said. | ||
| const personal = ACTS_AS_A_PERSON.has(args[0] ?? "") | ||
| ? { XDG_CONFIG_HOME: await this.personalConfig(), BROWSER: "none" } |
main gained the session gates (#3552). Nothing here conflicts; the branch is level with main so that its checks run on what will land. 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
| init: Omit<RequestInit, "headers" | "signal"> & { headers?: Record<string, string> }, | ||
| signal: AbortSignal, | ||
| ): Promise<Response> { | ||
| return fetch(url, { |


Context
x-zitadel-self), beside thex-zitadel-clithis change adds: the commands here call them with the signed-in person's token, never a project secret.zitadel login.The
zitadelCLI had no sign-in: it works from the project secretzitadel setupwrites. A person could not act as themselves from a terminal, and could not create a personal access token for CI without a hand-made request.Summary
zitadel loginsigns a person in to a server with the OAuth code flow, PKCE and a loopback redirect, as the client whose document the platform issuer answers (feat(api): serve the CLI's client document on the platform issuer #3558). It prints the link, opens a browser unless--no-open, and waits up to--timeout(300 seconds by default), then fails withE_AUTH. The person always sees the consent step and picks the scopes.zitadel logoutdeletes the local sign-in and reportsrevoked: false: the server has no token revocation endpoint and no operation that ends a grant yet. The CLI will callrevocation_endpointonce the server's metadata lists one.zitadel personal-access-token create|list|revokeuse the stored sign-in.createnever asks for more scopes than the sign-in holds and refuses up front, naming the scopes held; it defaults to 30 days and allows at most 90;--jsonreturns the token once.claimannounces its link, which is silent under--json, so an agent runsloginwithout--jsonand relays the link to its person.SKILL.mdsays so.x-zitadel-cli), which the CLI's coverage test reads.Validation
Run by the session that wrote the change, in its cloud container:
login's specs stop at the link and the timeout. About 20 unit files fail in that container on a clean checkout too (prompt rendering); CI passes them.full-prwas green on the session's working branch at its last head (609f1eef1). This branch's tree is identical to that head's, checked withgit diffwhen the stack was cut.loginagainst a real server with a real browser.Checked when opening this draft:
node scripts/check-pr-title.mjs --title "…"passes. Rebuilt on main after its bases merged, without rewriting history: the diff against main is the same 44 files, line for line, as against the base it was opened on.embed dist/.turbo-restore-…: no such file or directory), a race in CI that also hit fix(api): name the field of a request body the API cannot read #3554 and has nothing to do with the change. The branch has since gained merges of its bases and of main, and one commit that takes the base's explanation of the three token operations out of the CLI's coverage test.Release notes / changeset
@zitadel/cli(minor):zitadel login,logoutandpersonal-access-token.Notes
personal_access_tokens.enabled), and the cloud launcher does not turn them on. Until someone does, the token commands answer 501 there.personal-access-token, notpat. The CLI's rules make a noun's plural equal the collection the API lists and allow no other alias, sopatcould not also answer topersonal-access-tokens. Root help widens to fit the longer name.login --jsonwaits as the terminal rendering does, instead of refusing at once: a fast refusal would end differently from the terminal rendering, which the CLI's every-rendering check forbids.logoutcan end the grant; the keychain;zitadel whoamionce a person's token can callgetMyUser(feat(api): let a person's token read who they are and which projects they can act on #3559).https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U
Generated by Claude Code