Skip to content

feat(auth): Add IdTokenResult and User::GetIdTokenResult support - #1938

Open
AustinBenoit wants to merge 3 commits into
mainfrom
feat/auth-id-token-claims
Open

AustinBenoit wants to merge 3 commits into
mainfrom
feat/auth-id-token-claims

Conversation

@AustinBenoit

Copy link
Copy Markdown
Contributor

Description

Provide details of the change, and generalize the change in the PR title above.

Adds IdTokenResult struct and User::GetIdTokenResult(bool force_refresh) to retrieve Firebase Auth ID token details, including standard claims, custom claims (std::map<Variant, Variant>), authentication/issued-at/expiration timestamps, and sign-in provider / second-factor metadata.

Key changes:

  • Added IdTokenResult struct and User::GetIdTokenResult(), User::GetIdTokenResultLastResult(), and User::GetIdTokenResultThreadSafe() to firebase/auth/user.h.
  • Desktop: Implemented User::GetIdTokenResult using EnsureFreshToken and a JWT payload decoder with URL-safe base64 decoding and JSON parsing into Variant maps.
  • Android: Implemented User::GetIdTokenResult via JNI calling FirebaseUser.getIdToken(forceRefresh).
  • iOS: Implemented User::GetIdTokenResult using [FIRUser getIDTokenResultWithCompletion:].
  • Added unit tests for JWT parsing, custom/standard claims extraction, and edge cases (IdTokenResultTest in auth/tests/id_token_result_test.cc and auth/tests/user_test.cc).
  • Added documentation sample in auth/samples/src/doc_samples.cc.
  • Updated release notes in release_build_files/readme.md.

Testing

Describe how you've tested these changes. Link any manually triggered Integration tests or CPP binary SDK Packaging Github Action workflows, if applicable.

  • Built firebase_auth desktop library locally.
  • Built and ran firebase_auth_id_token_result_test (12 unit test cases passing, covering valid tokens with standard & custom claims, base64url padding variants, malformed tokens, and equality operators).
  • Ran repository code formatting script (scripts/format_code.py -git_diff).

Type of Change

Place an x the applicable box:

  • Bug fix. Add the issue # below if applicable.
  • New feature. A non-breaking change which adds functionality.
  • Other, such as a build process or documentation change.

Notes

  • Bug fixes and feature changes require an update to the Release Notes section of release_build_files/readme.md.
  • Read the contribution guidelines CONTRIBUTING.md.
  • Changes to the public API require an internal API review. If you'd like to help us make Firebase APIs better, please propose your change in a feature request so that we can discuss it together.

Implements IdTokenResult struct and User::GetIdTokenResult(bool force_refresh)
with token parsing, custom claims extraction, and timestamp decoding.
Supports Desktop, Android, and iOS platforms. Adds comprehensive unit tests,
doc samples, and release notes.
Comment thread auth/src/include/firebase/auth/user.h
Comment thread auth/src/include/firebase/auth/user.h

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request adds the IdTokenResult struct and the User::GetIdTokenResult() method to retrieve decoded ID token claims and metadata across Desktop, Android, and iOS platforms. It also introduces JWT parsing utilities and comprehensive tests. The review feedback suggests explicitly deleting the local JNI reference j_token in the Android implementation to prevent reference table overflow, and logging warnings on Desktop if token parsing fails to assist with debugging.

Comment thread auth/src/android/user_android.cc Outdated
Comment thread auth/src/desktop/user_desktop.cc
Comment thread auth/src/desktop/user_desktop.cc
- Document IdTokenResult equality and inequality operators for Doxygen
- Include <map> in id_token_util.cc for IWYU compliance
- Delete local JNI reference j_token in ReadIdTokenResult
- Log warnings on Desktop if ParseIdToken fails for cached or refreshed tokens
- Use PRIu64 with cinttypes in doc_samples.cc instead of casting to unsigned long long
- Reformat single-line block in user_desktop_test.cc
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.

1 participant