Ionic 2 Android Fingerprint Auth– Install cordova-plugin-android-fingerprint-auth plugin to use the android native fingerprint aunthentication feature. Here in this tutorial we are going to explain how you can use Ionic 2 Android Native Fingerprint Authentication.
Ionic 2 Android Fingerprint Auth Example | Command
First install the fingerprint Auth plugin simply as below –
Ionic 2 Android Fingerprint Auth Plugin Install Example:
$ ionic plugin add cordova-plugin-android-fingerprint-auth
$ npm install --save @ionic-native/android-fingerprint-auth
|
After Installing the plugin you will be able to use the androd fingerprint’s features.
Supported Platform
Usage
Let us create a simple example to access the native fingerprint feature in Ionic 2 –
Ionic 2 Android Fingerprint Auth Example:
import { AndroidFingerprintAuth, AFAAuthOptions } from '@ionic-native/android-fingerprint-auth';
constructor(private androidFingerprintAuth: AndroidFingerprintAuth) { }
...
this.androidFingerprintAuth.isAvailable()
.then((result)=> {
if(result.isAvailable){
// it is available
this.androidFingerprintAuth.encrypt({ clientId: "myAppName", username: "myUsername", password: "myPassword" })
.then(result => {
if (result.withFingerprint) {
console.log("Successfully encrypted credentials.");
console.log("Encrypted credentials: " + result.token);
} else if (result.withBackup) {
console.log('Successfully authenticated with backup password!');
} else console.log('Didn\'t authenticate!');
})
.catch(error => {
if (error === "Cancelled") {
console.log("Fingerprint authentication cancelled");
} else console.error(error)
});
} else {
// fingerprint auth isn't available
}
})
.catch(error => console.error(error));
|
Instance Members
- 1. encrypt(options) : This opens a native dialog fragment to use the device hardware fingerprint scanner to authenticate the against the fingerprints registered on the device.
Param |
Type |
Details |
options |
AFAAuthOptions |
Options |
- 2. decrypt(options) : This opens a native dialog fragment to use the device hardware fingerprint scanner to authenticate the against the fingerprints registered on the device.
Param |
Type |
Details |
options |
AFAAuthOptions |
Options |
- 2. isAvailable(options) : This checks if fingerprint auth service is avilable on devide.
- 2. delete(options) : This is used to delete the ciper used for the encryption and decryption by username.
- Returns – Promise : This Returns a promise that resolves if ciper was deleted successfully.
AFAAuthOptions
Following options are avialeble for AFAAuthOptions
Param |
Type |
Details |
clientId |
string |
Required Used as the alias for your key in the Android Key Store. |
username |
string(optional) |
Used to create credential string for encrypted token and as alias to retrieve the cipher. |
password |
string(optional) |
Used to create credential string for encrypted token |
token |
string(optional) |
Required for decrypt() Encrypted user credentials to decrypt upon successful authentication. |
disableBackup |
boolean |
Set to true to remove the “USE BACKUP” button |
locale |
string(optional) |
Change the language. (en_US or es)(optional) |
maxAttempts |
number(optional) |
The device max is 5 attempts. Set this parameter if you want to allow fewer than 5 attempts. |
userAuthRequired |
boolean(optional) |
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. |
dialogTitle |
string(optional) |
Set the title of the fingerprint authentication dialog. |
dialogMessage |
string(optional) |
Set the message of the fingerprint authentication dialog. |
dialogHint |
string(optional) |
Set the hint displayed by the fingerprint icon on the fingerprint authentication dialog. |
AFAEncryptResponse
Param |
Type |
Details |
withFingerprint |
boolean |
Biometric authentication |
withBackup |
boolean |
Authentication using backup credential activity. |
token |
string |
base64encoded string representation of user credentials. |
AFADecryptOptions
Param |
Type |
Details |
withFingerprint |
boolean |
Biometric authentication |
withBackup |
boolean |
Authentication using backup credential activity. |
token |
string |
FingerprintAuth.CipherMode.DECRYPT Decrypted password. |
Learn Ionic
Components
Ionic 2 Native