Skip to content

feat(api): list a person's own sessions, with where each began - #3560

Merged
fforootd merged 12 commits into
mainfrom
claude/my-sessions
Dec 2, 2026
Merged

fforootd merged 12 commits into
mainfrom
claude/my-sessions

Conversation

@fforootd

@fforootd fforootd commented Dec 2, 2026 •

Copy link
Copy Markdown
Member

Context

Summary

  • New: listMySessions (GET /users/me/sessions) lists the signed-in person's own sessions in the project they signed in to, newest first, each with its state, the IP address and user agent it began with, and never its token. The answer is querySessions' shape (sessions, next_page_token), paged with limit and page_token.
  • Who reads it: the person's session cookie, or a token issued for them with session.read; without the scope 403 auth.scope_insufficient. It is held to the project it belongs to with project_id, as the other /users/me reads. A project secret is no person: 401, as a request without a credential, and no tool.
  • No Check: it is the session service's list with the caller's own user_id as its filter, so another user's session is never in it, whatever the person administers. querySessions and getSession stay as they are until §3.
  • session.read becomes a scope a person's token can use, so the consent screen words it ("View sessions and where each began", in en, de and it, in a "Sessions" group) and the MCP endpoint's metadata lists it.
  • MCP: one tool, 854 bytes. listBudget rises from 147,142 to 147,996, by that and no more. A person's token with every scope is shown 66 tools (89,366 bytes); with every .read scope, 49 (64,575), of which the eight /users/me reads are 5,996 bytes. A project secret is still shown 79.

Validation

Run by the session that wrote the change, in its cloud container:

  • go test ./internal/api/ ./internal/mcp/ passes, with listMySessions in TestAPersonsTokenReadsWhatIsTheirOwn, the self-service contract and TestPersonScopesHaveConsentTextsInTheConsole.
  • go test -tags sqlite_integration ./internal/api/integration_test/ ./internal/api/integration_test/helpers/ ./internal/bootstrap/platform/ passes. New TestAccessTokenListsThePersonsOwnSessions (the person's sessions, the one the token was issued in and another, and not a stranger's in the same project; no token in the answer); /users/me/sessions joins TestAccessTokenReadsWhatIsThePersonsOwn (token with and without the scope, the cookie, another project, a project secret) and the MCP subtests.
  • turbo run generate --filter=@zitadel/server and --filter=@zitadel/api; turbo run lint --filter=@zitadel/server (only the gofmt finding in an untouched file); turbo run typecheck --filter=@zitadel/docs; the CLI's operation.test.ts and api.spec.ts refusals.
  • Not run there: the Postgres and Spanner lanes. CI's full-pr runs Postgres. The Spanner lane (spanner.yml, Spanner Omni) is not one of a pull request's checks: it runs weekly on main and on dispatch, and has not run on this branch.
  • After CI's first run: the CLI's api-coverage and api ls tests, which enumerate the client's operations, were updated for the new operation.

Checked when opening this draft: node scripts/check-pr-title.mjs --title "…" passes. I did not rerun the suites.

Release notes / changeset

  • Changeset: .changeset/api-person-token.md (pending), extended with GET /users/me/sessions.

Notes

https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U


Generated by Claude Code

…they can act on

An agent signed in to the MCP endpoint as a person could not ask who it
acts for or which projects that person can work on: the /users/me reads
took only a session cookie (ADR 094 §6, step 1 of §12).

- getMyUser, listMyProjects, listMyTeams, getMyUserSchema,
  listMyPasskeys, listMyIdentityLinks and getMyPasswordState take a
  token issued for the person, each under the read scope of what it
  returns (user.read, project.read, team.read, schema.read). Without it
  the token is refused with 403 auth.scope_insufficient naming the scope.
  The token is held to its project as a session is (sess.project_mismatch).
- A project secret is no person: on these reads the API passes over it
  before looking at it, so it is answered exactly as before, as a request
  without a credential, and the MCP endpoint shows it none of their tools.
- The spec marks a person's own operations x-zitadel-self. The CLI, which
  holds a project secret, refuses them with a reason, and the docs' sample
  for their bearer branch is a person's token, never a project secret.
- Their tools take no project_id: that parameter holds a browser's session
  to the project of the app that sends the cookie, which a bearer never
  needs, and an agent would read it as the project to act on.
- The endpoint's instructions tell an agent signed in as a person to start
  with getMyUser, then listMyProjects.
- The tool list's budget grows by the seven tools' 5,142 bytes. A project
  secret is still shown 79 tools (141,563 bytes); a person's token with
  every scope 65 (88,512).
- The 403 of the seven is now an error with a code in the Go client, in
  place of SessProjectMismatch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmTvJjKuUM2VnUUGH9Y
GET /users/me/sessions (listMySessions) lists the signed-in person's own
sessions in the project they signed in to, newest first, each with its
state and the IP address and user agent it began with, never its token
(ADR 094 §6, the rest of step 1 of §12). It needs none of §2's session
type: its filter is the session's user_id, so no Check is asked and
another user's session is never in it.

- It takes the person's session cookie, or a token issued for them with
  session.read, held to its project with project_id as the other
  /users/me reads. A project secret is no person: 401, and no tool.
- session.read becomes a scope a person's token can use, so the consent
  screen words it in en, de and it, and the MCP endpoint's metadata
  lists it.
- One more tool, 854 bytes: listBudget rises to 147,996.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmTvJjKuUM2VnUUGH9Y
getMyUser now takes a person's token as well as their session, so the
CLI refuses it as an operation that reads the person who calls it; the
session-cookie-only case is pinned on updateMyUser.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmTvJjKuUM2VnUUGH9Y
@vercel

vercel Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
cloud Ready Ready Preview Dec 2, 2026 3:49pm UTC

Request Review

@github-actions

github-actions Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

🦋 Changeset detected

Latest commit: 2f7ef36

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 27 packages
Name Type
@zitadel/server Minor
@zitadel/api Minor
@zitadel/cli Minor
@zitadel/components Minor
@zitadel/config Minor
@zitadel/sdk-angular Minor
@zitadel/sdk-core Minor
@zitadel/sdk-next Minor
@zitadel/sdk-nuxt Minor
@zitadel/sdk-qwik Minor
@zitadel/sdk-react Minor
@zitadel/sdk-solid Minor
@zitadel/sdk-svelte Minor
@zitadel/sdk-tanstack-start Minor
@zitadel/sdk-vue Minor
@zitadel/testing Minor
@zitadel/cloud Patch
@zitadel/client-sdk-contract Patch
@zitadel/sdk-qwik-router Minor
@zitadel/sdk-solid-start Minor
@zitadel/sdk-sveltekit Minor
@zitadel/server-sdk-contract Patch
@zitadel/server-darwin-arm64 Minor
@zitadel/server-darwin-x64 Minor
@zitadel/server-linux-arm64 Minor
@zitadel/server-linux-x64 Minor
@zitadel/server-win32-x64 Minor

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

The page test keeps its own rule for which operations the CLI calls:
one that names no bearer scheme is a session's. A person's own read now
names one, for a person's token, but takes no project secret, which the
CLI holds, so the test reads x-zitadel-self as the docs' samples do.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmTvJjKuUM2VnUUGH9Y
…tests

The CLI holds a project secret and does not call a person's own
sessions, so the coverage test says why, beside the other /users/me
reads. In the spec's order /users/me/sessions now comes before
/sessions, which moves the first row api ls sessions prints.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmTvJjKuUM2VnUUGH9Y
@fforootd
fforootd marked this pull request as ready for review December 2, 2026 14:08
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
🔒 Security Review ✅ Completed 2026-12-02T14:14:26.790877Z e536f67 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

main replaced the one budget on the whole tool list with three checks
(#3555), so the raise this branch made to that budget goes. A person's
own reads fit them: 86 tools on a plain URL, and 50 tools, 66,412 bytes,
on the list a default consent yields. The tool-set tests expect the own
reads in the users set, and ADR 092's measured figures say so.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U
The base took main's three checks on the tool list in place of the one
budget, so the raise this branch made goes. listMySessions fits them:
87 tools on a plain URL, and 51 tools, 67,266 bytes, on the list a
default consent yields. The tool-set tests expect it in the users set,
and ADR 092's measured figures count it.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U
Base automatically changed from claude/my-reads-person-token to main December 2, 2026 15:34
main holds this branch's base as one squash commit (#3559). 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 the client secret's rotation (#3561) and the session type (#3551). The generated router conflicted, so the server's code is generated again from the merged spec. ADR 092's measured figures count rotation's tool: 88 on a plain URL.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are recorded for the self-service session-listing change.

No open issues 🎉

What changed in this PR

Adds listMySessions to Zitadel’s self-service API, extending the personal-token reads introduced in #3559 and completing ADR 094’s first implementation step.

Changes:

  • Lists the caller’s own sessions within their sign-in project, including origin details but no session tokens.
  • Adds the OpenAPI contract, generated Go support, and authentication and MCP coverage.
  • Updates consent translations, CLI expectations, documentation, and release notes.
File Description
packages/​go/​api/​oas_validators_gen.go Generates response-wrapper validation.
packages/​go/​api/​oas_security_gen.go Registers supported credentials and scope.
packages/​go/​api/​oas_schemas_gen.go Generates response and error types.
packages/​go/​api/​oas_response_decoders_gen.go Decodes endpoint responses.
packages/​go/​api/​oas_parameters_gen.go Adds pagination and project parameters.
packages/​go/​api/​oas_operations_gen.go Adds the operation constant.
packages/​go/​api/​oas_json_gen.go Generates error JSON serialization.
packages/​go/​api/​oas_interfaces_gen.go Adds the response interface.
packages/​go/​api/​oas_client_gen.go Adds the Go client method.
docs/​design/​api/​system-permission-catalog.md Documents self-access and its scope.
docs/​adrs/​094-project-permission-model.md Records completion of self-service session listing.
docs/​adrs/​092-mcp-server.md Updates tool documentation and counts.
apps/​console/​src/​features/​sign-in/​consent-texts.ts Adds session consent translations.
apps/​cli/​tests/​unit/​cli/​commands/​api/​ls.test.ts Updates operation-order expectations.
apps/​cli/​tests/​unit/​cli/​commands/​api-coverage.test.ts Records the person-only operation exclusion.
apps/​api/​internal/​mcp/​sets_test.go Includes session listing in user tool sets.
apps/​api/​internal/​api/​session.go Implements project- and user-filtered listing.
apps/​api/​internal/​api/​security.go Registers self-service authentication handling.
apps/​api/​internal/​api/​security_access_token_test.go Checks the required token scope.
apps/​api/​internal/​api/​integration_test/​mcp_test.go Checks tool exclusion for project secrets.
apps/​api/​internal/​api/​integration_test/​access_token_test.go Tests authentication, ownership, and token omission.
apps/​api/​internal/​api/​generated/​oas_validators_gen.go Generates server response validation.
apps/​api/​internal/​api/​generated/​oas_unimplemented_gen.go Adds the fallback handler.
apps/​api/​internal/​api/​generated/​oas_server_gen.go Extends the server handler interface.
apps/​api/​internal/​api/​generated/​oas_security_gen.go Generates endpoint security mappings.
apps/​api/​internal/​api/​generated/​oas_schemas_gen.go Generates server response and error types.
apps/​api/​internal/​api/​generated/​oas_router_gen.go Routes the new endpoint.
apps/​api/​internal/​api/​generated/​oas_response_encoders_gen.go Encodes responses and cache headers.
apps/​api/​internal/​api/​generated/​oas_parameters_gen.go Decodes and validates request parameters.
apps/​api/​internal/​api/​generated/​oas_operations_gen.go Adds the server operation constant.
apps/​api/​internal/​api/​generated/​oas_json_gen.go Generates server error serialization.
apps/​api/​internal/​api/​generated/​oas_interfaces_gen.go Adds the server response interface.
apps/​api/​internal/​api/​generated/​oas_handlers_gen.go Generates request handling.
apps/​api/​internal/​api/​authz_ungated_contract_internal_test.go Classifies the operation as self-service.
apps/​api/​api/​openapi/​openapi-spec.yaml Registers the endpoint specification.
apps/​api/​api/​openapi/​endpoints/​users/​me/​sessions/​methods.yaml Defines authentication, pagination, and responses.
apps/​api/​api/​openapi/​endpoints/​users/​me/​sessions/​listMySessions-error-response.yaml Generates the endpoint error catalog.
apps/​api/​api/​openapi/​bundled/​openapi.json Includes the new contract in the bundle.
.changeset/​api-person-token.md Adds session listing to release notes.

Review effort: Balanced

@fforootd
fforootd added this pull request to the merge queue Dec 2, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Dec 2, 2026
@fforootd
fforootd added this pull request to the merge queue Dec 2, 2026
Merged via the queue into main with commit c94713b Dec 2, 2026
18 checks passed
@fforootd
fforootd deleted the claude/my-sessions branch December 2, 2026 16:02
fforootd pushed a commit that referenced this pull request Dec 2, 2026
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
fforootd pushed a commit that referenced this pull request Dec 2, 2026
main gained a person's own sessions (#3560), which the permission catalog lists beside this branch's session relations: both stay on the session.read row.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U
fforootd pushed a commit that referenced this pull request Dec 2, 2026
main renumbered the migrations (#3551) and marks a person's own
operations x-zitadel-self (#3559, #3560). listMyConsents takes the mark
and a person's token with user.read; revokeMyConsent takes the mark and
stays with the session cookie, as revokeMySession does. Generated files
regenerated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmUEzNb3SNs7Rj5USYf
@github-project-automation github-project-automation Bot moved this from Inbox to Done in Engineering Kanban Dec 2, 2026

This branch was successfully deployed

1 active deployment
Preview — 2f7ef360 Deployed Dec 2, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants