Skip to content

Commit cfd3ba9

Browse files
committed
Handled review comments
1 parent bbe752d commit cfd3ba9

File tree

7 files changed

+86
-34
lines changed

7 files changed

+86
-34
lines changed

V4_MIGRATION_GUIDE.md

Lines changed: 78 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,30 @@
11
# Migration Guide from SDK v3 to v4
22

3-
## Overview
3+
> **Note:** This guide is actively maintained during the v4 development phase. As new changes are merged, this document will be updated to reflect the latest breaking changes and migration steps.
44
5-
v4 of the Auth0 Android SDK includes significant build toolchain updates to support the latest
6-
Android development environment. This guide documents the changes required when migrating from v3 to
7-
v4.
5+
v4 of the Auth0 Android SDK includes significant build toolchain updates, updated default values for better out-of-the-box behavior, and behavior changes to simplify credential management. This guide documents the changes required when migrating from v3 to v4.
6+
7+
---
8+
9+
## Table of Contents
10+
11+
- [**Requirements Changes**](#requirements-changes)
12+
+ [Java Version](#java-version)
13+
+ [Gradle and Android Gradle Plugin](#gradle-and-android-gradle-plugin)
14+
+ [Kotlin Version](#kotlin-version)
15+
- [**Breaking Changes**](#breaking-changes)
16+
+ [Classes Removed](#classes-removed)
17+
+ [DPoP Configuration Moved to Builder](#dpop-configuration-moved-to-builder)
18+
- [**Default Values Changed**](#default-values-changed)
19+
+ [Credentials Manager minTTL](#credentials-manager-minttl)
20+
- [**Behavior Changes**](#behavior-changes)
21+
+ [clearCredentials() Now Clears All Storage](#clearCredentials-now-clears-all-storage)
22+
+ [Storage Interface: New removeAll() Method](#storage-interface-new-removeall-method)
23+
- [**Dependency Changes**](#dependency-changes)
24+
+ [Gson 2.8.9 → 2.11.0](#️-gson-289--2110-transitive-dependency)
25+
+ [DefaultClient.Builder](#defaultclientbuilder)
26+
27+
---
828

929
## Requirements Changes
1030

@@ -103,6 +123,60 @@ WebAuthProvider
103123
This change ensures that DPoP configuration is scoped to individual login requests rather than
104124
persisting across the entire application lifecycle.
105125

126+
## Default Values Changed
127+
128+
### Credentials Manager `minTTL`
129+
130+
**Change:** The default `minTtl` value changed from `0` to `60` seconds.
131+
132+
This change affects the following Credentials Manager methods:
133+
134+
- `getCredentials(callback)` / `awaitCredentials()`
135+
- `getCredentials(scope, minTtl, callback)` / `awaitCredentials(scope, minTtl)`
136+
- `getCredentials(scope, minTtl, parameters, callback)` / `awaitCredentials(scope, minTtl, parameters)`
137+
- `getCredentials(scope, minTtl, parameters, forceRefresh, callback)` / `awaitCredentials(scope, minTtl, parameters, forceRefresh)`
138+
- `getCredentials(scope, minTtl, parameters, headers, forceRefresh, callback)` / `awaitCredentials(scope, minTtl, parameters, headers, forceRefresh)`
139+
- `hasValidCredentials()`
140+
141+
**Impact:** Credentials will be renewed if they expire within 60 seconds, instead of only when already expired.
142+
143+
<details>
144+
<summary>Migration example</summary>
145+
146+
```kotlin
147+
// v3 - minTtl defaulted to 0, had to be set explicitly
148+
credentialsManager.getCredentials(scope = null, minTtl = 60, callback = callback)
149+
150+
// v4 - minTtl defaults to 60 seconds
151+
credentialsManager.getCredentials(callback)
152+
153+
// v4 - use 0 to restore v3 behavior
154+
credentialsManager.getCredentials(scope = null, minTtl = 0, callback = callback)
155+
```
156+
</details>
157+
158+
**Reason:** A `minTtl` of `0` meant credentials were not renewed until expired, which could result in delivering access tokens that expire immediately after retrieval, causing subsequent API requests to fail. Setting a default value of `60` seconds ensures the access token remains valid for a reasonable period.
159+
160+
## Behavior Changes
161+
162+
### `clearCredentials()` Now Clears All Storage
163+
164+
**Change:** `clearCredentials()` now calls `Storage.removeAll()` instead of removing individual credential keys.
165+
166+
In v3, `clearCredentials()` removed only specific credential keys (access token, refresh token, ID token, etc.) from the underlying `Storage`.
167+
168+
In v4, `clearCredentials()` calls `Storage.removeAll()`, which clears **all** values in the storage — including any API credentials stored for specific audiences.
169+
170+
**Impact:** If you need to remove only the primary credentials while preserving other stored data, consider using a separate `Storage` instance for API credentials.
171+
172+
**Reason:** This simplifies credential cleanup and ensures no stale data remains in storage after logout. It aligns the behavior with the Swift SDK's `clear()` method, which also clears all stored values.
173+
174+
### `Storage` Interface: New `removeAll()` Method
175+
176+
**Change:** The `Storage` interface now includes a `removeAll()` method with a default empty implementation.
177+
178+
**Impact:** Existing custom `Storage` implementations will continue to compile and work without changes. Override `removeAll()` to provide the actual clearing behavior if your custom storage is used with `clearCredentials()`.
179+
106180
## Dependency Changes
107181

108182
### ⚠️ Gson 2.8.9 → 2.11.0 (Transitive Dependency)

auth0/src/main/java/com/auth0/android/authentication/storage/CredentialsManager.kt

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -727,13 +727,7 @@ public class CredentialsManager @VisibleForTesting(otherwise = VisibleForTesting
727727
* Removes the credentials from the storage if present.
728728
*/
729729
override fun clearCredentials() {
730-
storage.remove(KEY_ACCESS_TOKEN)
731-
storage.remove(KEY_REFRESH_TOKEN)
732-
storage.remove(KEY_ID_TOKEN)
733-
storage.remove(KEY_TOKEN_TYPE)
734-
storage.remove(KEY_EXPIRES_AT)
735-
storage.remove(KEY_SCOPE)
736-
storage.remove(LEGACY_KEY_CACHE_EXPIRES_AT)
730+
storage.removeAll()
737731
}
738732

739733
/**

auth0/src/main/java/com/auth0/android/authentication/storage/SecureCredentialsManager.kt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -754,10 +754,7 @@ public class SecureCredentialsManager @VisibleForTesting(otherwise = VisibleForT
754754
* Delete the stored credentials
755755
*/
756756
override fun clearCredentials() {
757-
storage.remove(KEY_CREDENTIALS)
758-
storage.remove(KEY_EXPIRES_AT)
759-
storage.remove(LEGACY_KEY_CACHE_EXPIRES_AT)
760-
storage.remove(KEY_CAN_REFRESH)
757+
storage.removeAll()
761758
clearBiometricSession()
762759
Log.d(TAG, "Credentials were just removed from the storage")
763760
}

auth0/src/main/java/com/auth0/android/authentication/storage/Storage.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,5 @@ public interface Storage {
7979
/**
8080
* Removes all values from the storage.
8181
*/
82-
public fun removeAll()
82+
public fun removeAll() {}
8383
}

auth0/src/test/java/com/auth0/android/authentication/storage/CredentialsManagerTest.kt

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1480,13 +1480,7 @@ public class CredentialsManagerTest {
14801480
@Test
14811481
public fun shouldClearCredentials() {
14821482
manager.clearCredentials()
1483-
verify(storage).remove("com.auth0.id_token")
1484-
verify(storage).remove("com.auth0.access_token")
1485-
verify(storage).remove("com.auth0.refresh_token")
1486-
verify(storage).remove("com.auth0.token_type")
1487-
verify(storage).remove("com.auth0.expires_at")
1488-
verify(storage).remove("com.auth0.scope")
1489-
verify(storage).remove("com.auth0.cache_expires_at")
1483+
verify(storage).removeAll()
14901484
verifyNoMoreInteractions(storage)
14911485
}
14921486

auth0/src/test/java/com/auth0/android/authentication/storage/SecureCredentialsManagerBiometricPolicyTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ public class SecureCredentialsManagerBiometricPolicyTest {
270270

271271
// Clear credentials
272272
manager.clearCredentials()
273-
verify(mockStorage, atLeastOnce()).remove(any())
273+
verify(mockStorage).removeAll()
274274

275275
// Session should be invalid
276276
assert(!manager.isBiometricSessionValid())

auth0/src/test/java/com/auth0/android/authentication/storage/SecureCredentialsManagerTest.kt

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -770,9 +770,7 @@ public class SecureCredentialsManagerTest {
770770
exception.message,
771771
Is.`is`("A change on the Lock Screen security settings have deemed the encryption keys invalid and have been recreated. Any previously stored content is now lost. Please try saving the credentials again.")
772772
)
773-
verify(storage).remove("com.auth0.credentials")
774-
verify(storage).remove("com.auth0.credentials_expires_at")
775-
verify(storage).remove("com.auth0.credentials_can_refresh")
773+
verify(storage).removeAll()
776774
}
777775

778776
@Test
@@ -867,9 +865,7 @@ public class SecureCredentialsManagerTest {
867865
"Any previously stored content is now lost. Please try saving the credentials again."
868866
)
869867
)
870-
verify(storage).remove("com.auth0.credentials")
871-
verify(storage).remove("com.auth0.credentials_expires_at")
872-
verify(storage).remove("com.auth0.credentials_can_refresh")
868+
verify(storage).removeAll()
873869
}
874870

875871
@Test
@@ -2153,10 +2149,7 @@ public class SecureCredentialsManagerTest {
21532149
@Test
21542150
public fun shouldClearCredentials() {
21552151
manager.clearCredentials()
2156-
verify(storage).remove("com.auth0.credentials")
2157-
verify(storage).remove("com.auth0.credentials_expires_at")
2158-
verify(storage).remove("com.auth0.credentials_access_token_expires_at")
2159-
verify(storage).remove("com.auth0.credentials_can_refresh")
2152+
verify(storage).removeAll()
21602153
verifyNoMoreInteractions(storage)
21612154
}
21622155

0 commit comments

Comments
 (0)