-
Notifications
You must be signed in to change notification settings - Fork 167
Added two new exceptions to CredentialsManager class #939
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -20,6 +20,10 @@ public abstract class BaseCredentialsManager internal constructor( | |||||||
| protected val storage: Storage, | ||||||||
| private val jwtDecoder: JWTDecoder | ||||||||
| ) { | ||||||||
|
|
||||||||
| internal companion object { | ||||||||
| internal const val KEY_DPOP_THUMBPRINT = "com.auth0.dpop_key_thumbprint" | ||||||||
| } | ||||||||
|
Comment on lines
+24
to
+26
|
||||||||
| internal companion object { | |
| internal const val KEY_DPOP_THUMBPRINT = "com.auth0.dpop_key_thumbprint" | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will be updated in later PRs
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,6 +48,8 @@ public class CredentialsManagerException : | |
| API_ERROR, | ||
| SSO_EXCHANGE_FAILED, | ||
| MFA_REQUIRED, | ||
| DPOP_KEY_MISSING, | ||
| DPOP_NOT_CONFIGURED, | ||
| UNKNOWN_ERROR | ||
|
Comment on lines
48
to
53
|
||
| } | ||
|
|
||
|
|
@@ -159,6 +161,11 @@ public class CredentialsManagerException : | |
| public val MFA_REQUIRED: CredentialsManagerException = | ||
| CredentialsManagerException(Code.MFA_REQUIRED) | ||
|
|
||
| public val DPOP_KEY_MISSING: CredentialsManagerException = | ||
| CredentialsManagerException(Code.DPOP_KEY_MISSING) | ||
| public val DPOP_NOT_CONFIGURED: CredentialsManagerException = | ||
| CredentialsManagerException(Code.DPOP_NOT_CONFIGURED) | ||
|
|
||
| public val UNKNOWN_ERROR: CredentialsManagerException = CredentialsManagerException(Code.UNKNOWN_ERROR) | ||
|
|
||
|
|
||
|
|
@@ -207,6 +214,8 @@ public class CredentialsManagerException : | |
| Code.API_ERROR -> "An error occurred while processing the request." | ||
| Code.SSO_EXCHANGE_FAILED ->"The exchange of the refresh token for SSO credentials failed." | ||
pmathew92 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Code.MFA_REQUIRED -> "Multi-factor authentication is required to complete the credential renewal." | ||
| 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." | ||
| 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." | ||
| Code.UNKNOWN_ERROR -> "An unknown error has occurred while fetching the token. Please check the error cause for more details." | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -198,6 +198,29 @@ public class DPoP(context: Context) { | |
| return HeaderData(token, proof) | ||
| } | ||
|
|
||
| /** | ||
| * Returns whether a DPoP key pair currently exists in the Android KeyStore. | ||
| * | ||
| * This can be used to check if DPoP credentials are still available after events | ||
| * like device backup/restore or factory reset, which do not preserve KeyStore entries. | ||
| * | ||
| * ```kotlin | ||
| * | ||
| * if (!DPoP.hasKeyPair()) { | ||
| * // Key was lost — clear stored credentials and re-authenticate | ||
| * } | ||
| * | ||
| * ``` | ||
| * | ||
| * @return true if a DPoP key pair exists in the KeyStore, false otherwise. | ||
| * @throws DPoPException if there is an error accessing the KeyStore. | ||
| */ | ||
| @Throws(DPoPException::class) | ||
| @JvmStatic | ||
| public fun hasKeyPair(): Boolean { | ||
|
Comment on lines
+219
to
+220
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. DPoPUtil.hasKeyPair() it checks if the key exists, not if the key is usable. So that we can be sure the key is not corrupt or un usable.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We check the key is present or not . We will have another check to see if the key is usable or not in later PRs |
||
| return DPoPUtil.hasKeyPair() | ||
| } | ||
|
|
||
| /** | ||
| * Method to clear the DPoP key pair from the keystore. It must be called when the user logs out | ||
| * to prevent reuse of the key pair in subsequent sessions. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isDPoPEnabledis a new public API surface. There are already DPoP-related tests inAuthenticationAPIClientTest; consider adding a small assertion coveringisDPoPEnabled(false by default, true afteruseDPoP(context)) to prevent regressions.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will be updated in later PRs