From a1b0f885a73e0352e98fa3106e5c1043014867a9 Mon Sep 17 00:00:00 2001 From: Matthew Wheatley Date: Tue, 27 Dec 2016 06:57:54 -0600 Subject: [PATCH] feat(android-fingerprint-auth): update to v1.2.1 (#910) * update to use plugin v1.1.0 Updated example Added new configuration options. Added new show() result fields Added new delete method * Update to plugin v1.2.0 Removed show() Added encrypt() Added decrypt() Removed requirement of username * edit comments * edited comments --- src/plugins/android-fingerprint-auth.ts | 102 +++++++++++++++++++++--- 1 file changed, 89 insertions(+), 13 deletions(-) diff --git a/src/plugins/android-fingerprint-auth.ts b/src/plugins/android-fingerprint-auth.ts index 60b05bc9c..b991559ed 100644 --- a/src/plugins/android-fingerprint-auth.ts +++ b/src/plugins/android-fingerprint-auth.ts @@ -3,15 +3,27 @@ import { Cordova, Plugin } from './plugin'; export interface AndroidFingerprintAuthOptions { /** + * Required * Used as the alias for your key in the Android Key Store. */ clientId: string; /** - * Used to encrypt the token returned upon successful fingerprint authentication. + * Used to create credential string for encrypted token and as alias to retrieve the cipher. */ - clientSecret: string; + username?: string; + /** + * Used to create credential string for encrypted token + */ + password?: string; + + /** + * Required for decrypt() + * Encrypted user credentials to decrypt upon successful authentication. + */ + token?: string; + /** * Set to true to remove the "USE BACKUP" button */ @@ -21,6 +33,33 @@ export interface AndroidFingerprintAuthOptions { * Change the language. (en_US or es) */ locale?: string; + + /** + * The device max is 5 attempts. Set this parameter if you want to allow fewer than 5 attempts. + */ + maxAttempts?: number; + + /** + * 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. + */ + userAuthRequired?: boolean; + + /** + * Set the title of the fingerprint authentication dialog. + */ + dialogTitle?: string; + + /** + * Set the message of the fingerprint authentication dialog. + */ + dialogMessage?: string; + + /** + * Set the hint displayed by the fingerprint icon on the fingerprint authentication dialog. + */ + dialogHint?: string; } @@ -37,15 +76,20 @@ export interface AndroidFingerprintAuthOptions { * if(result.isAvailable){ * // it is available * - * AndroidFingerprintAuth.show({ clientId: "myAppName", clientSecret: "so_encrypted_much_secure_very_secret" }) + * AndroidFingerprintAuth.encrypt({ clientId: "myAppName", username: "myUsername", password: "myPassword" }) * .then(result => { - * if(result.withFingerprint) { - * console.log('Successfully authenticated with fingerprint!'); - * } else if(result.withPassword) { + * 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 => console.error(error)); + * .catch(error => { + * if (error === "Cancelled") { + * console.log("Fingerprint authentication cancelled"); + * } else console.error(error) + * }); * * } else { * // fingerprint auth isn't available @@ -70,15 +114,41 @@ export class AndroidFingerprintAuth { * @returns {Promise} */ @Cordova() - static show(options: AndroidFingerprintAuthOptions): Promise<{ + static encrypt(options: AndroidFingerprintAuthOptions): Promise<{ /** - * Base64 encoded string + * Biometric authentication */ - withFingerprint: string; + withFingerprint: boolean; /** - * + * Authentication using backup credential activity */ - withPassword: boolean; + withBackup: boolean; + /** + * base64encoded string representation of user credentials + */ + token: string; + }> {return; } + + /** + * Opens a native dialog fragment to use the device hardware fingerprint scanner to authenticate against fingerprints registered for the device. + * @param options {AndroidFingerprintAuthOptions} Options + * @returns {Promise} + */ + @Cordova() + static decrypt(options: AndroidFingerprintAuthOptions): Promise<{ + /** + * Biometric authentication + */ + withFingerprint: boolean; + /** + * Authentication using backup credential activity + */ + withBackup: boolean; + /** + * FingerprintAuth.CipherMode.DECRYPT + * Decrypted password + */ + password: string; }> {return; } /** @@ -87,5 +157,11 @@ export class AndroidFingerprintAuth { */ @Cordova() static isAvailable(): Promise<{isAvailable: boolean}> {return; } - + + /** + * Delete the cipher used for encryption and decryption by username + * @returns {Promise} Returns a Promise that resolves if the cipher was successfully deleted + */ + @Cordova() + static delete(options: {clientId: string; username: string;}): Promise<{deleted: boolean}> {return; } }