Cordova plugin to use Android fingerprint authentication API
npm install cordova-plugin-android-fingerprint-authThis plugin will open a native dialog fragment prompting the user to authenticate using their fingerprint. If the device has a secure lockscreen (pattern, PIN, or password), the user may opt to authenticate using that method as a backup.
This plugin will only work on devices whose manufacturers have implemented the Android 6.0 Fingerprint Authentication API. This plugin does not support the Samsung Pass SDK and not all Samsung devices implement the Android 6.0 Fingerprint Authentication API. If you are testing this plugin on a Samsung device and it is not working, please check the device compatibility before reporting an issue.
cordova plugin add cordova-plugin-android-fingerprint-authionic cordova plugin add cordova-plugin-android-fingerprint-authmeteor add cordova:cordova-plugin-android-fingerprint-auth@1.2.7 (or present version)isAvailable() to check the fingerprint status.encrypt() or decrypt() show the Authentication Dialog.delete() when you want to delete the cipher for the user.If you are not concerned with encrypting credentials and just want device authentication (fingerprint or backup), just call encrypt() with a clientId and look for a callback to the successCallback.
encrypt().decrypt() to return password.Opens a native dialog fragment to use the device hardware fingerprint scanner to authenticate against fingerprints
registered for the device.
Example
``javascript
FingerprintAuth.isAvailable(isAvailableSuccess, isAvailableError);
/**
* @return {
* isAvailable:boolean,
* isHardwareDetected:boolean,
* hasEnrolledFingerprints:boolean
* }
*/
function isAvailableSuccess(result) {
console.log("FingerprintAuth available: " + JSON.stringify(result));
if (result.isAvailable) {
var encryptConfig = {}; // See config object for required parameters
FingerprintAuth.encrypt(encryptConfig, encryptSuccessCallback, encryptErrorCallback);
}
}
function isAvailableError(message) {
console.log("isAvailableError(): " + message);
}
`
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| clientId | String | undefined | (REQUIRED) Used as the alias for your app's secret key in the Android Key Store. Also used as part of the Shared Preferences key for the cipher userd to encrypt the user credentials. |
| username | String | undefined | Used to create credential string for encrypted token and as alias to retrieve the cipher. |
| password | String | undefined | Used to create credential string for encrypted token |
| token | String | undefined | Data to be decrypted. Required for decrypt(). |true
| disableBackup | boolean | false | Set to true to remove the "USE BACKUP" button |
| maxAttempts | number | 5 | The device max is 5 attempts. Set this parameter if you want to allow fewer than 5 attempts. |
| locale | String | "en_US" | Change the language displayed on the authentication dialog.
|
| userAuthRequired | boolean | false | Require the user to authenticate with a fingerprint to authorize every use of the key. New fingerprint enrollment will invalidate key and require backup authenticate to re-enable the fingerprint authentication dialog. |
| encryptNoAuth | boolean | undefined | Bypass authentication and just encrypt input. If this option will not display the authentication dialog for fingerprint or backup credentials. It will just encrypt the input and return a token. |
| dialogTitle | String | undefined | Set the title of the fingerprint authentication dialog. |
| dialogMessage | String | undefined | Set the message of the fingerprint authentication dialog. |
| dialogHint | String | undefined | Set the hint displayed by the fingerprint icon on the fingerprint authentication dialog. |
Example
`javascript
var encryptConfig = {
clientId: "myAppName",
username: "currentUser",
password: "currentUserPassword"
};
FingerprintAuth.encrypt(encryptConfig, successCallback, errorCallback);
function successCallback(result) {
console.log("successCallback(): " + JSON.stringify(result));
if (result.withFingerprint) {
console.log("Successfully encrypted credentials.");
console.log("Encrypted credentials: " + result.token);
} else if (result.withBackup) {
console.log("Authenticated with backup password");
}
}
function errorCallback(error) {
if (error === FingerprintAuth.ERRORS.FINGERPRINT_CANCELLED) {
console.log("FingerprintAuth Dialog Cancelled!");
} else {
console.log("FingerprintAuth Error: " + error);
}
}
`
Example
`javascript
var decryptConfig = {
clientId: "myAppName",
username: "currentUser",
token: "base64encodedUserCredentials"
};
FingerprintAuth.decrypt(decryptConfig, successCallback, errorCallback);
function successCallback(result) {
console.log("successCallback(): " + JSON.stringify(result));
if (result.withFingerprint) {
console.log("Successful biometric authentication.");
if (result.password) {
console.log("Successfully decrypted credential token.");
console.log("password: " + result.password);
}
} else if (result.withBackup) {
console.log("Authenticated with backup password");
}
}
function errorCallback(error) {
if (error === FingerprintAuth.ERRORS.FINGERPRINT_CANCELLED) {
console.log("FingerprintAuth Dialog Cancelled!");
} else {
console.log("FingerprintAuth Error: " + error);
}
}
`
Used to delete a cipher.
#### Config Object
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| clientId | String | undefined | (REQUIRED) Used as the alias for your key in the Android Key Store. |
| username | String | undefined | Identify which cipher to delete. |
Example
`javascript
FingerprintAuth.delete({
clientId: "myAppName",
username: "usernameToDelete"
}, successCallback, errorCallback);
function successCallback(result) {
console.log("Successfully deleted cipher: " + JSON.stringify(result));
}
function errorCallback(error) {
console.log(error);
}
`
Used to dismiss a Fingerprint Authentication Dialog if one is being displayed
Example
`javascript
FingerprintAuth.dismiss(successCallback, errorCallback);
function successCallback(result) {
console.log("Successfully dismissed FingerprintAuth dialog: " + JSON.stringify(result));
}
function errorCallback(error) {
console.log(error);
}
`