Skip to content

Commit ec2c6ed

Browse files
authored
Added two new exceptions to CredentialsManager class (#939)
1 parent 10478a7 commit ec2c6ed

File tree

4 files changed

+43
-0
lines changed

4 files changed

+43
-0
lines changed

auth0/src/main/java/com/auth0/android/authentication/AuthenticationAPIClient.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ public class AuthenticationAPIClient @VisibleForTesting(otherwise = VisibleForTe
5555

5656
private var dPoP: DPoP? = null
5757

58+
/**
59+
* Returns whether DPoP (Demonstrating Proof of Possession) is enabled on this client.
60+
* DPoP is enabled by calling [useDPoP].
61+
*/
62+
public val isDPoPEnabled: Boolean
63+
get() = dPoP != null
64+
5865
/**
5966
* Creates a new API client instance providing Auth0 account info.
6067
*

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ public abstract class BaseCredentialsManager internal constructor(
2020
protected val storage: Storage,
2121
private val jwtDecoder: JWTDecoder
2222
) {
23+
24+
internal companion object {
25+
internal const val KEY_DPOP_THUMBPRINT = "com.auth0.dpop_key_thumbprint"
26+
}
2327
private var _clock: Clock = ClockImpl()
2428

2529
/**

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ public class CredentialsManagerException :
4848
API_ERROR,
4949
SSO_EXCHANGE_FAILED,
5050
MFA_REQUIRED,
51+
DPOP_KEY_MISSING,
52+
DPOP_NOT_CONFIGURED,
5153
UNKNOWN_ERROR
5254
}
5355

@@ -159,6 +161,11 @@ public class CredentialsManagerException :
159161
public val MFA_REQUIRED: CredentialsManagerException =
160162
CredentialsManagerException(Code.MFA_REQUIRED)
161163

164+
public val DPOP_KEY_MISSING: CredentialsManagerException =
165+
CredentialsManagerException(Code.DPOP_KEY_MISSING)
166+
public val DPOP_NOT_CONFIGURED: CredentialsManagerException =
167+
CredentialsManagerException(Code.DPOP_NOT_CONFIGURED)
168+
162169
public val UNKNOWN_ERROR: CredentialsManagerException = CredentialsManagerException(Code.UNKNOWN_ERROR)
163170

164171

@@ -207,6 +214,8 @@ public class CredentialsManagerException :
207214
Code.API_ERROR -> "An error occurred while processing the request."
208215
Code.SSO_EXCHANGE_FAILED ->"The exchange of the refresh token for SSO credentials failed."
209216
Code.MFA_REQUIRED -> "Multi-factor authentication is required to complete the credential renewal."
217+
Code.DPOP_KEY_MISSING -> "The stored credentials are DPoP-bound but the DPoP key pair is no longer available in the Android KeyStore. Re-authentication is required."
218+
Code.DPOP_NOT_CONFIGURED -> "The stored credentials are DPoP-bound but the AuthenticationAPIClient used by this CredentialsManager was not configured with useDPoP(context). Call AuthenticationAPIClient(auth0).useDPoP(context) and pass the configured client to CredentialsManager."
210219
Code.UNKNOWN_ERROR -> "An unknown error has occurred while fetching the token. Please check the error cause for more details."
211220
}
212221
}

auth0/src/main/java/com/auth0/android/dpop/DPoP.kt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,29 @@ public class DPoP(context: Context) {
198198
return HeaderData(token, proof)
199199
}
200200

201+
/**
202+
* Returns whether a DPoP key pair currently exists in the Android KeyStore.
203+
*
204+
* This can be used to check if DPoP credentials are still available after events
205+
* like device backup/restore or factory reset, which do not preserve KeyStore entries.
206+
*
207+
* ```kotlin
208+
*
209+
* if (!DPoP.hasKeyPair()) {
210+
* // Key was lost — clear stored credentials and re-authenticate
211+
* }
212+
*
213+
* ```
214+
*
215+
* @return true if a DPoP key pair exists in the KeyStore, false otherwise.
216+
* @throws DPoPException if there is an error accessing the KeyStore.
217+
*/
218+
@Throws(DPoPException::class)
219+
@JvmStatic
220+
public fun hasKeyPair(): Boolean {
221+
return DPoPUtil.hasKeyPair()
222+
}
223+
201224
/**
202225
* Method to clear the DPoP key pair from the keystore. It must be called when the user logs out
203226
* to prevent reuse of the key pair in subsequent sessions.

0 commit comments

Comments
 (0)