Add SSOCredentialsDeserializer for proper JSON deserialization of SSOCredentials#931
Add SSOCredentialsDeserializer for proper JSON deserialization of SSOCredentials#931pmathew92 merged 4 commits intov4_developmentfrom
Conversation
There was a problem hiding this comment.
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.expiresInfromInt(seconds) toDate(absolute expiration time) and update its KDoc. - Add
SSOCredentialsDeserializerand register it inGsonProviderto compute the expirationDatefromexpires_in. - Update unit tests, mocks, and the v4 migration guide to reflect the new
expiresIntype.
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.
| var expiresInDate: Date? = null | ||
| if (expiresIn != null) { | ||
| expiresInDate = Date(currentTimeInMillis + expiresIn * 1000) | ||
| } | ||
|
|
||
| return createSSOCredentials( | ||
| sessionTransferToken, | ||
| idToken, | ||
| issuedTokenType, | ||
| tokenType, | ||
| expiresInDate!!, |
There was a problem hiding this comment.
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.
| 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, |
| 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 |
There was a problem hiding this comment.
Unused imports JsonParseException and assertThrows will fail Kotlin compilation. Remove them (or add the intended negative test that uses them).
| 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 |
Changes
This PR changes the type of the
expiresInproperty of theSSOCredentialsclass from Int to Date to keep it consistent with other Credential classes in the code