Skip to content

feat(account): store the ID token on the identity - #13698

Merged
Meldiron merged 3 commits into
mainfrom
feat-identity-id-token
Sep 15, 2026
Merged

Meldiron merged 3 commits into
mainfrom
feat-identity-id-token

Conversation

@Meldiron

Copy link
Copy Markdown
Contributor

What does this PR do?

Native sign-in (POST /account/sessions/id-token) verifies a full OIDC ID token and then throws it away, keeping only the handful of claims the identity models (sub, email, name, picture). A client that wants anything else has no way to read it back short of another round trip to the provider.

Google's locale is the motivating case — useful for picking a UI language on first sign-in, but not worth a first-class attribute of its own. The same goes for hd, given_name/family_name, Apple's is_private_email, and whatever a provider adds next.

So keep the raw token on the identity and hand it back on the Identity model, letting clients decode whatever they need.

Changes

  • Schema — providerIdToken on identities, encrypted at rest with the same encrypt filter as the providerAccessToken and providerRefreshToken beside it. Sized 16384 to match them; the idToken request param caps at 8192 characters, so there is room.
  • Migration — V25 creates the attribute alongside photo, via the same createAttributeFromCollection path and the same warn-on-failure handling.
  • Write path — set on identity creation, and refreshed on every subsequent sign-in. The token is verified and required, so it always supersedes the stored one: it expires within the hour and its claims may have changed. This makes the !empty($changes) guard on the update permanently true, so it goes away.
  • Response model — providerIdToken on Identity.

Only the native flow stores one. The browser OAuth2 flow never receives an ID token, so identities it creates leave the attribute empty — which is why the model documents it as such.

Test Plan

New e2e test testCreateIdTokenSessionStoresIdToken, against the mock OAuth2 provider. It signs in with a Google-shaped token carrying locale, then reads the identity back through GET /account/identities and asserts the token is:

  1. stored — the identity carries a providerIdToken;
  2. the right value — equal to the minted token byte for byte, so the signature still verifies downstream (this also proves the round trip through the encrypt filter is lossless);
  3. decodable — a three-part JWT whose payload is valid base64url JSON;
  4. carrying the right claims — sub, email and name match, and locale is en: the claim Appwrite deliberately does not model, now readable by the client.

It then signs in again with a token minted with locale set to cs and asserts the stored token was replaced and decodes to the new value, covering the refresh path as well as the create path.

$ docker exec appwrite vendor/bin/phpunit --filter 'IdToken' \
    tests/e2e/Services/Account/AccountCustomClientTest.php
OK (18 tests, 240 assertions)

$ docker exec appwrite vendor/bin/phpunit --filter 'OAuth2' \
    tests/e2e/Services/Account/AccountCustomClientTest.php
OK (7 tests, 186 assertions)

The browser OAuth2 run confirms identities created without an ID token are unaffected. composer lint, composer refactor:check and PHPStan on the changed files all pass.

Related PRs and Issues

  • Builds on the native ID token sign-in flow in Account/Http/Account/Sessions/IdToken

Checklist

  • Have you read the Contributing Guidelines on issues?
  • If the PR includes a change to an API's metadata (desc, label, params, etc.), does it also include updated API specs and example docs? — the Identity model gained a field, but app/config/specs/ is gitignored and no longer tracked (8d82bc89a1), so specs are regenerated and published separately.

🤖 Generated with Claude Code

Native sign-in verifies a full OIDC ID token and then throws it away,
keeping only the handful of claims the identity models. Clients that want
anything else — Google's `locale`, say, which is useful for picking a UI
language but not worth an attribute of its own — have no way to read it
back short of another round trip to the provider.

Keep the raw token on the identity instead, and hand it back on the
Identity model so clients can decode whatever claims they need.

- `providerIdToken` on `identities`, encrypted at rest like the access
  and refresh tokens beside it, and sized to match. The ID token param
  caps at 8192 characters, so 16384 leaves room.
- V25 creates the attribute alongside `photo`, the same way.
- Written on identity creation and refreshed on every subsequent
  sign-in: the stored token expires within the hour and its claims may
  have changed since.

Only the native flow stores one. The browser OAuth2 flow never sees an
ID token, so its identities leave the attribute empty.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@greptile-apps

greptile-apps Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

The production behavior appears sound, but the explicit repository testing requirement must be satisfied before merging.

Fix All in Claude CodeFindings

  1. P2 Redundant JWT Fixture Assertions ▶
Fix with agent prompt
### Issue 1
tests/e2e/Services/Account/AccountCustomClientTest.php:6339-6345
These assertions manually decode the returned JWT and recheck claims supplied by `mintIdToken`. The preceding byte-for-byte equality assertion already proves that the entire token survived the API round trip, including its payload and signature. The extra decoding therefore retests the fixture and JWT format rather than another observable application behavior, violating the repository directive against implementation-coupled tests. The same pattern appears in the refreshed-token locale assertion and the `decodeJwtPayload` helper. This repository requirement must be satisfied before merging.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

This PR persists the verified native OIDC ID token on an identity, refreshes it during subsequent native sign-ins, and exposes it through the Identity response model.

  • Adds an encrypted, optional providerIdToken identity attribute and V25 migration handling.
  • Stores the raw token during identity creation and replacement.
  • Adds response-model metadata and end-to-end coverage for storage and refresh behavior.
  • The behavioral coverage is useful, but its redundant manual JWT decoding violates the repository’s testing rule.

Reviews (2) · Last reviewed commit: "fix(tests): decode the stored ID token p..."

Comment thread src/Appwrite/Migration/Version/V25.php Resolved
@github-actions

github-actions Bot commented Sep 15, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → feat-identity-id-token (after).

Metric Before After Change
🚀 Requests/sec 201.67 204.04 ⚪ +1.2%
⏱️ Latency P50 87.01 ms 86.12 ms ⚪ -1%
⏱️ Latency P95 199.19 ms 198.08 ms ⚪ -0.6%
Per-scenario breakdown & investigation details

Metrics below reflect the current branch (after). Δ P95 compares against the base.

Scenario P50 (ms) P95 (ms) Requests RPS Δ P95 (ms)
API total 86.12 198.08 12,540 204.04 -1.11
Account 163.01 292.88 660 11.42 -14.53
TablesDB 83.92 155 6,820 113.29 +2.86
Storage 77.79 168.94 3,300 56.69 +0.56
Functions 123.82 235.77 1,760 30.98 -1.23

Top API waits (after)

API request Max wait (ms)
account.name.update 464.63
functions.variables.update 438.18
storage.buckets.create 423.32
storage.files.create 418.82
functions.delete 409.39

@Meldiron Meldiron left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

lgtm

Meldiron and others added 2 commits September 15, 2026 11:29
#13697 landed the Google- and Apple-shaped claim tests on the same tail
of AccountCustomClientTest, which is the only conflict. Both sets of
tests are kept: main's two shape tests and its isMockOAuth2Photo helper,
followed by this branch's testCreateIdTokenSessionStoresIdToken and its
findMockIdentity / decodeJwtPayload helpers.

2.2.0 maps to V25 in Migration.php, so the providerIdToken attribute
stays in the migration it was added to.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
PHPStan flagged the assertion as dead: base64_decode() only returns false
in strict mode, so asserting the non-strict result is a string always
held. Decode strictly and assert against false, which also stops a
payload that is not really base64url from being silently scrubbed into
something that decodes to nothing.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@Meldiron
Meldiron merged commit 2977183 into main Sep 15, 2026
48 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants