[auth] Validate nonce claim in id_token after PKCE token exchange#276
Closed
partha-uber wants to merge 1 commit into
Closed
[auth] Validate nonce claim in id_token after PKCE token exchange#276partha-uber wants to merge 1 commit into
partha-uber wants to merge 1 commit into
Conversation
When a caller supplies a nonce via AuthContext, the SDK now validates the nonce claim in the returned id_token after PKCE token exchange. If the id_token is missing or the nonce claim does not match the sent value, authentication fails with INVALID_NONCE. When no nonce is supplied, validation is skipped (backward compatible). Matches the iOS SDK behavior from uber-ios-sdk PR #337. Co-Authored-By: Claude <noreply@anthropic.com>
941576b to
19259e7
Compare
Contributor
Author
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.
Summary
nonceviaAuthContext, the SDK now validates thenonceclaim in the returnedid_tokenafter PKCE token exchangeid_tokenis missing or the nonce claim does not match the sent value, authentication fails withINVALID_NONCEid_tokenfield toUberTokenresponse modelNonceUtil.extractNonceFromIdToken()to decode the JWT payload and extract the nonce claim (no signature verification, matching iOS approach)Addresses review feedback from #273 (comment)
Matches the iOS SDK behavior from uber/uber-ios-sdk#337 (OIDC Core §3.1.3.7)
Test plan
NonceUtilTest: nonce extraction from valid JWT, missing nonce, malformed JWT, two-segment token, invalid base64AuthProviderTest: PKCE with matching nonce succeeds, mismatched nonce returns error, missing id_token returns error, no nonce skips validation🤖 Generated with Claude Code
Co-Authored-By: Claude noreply@anthropic.com