-
public final class SecureCredentialsManager extends BaseCredentialsManager
A safer alternative to the CredentialsManager class. A combination of RSA and AES keys is used to keep the values secure. On devices with a Secure LockScreen configured (PIN, Pattern, Password or Fingerprint) an extra authentication step can be required.
-
-
Constructor Summary
Constructors Constructor Description SecureCredentialsManager(Context context, AuthenticationAPIClient apiClient, Storage storage)
Creates a new SecureCredentialsManager to handle Credentials
-
Method Summary
Modifier and Type Method Description final Boolean
requireAuthentication(Activity activity, Integer requestCode, String title, String description)
Require the user to authenticate using the configured LockScreen before accessing the credentials. final Boolean
checkAuthenticationResult(Integer requestCode, Integer resultCode)
Checks the result after showing the LockScreen to the user. Unit
saveCredentials(Credentials credentials)
Saves the given credentials in the Storage. Unit
getCredentials(Callback<Credentials, CredentialsManagerException> callback)
Tries to obtain the credentials from the Storage. Unit
getCredentials(String scope, Integer minTtl, Callback<Credentials, CredentialsManagerException> callback)
Tries to obtain the credentials from the Storage. Unit
clearCredentials()
Delete the stored credentials Boolean
hasValidCredentials()
Returns whether this manager contains a valid non-expired pair of credentials. Boolean
hasValidCredentials(Long minTtl)
Returns whether this manager contains a valid non-expired pair of credentials. -
Methods inherited from class com.auth0.android.authentication.storage.SecureCredentialsManager
setClock
-
Methods inherited from class com.auth0.android.authentication.storage.BaseCredentialsManager
equals, hashCode, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Constructor Detail
-
SecureCredentialsManager
SecureCredentialsManager(Context context, AuthenticationAPIClient apiClient, Storage storage)
Creates a new SecureCredentialsManager to handle Credentials- Parameters:
context
- a valid contextapiClient
- the Auth0 Authentication API Client to handle token refreshment when needed.storage
- the storage implementation to use
-
-
Method Detail
-
requireAuthentication
final Boolean requireAuthentication(Activity activity, Integer requestCode, String title, String description)
Require the user to authenticate using the configured LockScreen before accessing the credentials. This feature is disabled by default and will only work if the device is running on Android version 21 or up and if the user has configured a secure LockScreen (PIN, Pattern, Password or Fingerprint).
The activity passed as first argument here must override the Activity.onActivityResult method and call SecureCredentialsManager.checkAuthenticationResult with the received parameters.
- Parameters:
activity
- a valid activity context.requestCode
- the request code to use in the authentication request.title
- the text to use as title in the authentication screen.description
- the text to use as description in the authentication screen.
-
checkAuthenticationResult
final Boolean checkAuthenticationResult(Integer requestCode, Integer resultCode)
Checks the result after showing the LockScreen to the user. Must be called from the Activity.onActivityResult method with the received parameters. It's safe to call this method even if SecureCredentialsManager.requireAuthentication was unsuccessful.
- Parameters:
requestCode
- the request code received in the onActivityResult call.resultCode
- the result code received in the onActivityResult call.
-
saveCredentials
Unit saveCredentials(Credentials credentials)
Saves the given credentials in the Storage.
- Parameters:
credentials
- the credentials to save.
-
getCredentials
Unit getCredentials(Callback<Credentials, CredentialsManagerException> callback)
Tries to obtain the credentials from the Storage. The callback's Callback.onSuccess method will be called with the result. If something unexpected happens, the Callback.onFailure method will be called with the error. Some devices are not compatible at all with the cryptographic implementation and will have CredentialsManagerException.isDeviceIncompatible return true.
If a LockScreen is setup and .requireAuthentication was called, the user will be asked to authenticate before accessing the credentials. Your activity must override the Activity.onActivityResult method and call .checkAuthenticationResult with the received values.
- Parameters:
callback
- the callback to receive the result in.
-
getCredentials
Unit getCredentials(String scope, Integer minTtl, Callback<Credentials, CredentialsManagerException> callback)
Tries to obtain the credentials from the Storage. The callback's Callback.onSuccess method will be called with the result. If something unexpected happens, the Callback.onFailure method will be called with the error. Some devices are not compatible at all with the cryptographic implementation and will have CredentialsManagerException.isDeviceIncompatible return true.
If a LockScreen is setup and .requireAuthentication was called, the user will be asked to authenticate before accessing the credentials. Your activity must override the Activity.onActivityResult method and call .checkAuthenticationResult with the received values.
- Parameters:
scope
- the scope to request for the access token.minTtl
- the minimum time in seconds that the access token should last before expiration.callback
- the callback to receive the result in.
-
clearCredentials
Unit clearCredentials()
Delete the stored credentials
-
hasValidCredentials
Boolean hasValidCredentials()
Returns whether this manager contains a valid non-expired pair of credentials.
-
hasValidCredentials
Boolean hasValidCredentials(Long minTtl)
Returns whether this manager contains a valid non-expired pair of credentials.
- Parameters:
minTtl
- the minimum time in seconds that the access token should last before expiration.
-
-
-
-