Repository navigation
feat(account): store the ID token on the identity - #13698
Merged
Merged
Conversation
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]>
Contributor
|
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
#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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
localeis 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 forhd,given_name/family_name, Apple'sis_private_email, and whatever a provider adds next.So keep the raw token on the identity and hand it back on the
Identitymodel, letting clients decode whatever they need.Changes
providerIdTokenonidentities, encrypted at rest with the sameencryptfilter as theproviderAccessTokenandproviderRefreshTokenbeside it. Sized 16384 to match them; theidTokenrequest param caps at 8192 characters, so there is room.V25creates the attribute alongsidephoto, via the samecreateAttributeFromCollectionpath and the same warn-on-failure handling.!empty($changes)guard on the update permanently true, so it goes away.providerIdTokenonIdentity.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 carryinglocale, then reads the identity back throughGET /account/identitiesand asserts the token is:providerIdToken;encryptfilter is lossless);sub,emailandnamematch, andlocaleisen: the claim Appwrite deliberately does not model, now readable by the client.It then signs in again with a token minted with
localeset tocsand asserts the stored token was replaced and decodes to the new value, covering the refresh path as well as the create path.The browser OAuth2 run confirms identities created without an ID token are unaffected.
composer lint,composer refactor:checkand PHPStan on the changed files all pass.Related PRs and Issues
Account/Http/Account/Sessions/IdTokenChecklist
Identitymodel gained a field, butapp/config/specs/is gitignored and no longer tracked (8d82bc89a1), so specs are regenerated and published separately.🤖 Generated with Claude Code