The 2017 Ionic Developer Survey Results are in!

Android Fingerprint Auth

Improve this doc

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.

Repo: https://github.com/mjwheatley/cordova-plugin-android-fingerprint-auth

Installation

  1. Install the Cordova and Ionic Native plugins:
    $ ionic cordova plugin add cordova-plugin-android-fingerprint-auth
    $ npm install --save @ionic-native/android-fingerprint-auth
    
  2. Add this plugin to your app's module

Supported platforms

Usage

import { AndroidFingerprintAuth } 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 === this.androidFingerprintAuth.ERRORS.FINGERPRINT_CANCELLED) {
             console.log('Fingerprint authentication cancelled');
           } else console.error(error)
        });

    } else {
      // fingerprint auth isn't available
    }
  })
  .catch(error => console.error(error));

Instance Members

ERRORS

encrypt(options)

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

Param Type Details
options AFAAuthOptions

Options

Returns: Promise<any>

decrypt(options)

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

Param Type Details
options AFAAuthOptions

Options

Returns: Promise<any>

isAvailable()

Check if service is available

Returns: Promise<any> Returns a Promise that resolves if fingerprint auth is available on the device

delete()

Delete the cipher used for encryption and decryption by username

Returns: Promise<any> Returns a Promise that resolves if the cipher was successfully deleted

AFAAuthOptions

Param Type Details
clientId string

Required Used as the alias for your key in the Android Key Store.

username string

Used to create credential string for encrypted token and as alias to retrieve the cipher.

(optional)
password string

Used to create credential string for encrypted token

(optional)
token string

Required for decrypt() Encrypted user credentials to decrypt upon successful authentication.

(optional)
disableBackup boolean

Set to true to remove the "USE BACKUP" button

(optional)
locale string

Change the language. (en_US or es)

(optional)
maxAttempts number

The device max is 5 attempts. Set this parameter if you want to allow fewer than 5 attempts.

(optional)
userAuthRequired boolean

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.

(optional)
dialogTitle string

Set the title of the fingerprint authentication dialog.

(optional)
dialogMessage string

Set the message of the fingerprint authentication dialog.

(optional)
dialogHint string

Set the hint displayed by the fingerprint icon on the fingerprint authentication dialog.

(optional)

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

password string

FingerprintAuth.CipherMode.DECRYPT Decrypted password

API

Native

General