Skip to content

Commit 91a2d1a

Browse files
committed
feat: Added option to pass AuthenticationAPIClient to SecureCredentialsManager class
1 parent ddb9db0 commit 91a2d1a

File tree

2 files changed

+79
-15
lines changed

2 files changed

+79
-15
lines changed

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,24 @@
11
package com.auth0.android.authentication.storage
22

33
import android.text.TextUtils
4-
import android.util.Base64
54
import android.util.Log
65
import androidx.annotation.VisibleForTesting
76
import com.auth0.android.authentication.AuthenticationAPIClient
87
import com.auth0.android.authentication.AuthenticationException
9-
import com.auth0.android.authentication.storage.SecureCredentialsManager.Companion.KEY_CREDENTIALS
108
import com.auth0.android.callback.Callback
119
import com.auth0.android.request.internal.GsonProvider
1210
import com.auth0.android.request.internal.Jwt
1311
import com.auth0.android.result.APICredentials
1412
import com.auth0.android.result.Credentials
15-
import com.auth0.android.result.OptionalCredentials
1613
import com.auth0.android.result.SSOCredentials
1714
import com.auth0.android.result.UserProfile
1815
import com.auth0.android.result.toAPICredentials
1916
import com.google.gson.Gson
2017
import kotlinx.coroutines.suspendCancellableCoroutine
21-
import java.util.*
18+
import java.util.Date
19+
import java.util.Locale
2220
import java.util.concurrent.Executor
2321
import java.util.concurrent.Executors
24-
import kotlin.collections.component1
25-
import kotlin.collections.component2
2622
import kotlin.coroutines.resume
2723
import kotlin.coroutines.resumeWithException
2824

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

Lines changed: 77 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,19 @@ import com.auth0.android.authentication.AuthenticationAPIClient
1111
import com.auth0.android.authentication.AuthenticationException
1212
import com.auth0.android.callback.Callback
1313
import com.auth0.android.request.internal.GsonProvider
14-
import com.auth0.android.request.internal.Jwt
1514
import com.auth0.android.result.APICredentials
1615
import com.auth0.android.result.Credentials
1716
import com.auth0.android.result.OptionalCredentials
1817
import com.auth0.android.result.SSOCredentials
1918
import com.auth0.android.result.UserProfile
2019
import com.auth0.android.result.toAPICredentials
2120
import com.google.gson.Gson
22-
import kotlinx.coroutines.CoroutineScope
23-
import kotlinx.coroutines.GlobalScope
24-
import kotlinx.coroutines.launch
2521
import kotlinx.coroutines.suspendCancellableCoroutine
2622
import java.lang.ref.WeakReference
27-
import java.util.*
23+
import java.util.Date
24+
import java.util.Locale
2825
import java.util.concurrent.Executor
2926
import java.util.concurrent.atomic.AtomicLong
30-
import kotlin.collections.component1
31-
import kotlin.collections.component2
3227
import kotlin.coroutines.resume
3328
import kotlin.coroutines.resumeWithException
3429

@@ -65,6 +60,34 @@ public class SecureCredentialsManager @VisibleForTesting(otherwise = VisibleForT
6560
storage: Storage,
6661
) : this(
6762
AuthenticationAPIClient(auth0),
63+
context,
64+
auth0,
65+
storage
66+
)
67+
68+
/**
69+
* Creates a new SecureCredentialsManager to handle Credentials with a custom AuthenticationAPIClient instance.
70+
* Use this constructor when you need to configure the API client with advanced features like DPoP.
71+
*
72+
* Example usage:
73+
* ```
74+
* val auth0 = Auth0.getInstance("YOUR_CLIENT_ID", "YOUR_DOMAIN")
75+
* val apiClient = AuthenticationAPIClient(auth0).useDPoP(context)
76+
* val manager = SecureCredentialsManager(apiClient, context, auth0, storage)
77+
* ```
78+
*
79+
* @param apiClient a configured AuthenticationAPIClient instance
80+
* @param context a valid context
81+
* @param auth0 the Auth0 account information to use
82+
* @param storage the storage implementation to use
83+
*/
84+
public constructor(
85+
apiClient: AuthenticationAPIClient,
86+
context: Context,
87+
auth0: Auth0,
88+
storage: Storage
89+
) : this(
90+
apiClient,
6891
storage,
6992
CryptoUtil(context, storage, KEY_ALIAS),
7093
JWTDecoder(),
@@ -89,6 +112,50 @@ public class SecureCredentialsManager @VisibleForTesting(otherwise = VisibleForT
89112
localAuthenticationOptions: LocalAuthenticationOptions
90113
) : this(
91114
AuthenticationAPIClient(auth0),
115+
context,
116+
auth0,
117+
storage,
118+
fragmentActivity,
119+
localAuthenticationOptions
120+
)
121+
122+
123+
/**
124+
* Creates a new SecureCredentialsManager to handle Credentials with biometrics Authentication
125+
* and a custom AuthenticationAPIClient instance.
126+
* Use this constructor when you need to configure the API client with advanced features like DPoP
127+
* along with biometric authentication.
128+
*
129+
* Example usage:
130+
* ```
131+
* val auth0 = Auth0.getInstance("YOUR_CLIENT_ID", "YOUR_DOMAIN")
132+
* val apiClient = AuthenticationAPIClient(auth0).useDPoP(context)
133+
* val manager = SecureCredentialsManager(
134+
* apiClient,
135+
* context,
136+
* auth0,
137+
* storage,
138+
* fragmentActivity,
139+
* localAuthenticationOptions
140+
* )
141+
* ```
142+
*
143+
* @param apiClient a configured AuthenticationAPIClient instance
144+
* @param context a valid context
145+
* @param auth0 the Auth0 account information to use
146+
* @param storage the storage implementation to use
147+
* @param fragmentActivity the FragmentActivity to use for the biometric authentication
148+
* @param localAuthenticationOptions the options of type [LocalAuthenticationOptions] to use for the biometric authentication
149+
*/
150+
public constructor(
151+
apiClient: AuthenticationAPIClient,
152+
context: Context,
153+
auth0: Auth0,
154+
storage: Storage,
155+
fragmentActivity: FragmentActivity,
156+
localAuthenticationOptions: LocalAuthenticationOptions
157+
) : this(
158+
apiClient,
92159
storage,
93160
CryptoUtil(context, storage, KEY_ALIAS),
94161
JWTDecoder(),
@@ -270,7 +337,7 @@ public class SecureCredentialsManager @VisibleForTesting(otherwise = VisibleForT
270337
if (credentials == null) {
271338
return null
272339
}
273-
return credentials.user
340+
return credentials.user
274341
}
275342

276343
/**
@@ -1138,7 +1205,7 @@ public class SecureCredentialsManager @VisibleForTesting(otherwise = VisibleForT
11381205
internal fun isBiometricSessionValid(): Boolean {
11391206
val lastAuth = lastBiometricAuthTime.get()
11401207
if (lastAuth == NO_SESSION) return false // No session exists
1141-
1208+
11421209
return when (val policy = biometricPolicy) {
11431210
is BiometricPolicy.Session,
11441211
is BiometricPolicy.AppLifecycle -> {
@@ -1149,6 +1216,7 @@ public class SecureCredentialsManager @VisibleForTesting(otherwise = VisibleForT
11491216
} * 1000L
11501217
System.currentTimeMillis() - lastAuth < timeoutMillis
11511218
}
1219+
11521220
is BiometricPolicy.Always -> false
11531221
}
11541222
}

0 commit comments

Comments
 (0)