Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including cordova-plugin-android-fingerprint-auth with all npm packages installed. Try it out:

cordova-plugin-android-fingerprint-auth lists no main file and has no index.js, so it can't be directly required. If this is a mistake, please let us know. It may however contain internal files that you can require manually:

// require("cordova-plugin-android-fingerprint-auth/[??]")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

cordova-plugin-android-fingerprint-auth v1.5.0

Cordova plugin to use Android fingerprint authentication API

Update to Version 1.4.0

Please consult the changelog.

About

This plugin was created referencing the Fingerprint Dialog sample and the Confirm Credential sample referenced by the Android 6.0 APIs webpage.

This 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.

Screenshots

Fingerprint Authentication Dialog

Fingerprint Auth Dialog Fingerprint Auth Dialog Success Fingerprint Auth Dialog Fail Fingerprint Auth Dialog Too Many Fingerprint Auth Dialog No Backup Fingerprint Auth Dialog No Backup

Backup Credentials

Confirm Password Confirm PIN Confirm Pattern

Installation

Cordova

cordova plugin add cordova-plugin-android-fingerprint-auth

Ionic

ionic cordova plugin add cordova-plugin-android-fingerprint-auth

Meteor

meteor add cordova:cordova-plugin-android-fingerprint-auth@1.2.7 (or present version)

How to use

  • Call isAvailable() to check the fingerprint status.
  • Call encrypt() or decrypt() show the Authentication Dialog.
  • Call 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 User Credentials

  • Encrypt user credentials
    • Have user sign in with username and password.
    • Check plugin availability and pass username and password to encrypt().
    • Store encrypted token with user profile.
  • Decrypt user credentials
    • Prompt for username.
    • Query on username to retrieve encrypted token.
    • Pass username and token to decrypt() to return password.
    • Login using username and decrypted password.

Example implementation

API Reference

FingerprintAuth.isAvailable(successCallback, errorCallback)

Opens a native dialog fragment to use the device hardware fingerprint scanner to authenticate against fingerprints registered for the device.

isAvailable() Result Object

ParamTypeDescription
isAvailablebooleanFingerprint Authentication Dialog is available for use.
isHardwareDetectedbooleanDevice has hardware fingerprint sensor.
hasEnrolledFingerprintsbooleanDevice has any fingerprints enrolled.

Example

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);
}

FingerprintAuth Config Object

ParamTypeDefaultDescription
clientIdStringundefined(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.
usernameStringundefinedUsed to create credential string for encrypted token and as alias to retrieve the cipher.
passwordStringundefinedUsed to create credential string for encrypted token
tokenStringundefinedData to be decrypted. Required for decrypt().
disableBackupbooleanfalseSet to true to remove the "USE BACKUP" button
maxAttemptsnumber5The device max is 5 attempts. Set this parameter if you want to allow fewer than 5 attempts.
localeString"en_US"Change the language displayed on the authentication dialog.
  • English: "en_US"
  • Italian: "it"
  • Spanish: "es"
  • Russian: "ru"
  • French: "fr"
  • Chinese (Simplified):
    • "zh_CN"
    • "zh_SG"
  • Chinese (Traditional):
    • "zh"
    • "zh_HK"
    • "zh_TW"
    • "zh_MO"
  • Norwegian: "no"
  • Portuguese: "pt"
  • Japanese: "ja"
  • German: "de"
  • Thai: "th"
  • Arabic: "ar"
  • Korean: "ko", "ko-KR"
userAuthRequiredbooleanfalseRequire 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.
encryptNoAuthbooleanundefinedBypass authentication and just encrypt input. If true this option will not display the authentication dialog for fingerprint or backup credentials. It will just encrypt the input and return a token.
dialogTitleStringundefinedSet the title of the fingerprint authentication dialog.
dialogMessageStringundefinedSet the message of the fingerprint authentication dialog.
dialogHintStringundefinedSet the hint displayed by the fingerprint icon on the fingerprint authentication dialog.

FingerprintAuth.encrypt(encryptConfig, encryptSuccessCallback, encryptErrorCallback)

Result Object

ParamTypeDescription
withFingerprintbooleanUser authenticated using a fingerprint
withBackupbooleanUser authenticated using backup credentials.
tokenStringWill contain the base64 encoded credentials upon successful fingerprint authentication.

Example

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);
    }
}

FingerprintAuth.decrypt(decryptConfig, encryptSuccessCallback, encryptErrorCallback)

Result Object

ParamTypeDescription
withFingerprintbooleanUser authenticated using a fingerprint
withBackupbooleanUser authenticated using backup credentials.
passwordStringWill contain the decrypted password upon successful fingerprint authentication.

Example

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);
    }
}

FingerprintAuth.delete(config, successCallback, errorCallback)

Used to delete a cipher.

Config Object

ParamTypeDefaultDescription
clientIdStringundefined(REQUIRED) Used as the alias for your key in the Android Key Store.
usernameStringundefinedIdentify which cipher to delete.

Example

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);
}

FingerprintAuth.dismiss(successCallback, errorCallback)

Used to dismiss a Fingerprint Authentication Dialog if one is being displayed

Example

FingerprintAuth.dismiss(successCallback, errorCallback);

function successCallback(result) {
    console.log("Successfully dismissed FingerprintAuth dialog: " + JSON.stringify(result));
}

function errorCallback(error) {
    console.log(error);
}

FingerprintAuth.ERRORS JSON Object

PropertyTypeValue
BAD_PADDING_EXCEPTIONString"BAD_PADDING_EXCEPTION"
CERTIFICATE_EXCEPTIONString"BAD_PADDING_EXCEPTION"
FINGERPRINT_CANCELLEDString"FINGERPRINT_CANCELLED"
FINGERPRINT_DATA_NOT_DELETEDString"FINGERPRINT_DATA_NOT_DELETED"
FINGERPRINT_ERRORString"FINGERPRINT_ERROR"
FINGERPRINT_NOT_AVAILABLEString"FINGERPRINT_NOT_AVAILABLE"
FINGERPRINT_PERMISSION_DENIEDString"FINGERPRINT_PERMISSION_DENIED"
FINGERPRINT_PERMISSION_DENIED_SHOW_REQUESTString"FINGERPRINT_PERMISSION_DENIED_SHOW_REQUEST"
ILLEGAL_BLOCK_SIZE_EXCEPTIONString"ILLEGAL_BLOCK_SIZE_EXCEPTION"
INIT_CIPHER_FAILEDString"INIT_CIPHER_FAILED"
INVALID_ALGORITHM_PARAMETER_EXCEPTIONString"INVALID_ALGORITHM_PARAMETER_EXCEPTION"
IO_EXCEPTIONString"IO_EXCEPTION"
JSON_EXCEPTIONString"JSON_EXCEPTION"
MINIMUM_SDKString"MINIMUM_SDK"
MISSING_ACTION_PARAMETERSString"MISSING_ACTION_PARAMETERS"
MISSING_PARAMETERSString"MISSING_PARAMETERS"
NO_SUCH_ALGORITHM_EXCEPTIONString"NO_SUCH_ALGORITHM_EXCEPTION"
SECURITY_EXCEPTIONString"SECURITY_EXCEPTION"
FRAGMENT_NOT_EXISTString"FRAGMENT_NOT_EXIST
RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free