diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index d21b96de4..4dfe1a7e4 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -36,7 +36,7 @@ jobs: run: exit 0 # Skip unnecessary test runs for dependabot and merge queues. Artifically flag as successful, as this is a required check for branch protection. - name: Set up Java - uses: actions/setup-java@77dd5b2ce225ea11469928ac317850245a74ae78 # v6.2.0 + uses: actions/setup-java@d1374f8ac74474200d16ef8ecee22c7ae7a51880 # v6.3.0 with: distribution: 'temurin' java-version: '17' @@ -45,15 +45,15 @@ jobs: uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - name: Initialize CodeQL - uses: github/codeql-action/init@33d7b85da1a04171e211befe2c739303b9a4c066 # v4.39.3 + uses: github/codeql-action/init@915412ff23e8b7659517e607487dbeae018f2934 # v4.39.5 with: languages: ${{ matrix.language }} queries: +security-and-quality - name: Autobuild - uses: github/codeql-action/autobuild@33d7b85da1a04171e211befe2c739303b9a4c066 # v4.39.3 + uses: github/codeql-action/autobuild@915412ff23e8b7659517e607487dbeae018f2934 # v4.39.5 - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@33d7b85da1a04171e211befe2c739303b9a4c066 # v4.39.3 + uses: github/codeql-action/analyze@915412ff23e8b7659517e607487dbeae018f2934 # v4.39.5 with: category: "/language:${{ matrix.language }}" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 6036d5d45..deb7079de 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -33,7 +33,7 @@ jobs: echo "version=$version" >> $GITHUB_OUTPUT - name: Run RL Scanner - uses: auth0/devsecops-tooling/.github/actions/rl-scan@main + uses: auth0/devsecops-tooling/.github/actions/rl-scan@e29f26478db18ff0bcbe4bc447a8fbd54fbeec9e # main on 2026-11-27, TODO: use a release instead with: artifact-name: "auth0-android" artifact-path: "${{ github.workspace }}/auth0/build/outputs/aar/auth0-release.aar" diff --git a/.github/workflows/sca_scan.yml b/.github/workflows/sca_scan.yml index 9f7d29d6c..c6acbff0d 100644 --- a/.github/workflows/sca_scan.yml +++ b/.github/workflows/sca_scan.yml @@ -6,7 +6,7 @@ on: jobs: snyk-cli: - uses: auth0/devsecops-tooling/.github/workflows/sca-scan.yml@main + uses: auth0/devsecops-tooling/.github/workflows/sca-scan.yml@e29f26478db18ff0bcbe4bc447a8fbd54fbeec9e # main on 2026-11-27, TODO: use a release instead with: java-version: "17" additional-arguments: "--exclude=README.md,.jfrog" diff --git a/.github/workflows/scorecard.yml b/.github/workflows/scorecard.yml index 7b9a99e46..eeb3b679b 100644 --- a/.github/workflows/scorecard.yml +++ b/.github/workflows/scorecard.yml @@ -50,7 +50,7 @@ jobs: persist-credentials: false # required by Scorecard — do not remove - name: Run analysis - uses: ossf/scorecard-action@fa7117db83c52d787ae5a89f350999701505d78e # v2.5.0 + uses: ossf/scorecard-action@23f22cd43608bae7a1f1fa2603d7314dee9538a5 # v2.6.0 with: results_file: results.sarif results_format: sarif @@ -74,7 +74,7 @@ jobs: # token can write. (github.event.pull_request is null on push/schedule, so !…fork is true.) - name: Upload to code-scanning if: ${{ !github.event.pull_request.head.repo.fork }} - uses: github/codeql-action/upload-sarif@33d7b85da1a04171e211befe2c739303b9a4c066 # v4.39.3 + uses: github/codeql-action/upload-sarif@915412ff23e8b7659517e607487dbeae018f2934 # v4.39.5 with: sarif_file: results.sarif category: scorecard diff --git a/README.md b/README.md index d4fb0db53..1fe8575b0 100644 --- a/README.md +++ b/README.md @@ -316,6 +316,25 @@ WebAuthProvider.login(account) .await(this) ``` +### Experiment Center + +> [!NOTE] +> Experiment Center support via SDKs is currently in Early Access. To request access to this feature, contact your Auth0 representative. + +[Experiment Center](https://auth0.com/docs/customize/experiment-center/overview) is Auth0's A/B testing platform for authentication flows. Pass `experiment_id`, `variation_id`, and optionally `segment_id` via `withParameters()` to force a specific variation on a Web Auth login request: + +```kotlin +WebAuthProvider.login(account) + .withParameters(mapOf( + "experiment_id" to "", + "variation_id" to "", + "segment_id" to "" // optional + )) + .start(this, callback) +``` + +See the [full usage example](examples/experiment-center.md) for coroutine and Java samples. + ### My Account API: user profile [Beta] > [!NOTE] diff --git a/auth0/src/main/java/com/auth0/android/request/internal/DateTypeAdapter.kt b/auth0/src/main/java/com/auth0/android/request/internal/DateTypeAdapter.kt new file mode 100644 index 000000000..c94a70812 --- /dev/null +++ b/auth0/src/main/java/com/auth0/android/request/internal/DateTypeAdapter.kt @@ -0,0 +1,70 @@ +package com.auth0.android.request.internal + +import com.google.gson.JsonSyntaxException +import com.google.gson.TypeAdapter +import com.google.gson.stream.JsonReader +import com.google.gson.stream.JsonToken +import com.google.gson.stream.JsonWriter +import java.text.ParseException +import java.text.SimpleDateFormat +import java.util.* + +/** + * Writes dates in UTC with an explicit offset so they survive DST transitions and device + * time zone changes. Dates written by older SDK versions (device local time with a literal + * 'Z' suffix) are still read as local time to preserve their original meaning. Such a value + * inside a repeated DST hour is ambiguous and reads one hour late until it is saved again. + * + * Only meant for dates the SDK persists itself (e.g. stored credentials): any value ending in + * 'Z' is treated as that legacy local-time format, not as UTC. + * + * @param legacyTimeZone zone used to read legacy values. Captured once, like the formatter + * previously configured via `GsonBuilder.setDateFormat`, so a legacy value resolves to the same + * instant for the lifetime of the adapter even if the device time zone changes. + */ +internal class DateTypeAdapter( + private val legacyTimeZone: TimeZone = TimeZone.getDefault() +) : TypeAdapter() { + + override fun write(out: JsonWriter, value: Date?) { + if (value == null) { + out.nullValue() + return + } + out.value(format(value)) + } + + override fun read(reader: JsonReader): Date? { + if (reader.peek() == JsonToken.NULL) { + reader.nextNull() + return null + } + val value = reader.nextString() + return try { + parse(value) + } catch (e: ParseException) { + throw JsonSyntaxException("Failed parsing '$value' as Date", e) + } + } + + @Throws(ParseException::class) + private fun parse(value: String): Date { + if (value.endsWith("Z")) { + val legacyFormatter = SimpleDateFormat(LEGACY_DATE_FORMAT, Locale.US) + legacyFormatter.timeZone = legacyTimeZone + return legacyFormatter.parse(value) + } + return SimpleDateFormat(DATE_FORMAT, Locale.US).parse(value) + } + + internal companion object { + private const val DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSSZ" + private const val LEGACY_DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" + + fun format(date: Date): String { + val formatter = SimpleDateFormat(DATE_FORMAT, Locale.US) + formatter.timeZone = TimeZone.getTimeZone("UTC") + return formatter.format(date) + } + } +} diff --git a/auth0/src/main/java/com/auth0/android/request/internal/GsonProvider.kt b/auth0/src/main/java/com/auth0/android/request/internal/GsonProvider.kt index a927a89dd..a6301d3ec 100755 --- a/auth0/src/main/java/com/auth0/android/request/internal/GsonProvider.kt +++ b/auth0/src/main/java/com/auth0/android/request/internal/GsonProvider.kt @@ -8,13 +8,10 @@ import com.google.gson.Gson import com.google.gson.GsonBuilder import com.google.gson.reflect.TypeToken import java.security.PublicKey -import java.text.SimpleDateFormat import java.util.* internal object GsonProvider { internal val gson: Gson - private var sdf: SimpleDateFormat - private const val DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" init { val jwksType = TypeToken.getParameterized( @@ -28,14 +25,13 @@ internal object GsonProvider { .registerTypeAdapter(Credentials::class.java, CredentialsDeserializer()) .registerTypeAdapter(SSOCredentials::class.java, SSOCredentialsDeserializer()) .registerTypeAdapter(jwksType, JwksDeserializer()) - .setDateFormat(DATE_FORMAT) + .registerTypeAdapter(Date::class.java, DateTypeAdapter()) .create() - sdf = SimpleDateFormat(DATE_FORMAT, Locale.US) } @JvmStatic @VisibleForTesting fun formatDate(date: Date): String { - return sdf.format(date) + return DateTypeAdapter.format(date) } -} \ No newline at end of file +} diff --git a/auth0/src/test/java/com/auth0/android/request/internal/DateTypeAdapterTest.kt b/auth0/src/test/java/com/auth0/android/request/internal/DateTypeAdapterTest.kt new file mode 100644 index 000000000..d4b17de58 --- /dev/null +++ b/auth0/src/test/java/com/auth0/android/request/internal/DateTypeAdapterTest.kt @@ -0,0 +1,132 @@ +package com.auth0.android.request.internal + +import com.auth0.android.result.APICredentials +import com.auth0.android.result.Credentials +import com.auth0.android.result.CredentialsMock +import com.google.gson.Gson +import com.google.gson.GsonBuilder +import com.google.gson.JsonSyntaxException +import org.hamcrest.MatcherAssert.assertThat +import org.hamcrest.Matchers.`is` +import org.hamcrest.Matchers.nullValue +import org.junit.After +import org.junit.Assert +import org.junit.Before +import org.junit.Test +import java.util.* + +public class DateTypeAdapterTest { + + private lateinit var gson: Gson + private lateinit var defaultTimeZone: TimeZone + + @Before + public fun setUp() { + defaultTimeZone = TimeZone.getDefault() + TimeZone.setDefault(TimeZone.getTimeZone("Europe/Amsterdam")) + gson = GsonProvider.gson + } + + @After + public fun tearDown() { + TimeZone.setDefault(defaultTimeZone) + } + + @Test + public fun shouldWriteDateInUtcWithExplicitOffset() { + // 2026-10-25T00:35:16Z, which is 02:35:16 CEST in Amsterdam + assertThat(gson.toJson(Date(DST_REPEATED_HOUR_MS)), `is`("\"2026-10-25T00:35:16.000+0000\"")) + } + + @Test + public fun shouldRoundTripDateInsideRepeatedDstHour() { + val date = Date(DST_REPEATED_HOUR_MS) + val parsed = gson.fromJson(gson.toJson(date), Date::class.java) + assertThat(parsed, `is`(date)) + } + + @Test + public fun shouldRoundTripDateAcrossTimeZoneChange() { + val date = Date(DST_REPEATED_HOUR_MS) + TimeZone.setDefault(TimeZone.getTimeZone("Asia/Kolkata")) + val json = gson.toJson(date) + TimeZone.setDefault(TimeZone.getTimeZone("America/New_York")) + assertThat(gson.fromJson(json, Date::class.java), `is`(date)) + } + + @Test + public fun shouldReadLegacyFormatAsLocalTime() { + // Older SDK versions wrote local wall-clock time followed by a literal 'Z'. + // 2026-10-24T12:00 CEST is 10:00 UTC. + val parsed = gsonWithAdapter(DateTypeAdapter(AMSTERDAM)) + .fromJson("\"2026-10-24T12:00:00.000Z\"", Date::class.java) + assertThat(parsed, `is`(Date(1792836000000L))) + } + + @Test + public fun shouldKeepReadingLegacyFormatInCapturedZoneAfterDefaultZoneChange() { + // Adapter created while the default zone is Europe/Amsterdam (see setUp) + val adapterGson = gsonWithAdapter(DateTypeAdapter()) + val before = adapterGson.fromJson("\"2026-10-24T12:00:00.000Z\"", Date::class.java) + TimeZone.setDefault(TimeZone.getTimeZone("America/New_York")) + val after = adapterGson.fromJson("\"2026-10-24T12:00:00.000Z\"", Date::class.java) + assertThat(before, `is`(Date(1792836000000L))) + assertThat(after, `is`(before)) + } + + @Test + public fun shouldReadLegacyValueInsideRepeatedDstHourOneHourLate() { + // Known limitation: the legacy format never stored the offset, so a local time in the + // repeated hour resolves to its second occurrence (CET), one hour after the real instant. + // It is corrected the next time the value is saved in the new format. + val parsed = gsonWithAdapter(DateTypeAdapter(AMSTERDAM)) + .fromJson("\"2026-10-25T02:35:16.000Z\"", Date::class.java) + assertThat(parsed, `is`(Date(DST_REPEATED_HOUR_MS + ONE_HOUR_MS))) + } + + @Test + public fun shouldReadDateWithNonUtcOffset() { + val parsed = gson.fromJson("\"2026-10-25T03:35:16.000+0300\"", Date::class.java) + assertThat(parsed, `is`(Date(DST_REPEATED_HOUR_MS))) + } + + @Test + public fun shouldReadAndWriteNull() { + assertThat(gson.fromJson("null", Date::class.java), `is`(nullValue())) + assertThat(gson.toJson(null, Date::class.java), `is`("null")) + } + + @Test + public fun shouldFailOnInvalidDate() { + Assert.assertThrows(JsonSyntaxException::class.java) { + gson.fromJson("\"not-a-date\"", Date::class.java) + } + } + + @Test + public fun shouldRoundTripCredentialsExpiresAtInsideRepeatedDstHour() { + val expiresAt = Date(DST_REPEATED_HOUR_MS) + val credentials: Credentials = + CredentialsMock.create("id", "access", "bearer", "refresh", expiresAt, "openid") + val parsed = gson.fromJson(gson.toJson(credentials), Credentials::class.java) + assertThat(parsed.expiresAt, `is`(expiresAt)) + } + + @Test + public fun shouldRoundTripApiCredentialsExpiresAtInsideRepeatedDstHour() { + val expiresAt = Date(DST_REPEATED_HOUR_MS) + val apiCredentials = APICredentials("access", "bearer", expiresAt, "read:data") + val parsed = gson.fromJson(gson.toJson(apiCredentials), APICredentials::class.java) + assertThat(parsed.expiresAt, `is`(expiresAt)) + } + + private fun gsonWithAdapter(adapter: DateTypeAdapter): Gson = + GsonBuilder().registerTypeAdapter(Date::class.java, adapter).create() + + private companion object { + // 2026-10-25T00:35:16Z: inside the first occurrence of the repeated 02:00-03:00 hour in Europe/Amsterdam + private const val DST_REPEATED_HOUR_MS = 1792888516000L + private const val ONE_HOUR_MS = 3600000L + private val AMSTERDAM: TimeZone = TimeZone.getTimeZone("Europe/Amsterdam") + } +} diff --git a/build.gradle b/build.gradle index eac37a087..efc76fd28 100644 --- a/build.gradle +++ b/build.gradle @@ -13,7 +13,7 @@ buildscript { } plugins { - id 'org.jetbrains.dokka' version '1.9.20' + id 'org.jetbrains.dokka' version '2.3.0' id 'io.github.gradle-nexus.publish-plugin' version '2.0.0' } @@ -44,8 +44,8 @@ allprojects { } // Patch vulnerable transitive deps to clear the reported CVEs. Pulled in by test - // tooling (netty-codec-http via AGP/grpc-netty, bcprov-jdk18on via Robolectric); - // not included in the published AAR. + // tooling (netty-codec-http via AGP/grpc-netty, bcprov-jdk18on via Robolectric) + // and doc tooling (jackson-* via Dokka); not included in the published AAR. configurations.configureEach { resolutionStrategy.eachDependency { details -> if (details.requested.group == 'io.netty' && details.requested.name == 'netty-codec-http') { @@ -54,6 +54,11 @@ allprojects { if (details.requested.group == 'org.bouncycastle' && details.requested.name == 'bcprov-jdk18on') { details.useVersion '1.85' } + // Keep Jackson modules aligned on the patched release. jackson-annotations is + // published with a minor-only version since 2.20, so leave it as Dokka requests it. + if (details.requested.group.startsWith('com.fasterxml.jackson') && details.requested.name != 'jackson-annotations') { + details.useVersion '2.22.4' + } } } } diff --git a/gradle/maven-publish.gradle b/gradle/maven-publish.gradle index 4575f9a1a..225f706cd 100644 --- a/gradle/maven-publish.gradle +++ b/gradle/maven-publish.gradle @@ -4,9 +4,9 @@ apply plugin: 'signing' apply from: rootProject.file('gradle/versioning.gradle') -task javadocJar(type: Jar, dependsOn: dokkaHtml) { +task javadocJar(type: Jar) { archiveClassifier = "javadoc" - from dokkaHtml.outputDirectory + from tasks.named('dokkaGeneratePublicationHtml').flatMap { it.outputDirectory } } task sourcesJar(type: Jar) {