Skip to content

[auth] Validate nonce claim in id_token after PKCE token exchange#276

Closed
partha-uber wants to merge 1 commit into
mainfrom
sirker-nonce-validation
Closed

[auth] Validate nonce claim in id_token after PKCE token exchange#276
partha-uber wants to merge 1 commit into
mainfrom
sirker-nonce-validation

Conversation

@partha-uber

Copy link
Copy Markdown
Contributor

Summary

  • 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)
  • Adds id_token field to UberToken response model
  • Adds NonceUtil.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 base64
  • AuthProviderTest: PKCE with matching nonce succeeds, mismatched nonce returns error, missing id_token returns error, no nonce skips validation
  • All existing tests pass
  • CI green

🤖 Generated with Claude Code

Co-Authored-By: Claude noreply@anthropic.com

@partha-uber partha-uber requested a review from lalwani June 24, 2026 20:09
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>
@partha-uber partha-uber force-pushed the sirker-nonce-validation branch from 941576b to 19259e7 Compare June 26, 2026 05:10
@partha-uber

Copy link
Copy Markdown
Contributor Author

Splitting into two smaller PRs: #277 (NonceUtil + UberToken.idToken) and #278 (PKCE nonce validation). Each is under 120 diff lines.

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