Skip to content

[auth] Add id_token field to UberToken and validate nonce claim#274

Merged
partha-uber merged 9 commits into
sirker-auth-nonce-autogenfrom
sirker-auth-nonce-idtoken
Jun 25, 2026
Merged

[auth] Add id_token field to UberToken and validate nonce claim#274
partha-uber merged 9 commits into
sirker-auth-nonce-autogenfrom
sirker-auth-nonce-idtoken

Conversation

@partha-uber

@partha-uber partha-uber commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Summary

  • UberToken gains @Json(name = "id_token") val idToken: String? for
    OIDC id_token deserialization
  • AuthException.NONCE_MISMATCH constant added for replay-attack detection
  • performPkce validates the nonce claim in id_token against
    effectiveNonce; returns NONCE_MISMATCH error on mismatch
  • extractNonceFromIdToken decodes the JWT payload (base64url) and
    extracts the nonce claim via org.json.JSONObject — no extra libs
  • Validation is skipped when server returns no id_token (backward compat)

This is step 3/3 of iOS parity (PR #337 in uber-ios-sdk).

Test Plan

Issues

Stack

  1. [auth] Add state (CSRF) parameter to OAuth flow #272
  2. [auth] Auto-generate nonce when caller does not provide one #273
  3. @ [auth] Add id_token field to UberToken and validate nonce claim #274

Comment thread authentication/src/main/kotlin/com/uber/sdk2/auth/internal/AuthProvider.kt Outdated
partha-uber and others added 2 commits June 23, 2026 15:40
- Treat null state as a mismatch (a malicious callback omitting state
  should not bypass CSRF validation since the SDK always sends it)
- Replace em dash with plain hyphen in INVALID_STATE message

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
@partha-uber partha-uber marked this pull request as ready for review June 24, 2026 22:11
@partha-uber partha-uber requested a review from lalwani June 24, 2026 22:11
@@ -49,5 +49,11 @@ sealed class AuthException(override val message: String) : RuntimeException(mess
internal const val UNKNOWN = "Unknown error occurred"

internal const val INVALID_STATE = "State parameter mismatch — possible CSRF attack"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably didn't rebase? there's still a hyphen in the Invalid_state string

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rebased now.

partha-uber and others added 7 commits June 25, 2026 13:18
[auth] Add state (CSRF) parameter to OAuth flow
Summary:
- SDK now auto-generates a cryptographically secure `nonce` parameter
  (SecureRandom, 32 bytes, base64url) when `AuthContext.nonce` is null
- `effectiveNonce = authContext.nonce ?: generateSecureToken()` ensures
  nonce is always present in SSO query params for replay attack prevention
- Callers that supply their own nonce (for backend binding) are unaffected
- `@VisibleForTesting effectiveNonce` field exposed for assertions

This is step 2/3 of iOS parity (PR #337 in uber-ios-sdk).
Summary:
- Verify PKCE flow also forwards the auto-generated nonce
- Verify two different AuthProvider instances produce distinct nonces
  (randomness sanity check)
- Verify effectiveNonce field is stable on repeated reads
Summary:
- `UberToken` gains `@Json(name = "id_token") val idToken: String?` for
  OIDC id_token deserialization
- `AuthException.NONCE_MISMATCH` constant added for replay-attack detection
- `performPkce` validates the `nonce` claim in `id_token` against
  `effectiveNonce`; returns `NONCE_MISMATCH` error on mismatch
- `extractNonceFromIdToken` decodes the JWT payload (base64url) and
  extracts the `nonce` claim via `org.json.JSONObject` — no extra libs
- Validation is skipped when server returns no `id_token` (backward compat)

This is step 3/3 of iOS parity (PR #337 in uber-ios-sdk).
- extractNonceFromIdToken returning null now triggers ID_TOKEN_PARSE_FAILED
  instead of the misleading NONCE_MISMATCH error
- Use import for android.util.Base64 instead of fully qualified name
- Remove em dash from NONCE_MISMATCH message (plain ASCII)
- Add test for malformed id_token parse failure

Co-Authored-By: Claude <noreply@anthropic.com>
@partha-uber partha-uber force-pushed the sirker-auth-nonce-idtoken branch from e07fb86 to e6143e4 Compare June 25, 2026 22:00
@partha-uber partha-uber merged commit ef23990 into sirker-auth-nonce-autogen Jun 25, 2026
12 of 13 checks passed
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.

2 participants