...
Code Block |
---|
|
cordova plugin add cordova-plugin-android-fingerprint-auth |
Usage
Assume that there are two buttons "AVAIL FINGERPRINT SCANNER" and "AUTHENTICATE" on your mobile applications that checks if the fingerprint scanner is configured and authenticates the fingerprint respectively. The following is a sample code snippet that can be used in the listener JS file for invoking the fingerprint scanner and authenticating the fingerprint.
Code Block |
---|
|
//* The Thisfollowing function checks whether or not the user has configured the fingerprint scanner.
* Here, CFEC.CLICK is the Canvas event that can be used to capture the button clicked action.
* AVAIL is the form item ID for the "AVAIL FINGERPRINT SCANNER" button.
*/
this.fm.registerHandler("cbxclick"CFEC.CLICK, "AVAIL",
function (fm, event, fieldName, value)
{
canvas.env.util.fingerPrint.isAvailable(SuccessCallback, ErrorCallback);
});
/* To authenticate the fingerprint, *the Thisfollowing method opens a native dialog fragment
* to use the device hardware fingerprint scanner
* to authenticate against fingerprints
* registered for the device.
* Here, CFEC.CLICK is the Canvas event that can be used to capture the button clicked action.
* AVAIL is the form item ID for the "AVAIL FINGERPRINT SCANNER" button.
*/
this.fm.registerHandler("cbxclick"CFEC.CLICK, "AUTHENTICATE",
function (fm, event, fieldName, value)
{
var params =
{
buttonLabel: "Enter your PIN",
popupMessage: "Please scan your fingerprint",
clientSecret: "Used to encrypt the token returned upon successful fingerprint authentication.",
clientId: "Used as the alias for your key in the Android Key Store"
};
canvas.env.util.fingerPrint.authenticate(params, successCallback, errorCallback);
});
/* SuccessCallback will get callcalled only ifwhen the fingerprint or touch ID is available on a device.
* If the SuccessCallback handler was called, you can scan the fingerprint.
*/
function SuccessCallback(result)
{
showAlert("available");
}
// ErrorCallback will get callcalled if the device has no touch TouchIDID available.
function ErrorCallback(error)
{
showAlert("not available:" + error);
}
|