Skip to content

Add SSOCredentialsDeserializer for proper JSON deserialization of SSOCredentials#931

Merged
pmathew92 merged 4 commits intov4_developmentfrom
SDK-7917
Mar 5, 2026
Merged

Add SSOCredentialsDeserializer for proper JSON deserialization of SSOCredentials#931
pmathew92 merged 4 commits intov4_developmentfrom
SDK-7917

Conversation

@pmathew92
Copy link
Contributor

@pmathew92 pmathew92 commented Mar 5, 2026

Changes

This PR changes the type of the expiresIn property of the SSOCredentials class from Int to Date to keep it consistent with other Credential classes in the code

@pmathew92 pmathew92 marked this pull request as ready for review March 5, 2026 08:21
@pmathew92 pmathew92 requested a review from a team as a code owner March 5, 2026 08:21
Copilot AI review requested due to automatic review settings March 5, 2026 08:21
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR aligns SSOCredentials.expiresIn with other credential models by representing expiration as an absolute Date, and introduces a Gson deserializer to convert the OAuth expires_in seconds value into that Date during JSON parsing.

Changes:

  • Change SSOCredentials.expiresIn from Int (seconds) to Date (absolute expiration time) and update its KDoc.
  • Add SSOCredentialsDeserializer and register it in GsonProvider to compute the expiration Date from expires_in.
  • Update unit tests, mocks, and the v4 migration guide to reflect the new expiresIn type.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
auth0/src/test/java/com/auth0/android/util/AuthenticationAPIMockServer.kt Adds a dedicated mock response for SSO exchange containing expires_in.
auth0/src/test/java/com/auth0/android/result/SSOCredentialsMock.kt Updates test factory to accept Date for expiresIn.
auth0/src/test/java/com/auth0/android/request/internal/SSOCredentialsDeserializerTest.kt Adds tests validating expires_in seconds are converted into an expiration Date.
auth0/src/test/java/com/auth0/android/request/internal/SSOCredentialsDeserializerMock.kt Provides a test double for controlling “current time” and object creation.
auth0/src/test/java/com/auth0/android/authentication/storage/SecureCredentialsManagerTest.kt Updates SSO-related assertions and mocks to use Date expiration.
auth0/src/test/java/com/auth0/android/authentication/storage/CredentialsManagerTest.kt Updates SSO-related assertions and mocks to use Date expiration.
auth0/src/test/java/com/auth0/android/authentication/AuthenticationAPIClientTest.kt Uses the new SSO exchange mock response in SSO tests.
auth0/src/main/java/com/auth0/android/result/SSOCredentials.kt Changes expiresIn to Date and updates documentation accordingly.
auth0/src/main/java/com/auth0/android/request/internal/SSOCredentialsDeserializer.kt Adds deserializer converting expires_in seconds into a Date.
auth0/src/main/java/com/auth0/android/request/internal/GsonProvider.kt Registers SSOCredentialsDeserializer for SSOCredentials.
V4_MIGRATION_GUIDE.md Documents the breaking change (expiresIn from Int to Date) and migration guidance.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +36 to +46
var expiresInDate: Date? = null
if (expiresIn != null) {
expiresInDate = Date(currentTimeInMillis + expiresIn * 1000)
}

return createSSOCredentials(
sessionTransferToken,
idToken,
issuedTokenType,
tokenType,
expiresInDate!!,
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

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

expiresInDate!! will throw a NullPointerException when expires_in is missing/null/invalid, which is harder to diagnose than a parse error. Treat expires_in as required and throw a JsonParseException with a clear message (or provide a fallback) instead of force-unwrapping.

Suggested change
var expiresInDate: Date? = null
if (expiresIn != null) {
expiresInDate = Date(currentTimeInMillis + expiresIn * 1000)
}
return createSSOCredentials(
sessionTransferToken,
idToken,
issuedTokenType,
tokenType,
expiresInDate!!,
if (expiresIn == null) {
throw JsonParseException("expires_in is required and must be a valid number of seconds")
}
val expiresInDate = Date(currentTimeInMillis + expiresIn * 1000)
return createSSOCredentials(
sessionTransferToken,
idToken,
issuedTokenType,
tokenType,
expiresInDate,

Copilot uses AI. Check for mistakes.
Comment on lines +6 to +11
import com.google.gson.JsonParseException
import org.hamcrest.CoreMatchers
import org.hamcrest.MatcherAssert
import org.hamcrest.Matchers
import org.hamcrest.core.Is
import org.junit.Assert.assertThrows
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

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

Unused imports JsonParseException and assertThrows will fail Kotlin compilation. Remove them (or add the intended negative test that uses them).

Suggested change
import com.google.gson.JsonParseException
import org.hamcrest.CoreMatchers
import org.hamcrest.MatcherAssert
import org.hamcrest.Matchers
import org.hamcrest.core.Is
import org.junit.Assert.assertThrows
import org.hamcrest.CoreMatchers
import org.hamcrest.MatcherAssert
import org.hamcrest.Matchers
import org.hamcrest.core.Is

Copilot uses AI. Check for mistakes.
@pmathew92 pmathew92 merged commit f424b01 into v4_development Mar 5, 2026
6 checks passed
@pmathew92 pmathew92 deleted the SDK-7917 branch March 5, 2026 10:24
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.

3 participants