Repository navigation
[AppCheck] Populate iOS TokenChanged expiration from the JWT exp claim - #1961
Merged
Merged
Conversation
- Default-initialize AppCheckToken::expire_time_millis to 0 so default-constructed tokens never hold uninitialized memory, and document that 0 means the expiration time is unknown.
- Add AppCheckTokenFromJwt(std::string_view) in app_check/src/common/jwt_util.{h,cc} using Base64Decode + FlatBuffers FlexBuffers to extract the numeric "exp" claim into milliseconds. An exp that is not positive, or is later than 9999-12-31T23:59:59Z, is treated as unknown.
- Use AppCheckTokenFromJwt in -[AppCheckNotificationCenterWrapper appCheckTokenDidChangeNotification:] on iOS (firebase/firebase-unity-sdk#1556).
- Add unit tests in app_check/tests/jwt_util_test.cc and assert positive expire_time_millis in TestAddTokenChangedListener.
Contributor
There was a problem hiding this comment.
Code Review
This pull request introduces JWT utility functions to parse the expiration time (exp claim) from Firebase App Check tokens on iOS and tvOS. It default-initializes AppCheckToken::expire_time_millis to 0 and populates it using the new AppCheckTokenFromJwt helper during token change notifications on iOS, resolving an ArgumentOutOfRangeException crash in Unity. Additionally, comprehensive unit tests for the JWT utility have been added, and the release notes have been updated. I have no feedback to provide as there are no review comments.
TestAddTokenChangedListener now asserts that the expiration delivered to a token-changed listener matches the expiration GetAppCheckToken returns for the same token, within five minutes. On iOS and tvOS the two come from different clocks (JWT exp vs local request time plus TTL), so they are not expected to be identical.
✅ Integration test succeeded!Requested by @AustinBenoit on commit 770677d |
On desktop and Android the token-changed listener and GetAppCheckToken receive the same token, so TestAddTokenChangedListener now requires their expirations to be identical there. iOS and tvOS keep the five-minute tolerance, since the two values come from different clocks.
AustinBenoit
marked this pull request as ready for review
November 10, 2026 19:14
a-maurice
approved these changes
Nov 11, 2026
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.
Description
On iOS,
AppCheckListener::OnAppCheckTokenChangedreceived anAppCheckTokenwhoseexpire_time_milliswas never set, because theFIRAppChecktoken-change notification carries only the token string. The field also had no default value, so listeners read an uninitialized value. The Unity SDK converts that value to aDateTime, which can throwArgumentOutOfRangeExceptioninside theTokenChangedcallback (firebase/firebase-unity-sdk#1556).This change:
AppCheckToken::expire_time_millisto0and documents0as "expiration time unknown".AppCheckTokenFromJwt, that reads theexpclaim from the token's JWT payload using the Base64 and FlatBuffers code already built intofirebase_app. If the token is not a JWT with a validexp(positive, and no later than 9999-12-31T23:59:59Z), the expiration stays0.TestAddTokenChangedListenerintegration test to compare the listener's expiration with the oneGetAppCheckTokenreturns for the same token. On desktop and Android the two must be identical. On iOS and tvOS they must agree within five minutes: the listener's value comes from the JWTexp(server clock), whileGetAppCheckToken's is the local request time plus the token's TTL.Android and desktop behavior is unchanged; they already pass an expiration to token-changed listeners.
Testing
firebase_app_checkand the newfirebase_app_check_jwt_util_teston Linux desktop (Debug, with ASan and UBSan). The unit tests pass.tests-requested: quickon the current head (686b2d5) and all jobs passed: https://github.com/firebase/firebase-cpp-sdk/actions/runs/42869609104.TestAddTokenChangedListenerpassed on desktop (Linux, Windows), Android (device and emulator), iOS (real device and simulator) and the tvOS simulator.Type of Change
Place an
xthe applicable box:Related to firebase/firebase-unity-sdk#1556. Unity users get the fix once the Unity SDK builds against a C++ SDK release that includes this change.
Notes
Release Notessection ofrelease_build_files/readme.md.