### Install Cordova Biometric Auth Plugin Source: https://github.com/andreszs/cordova-plugin-biometric-auth/blob/main/README.md Installs the cordova-plugin-biometric-auth plugin from NPM or GitHub master branch. Requires Cordova CLI to be installed and configured. The plugin supports Android API level 21 and above. ```bash cordova plugin add cordova-plugin-biometric-auth ``` ```bash cordova plugin add https://github.com/andreszs/cordova-plugin-biometric-auth ``` -------------------------------- ### Authenticate with Biometrics using Cordova Plugin Source: https://github.com/andreszs/cordova-plugin-biometric-auth/blob/main/README.md Demonstrates how to prompt the user for biometric authentication using the cordova-plugin-biometric-auth. It includes success and error callback functions and optional parameters to customize the prompt, such as title and subtitle. Ensure the plugin is correctly installed in your Cordova project. ```javascript var onSuccess = function (strSuccess) { console.log(strSuccess); }; var onError = function (strError) { console.warn(strError); }; var optionalParams = { title: "Confirm operation", subtitle: "Verify with biometrics to continue" }; cordova.plugins.BiometricAuth.authenticate(onSuccess, onError, optionalParams); ``` -------------------------------- ### Complete Biometric Authentication Flow with Error Handling in JavaScript Source: https://context7.com/andreszs/cordova-plugin-biometric-auth/llms.txt This JavaScript code demonstrates a full authentication process using the cordova-plugin-biometric-auth. It first checks for biometric or keyguard availability, then attempts authentication, and includes detailed handling for various success and error scenarios, such as authentication failure, user cancellation, and lack of enrolled biometrics. It requires the cordova-plugin-biometric-auth to be installed. ```javascript function initiateSecureOperation() { cordova.plugins.BiometricAuth.isAvailable( function(availabilityResult) { console.log('Authentication method available:', availabilityResult); if (availabilityResult === 'BIOMETRIC_SUCCESS') { performBiometricAuth(); } else if (availabilityResult === 'KEYGUARD_SUCCESS') { performKeyguardAuth(); } }, function(availabilityError) { console.error('No authentication available:', availabilityError); handleNoAuthAvailable(availabilityError); } ); } function performBiometricAuth() { var params = { title: "Secure Operation", subtitle: "Authenticate to continue", disableBackup: false }; cordova.plugins.BiometricAuth.authenticate( function(success) { console.log('Authentication successful:', success); executeSecureOperation(); }, function(error) { console.error('Authentication error:', error); handleAuthError(error); }, params ); } function performKeyguardAuth() { var params = { title: "Enter Credentials", subtitle: "Verify your identity", authenticators: 1 }; cordova.plugins.BiometricAuth.authenticate( function(success) { console.log('Credential verification successful:', success); executeSecureOperation(); }, function(error) { console.error('Credential verification error:', error); handleAuthError(error); }, params ); } function handleAuthError(error) { switch(error) { case 'AUTHENTICATION_FAILED': console.log('Biometric not recognized. Please try again.'); showRetryOption(); break; case 'PIN_OR_PATTERN_DISMISSED': console.log('Authentication cancelled by user'); returnToMainScreen(); break; default: console.log('Authentication error:', error); showGenericError(); } } function handleNoAuthAvailable(error) { if (error === 'BIOMETRIC_ERROR_NONE_ENROLLED') { console.log('No biometric enrolled. Please set up fingerprint or face recognition.'); showEnrollmentPrompt(); } else if (error === 'BIOMETRIC_ERROR_NO_HARDWARE') { console.log('Device does not support biometric authentication'); showAlternativeLogin(); } else { console.log('Authentication unavailable:', error); showAlternativeLogin(); } } function executeSecureOperation() { console.log('Executing secure operation...'); } function showRetryOption() { console.log('Show retry button'); } function returnToMainScreen() { console.log('Returning to main screen'); } function showGenericError() { console.log('Show generic error message'); } function showEnrollmentPrompt() { console.log('Prompt user to enroll biometric in device settings'); } function showAlternativeLogin() { console.log('Show alternative authentication method'); } initiateSecureOperation(); ``` -------------------------------- ### Device Credential Authentication with Cordova Plugin Source: https://context7.com/andreszs/cordova-plugin-biometric-auth/llms.txt Implements device credential authentication (PIN, pattern, password) using cordova-plugin-biometric-auth, with optional biometric support via KeyguardManager. This method is suitable for general verification needs. The code handles success, and specific error scenarios like no security setup or user cancellation. ```javascript // KeyguardManager authentication (API 21+) // Supports PIN, pattern, password, and enrolled biometrics var authParams = { title: "Verify Your Identity", subtitle: "Enter your device PIN or use biometrics", authenticators: 1 // KEYGUARD_MANAGER }; var onSuccess = function (result) { console.log('Device credential verified:', result); // Returns: "AUTHENTICATION_SUCCEEDED" unlockFeature(); }; var onError = function (error) { console.error('Credential verification failed:', error); if (error === 'BIOMETRIC_ERROR_NONE_ENROLLED') { console.log('No security set up on device'); promptSetupDeviceSecurity(); } else if (error === 'PIN_OR_PATTERN_DISMISSED') { console.log('User cancelled credential entry'); } }; cordova.plugins.BiometricAuth.authenticate(onSuccess, onError, authParams); function unlockFeature() { console.log('Feature unlocked'); // Enable protected feature } function promptSetupDeviceSecurity() { console.log('Please set up device PIN, pattern, or password in Settings'); } ``` -------------------------------- ### Check Biometric Availability - Basic Check Source: https://github.com/andreszs/cordova-plugin-biometric-auth/blob/main/README.md Checks if the device supports biometric authentication, KeyguardManager fallback (PIN, pattern, password), or both. Returns success if any authentication method is available, or error if none are available or hardware is unsupported. ```javascript var onSuccess = function (strSuccess) { console.log(strSuccess); }; var onError = function (strError) { console.warn(strError); }; cordova.plugins.BiometricAuth.isAvailable(onSuccess, onError); ``` -------------------------------- ### Browser Platform Simulation for Biometric Authentication Testing (JavaScript) Source: https://context7.com/andreszs/cordova-plugin-biometric-auth/llms.txt Simulates biometric authentication dialogs and responses on the browser platform for development and testing. It demonstrates how to check availability (always succeeding in the browser) and how to trigger success or failure callbacks during authentication attempts using predefined parameters. ```javascript // Browser platform simulation (for testing) // Note: Browser platform always returns BIOMETRIC_SUCCESS for isAvailable // and shows a dialog with three options for authenticate var onAvailableSuccess = function(result) { console.log('Browser mock: availability check -', result); // Always returns "BIOMETRIC_SUCCESS" in browser }; cordova.plugins.BiometricAuth.isAvailable(onAvailableSuccess, function(error) { console.error('Availability error:', error); }); // Browser authenticate shows a dialog with three clickable options: // 1. Success icon - triggers successCallback with "BIOMETRIC_SUCCESS" // 2. Dismiss icon - triggers errorCallback with "BIOMETRIC_DISMISSED" // 3. Failed icon - triggers errorCallback with "AUTHENTICATION_FAILED" var authParams = { title: "Browser Test Authentication", subtitle: "Click an icon to simulate result", description: "This is a browser simulation for testing" }; cordova.plugins.BiometricAuth.authenticate( function(success) { console.log('Browser mock: user clicked success -', success); }, function(error) { console.error('Browser mock: user clicked dismiss/failed -', error); }, authParams ); ``` -------------------------------- ### Authenticate with Biometric or Device Credentials Source: https://github.com/andreszs/cordova-plugin-biometric-auth/blob/main/README.md Displays the biometric prompt or device credential dialog for user authentication. Supports multiple authenticator types and returns success when user is authenticated or error if authentication fails, is cancelled, or the device is unsupported. ```javascript cordova.plugins.BiometricAuth.authenticate(successCallback, errorCallback, [args]) ``` -------------------------------- ### Perform Basic Biometric Authentication in Cordova Source: https://context7.com/andreszs/cordova-plugin-biometric-auth/llms.txt Initiates a biometric authentication prompt using default settings. This function is suitable for basic authentication needs and calls success or error callbacks upon completion or failure. It returns 'AUTHENTICATION_SUCCEEDED' on success and handles errors like 'AUTHENTICATION_FAILED' or 'PIN_OR_PATTERN_DISMISSED'. ```javascript var onSuccess = function (result) { console.log('Authentication succeeded:', result); // Returns: "AUTHENTICATION_SUCCEEDED" // Proceed with secure operation performSecureTransaction(); }; var onError = function (error) { console.error('Authentication failed:', error); // Possible errors: "AUTHENTICATION_FAILED", "PIN_OR_PATTERN_DISMISSED" // Handle authentication failure if (error === 'AUTHENTICATION_FAILED') { console.log('Biometric not recognized, try again'); } else if (error === 'PIN_OR_PATTERN_DISMISSED') { console.log('User cancelled authentication'); } }; cordova.plugins.BiometricAuth.authenticate(onSuccess, onError); function performSecureTransaction() { console.log('User authenticated, processing secure transaction...'); // Your secure operation code here } ``` -------------------------------- ### Check Biometric Availability with Authenticator Types Source: https://github.com/andreszs/cordova-plugin-biometric-auth/blob/main/README.md Checks for specific authenticator types such as BIOMETRIC_WEAK, BIOMETRIC_STRONG, KEYGUARD_MANAGER, or DEVICE_CREDENTIAL. Passes optional parameters to filter authentication methods and returns appropriate success or error codes based on device capabilities and API level. ```javascript var Authenticators = { KEYGUARD_MANAGER: 1, BIOMETRIC_STRONG: 15, BIOMETRIC_WEAK: 255, DEVICE_CREDENTIAL: 32768 }; var onSuccess = function (strSuccess) { console.log(strSuccess); }; var onError = function (strError) { console.warn(strError); }; var optionalParams = { authenticators: Authenticators.BIOMETRIC_WEAK }; cordova.plugins.BiometricAuth.isAvailable(onSuccess, onError, optionalParams); ``` -------------------------------- ### Custom Authentication Prompt with Cordova Biometric Auth Source: https://context7.com/andreszs/cordova-plugin-biometric-auth/llms.txt Displays a customized authentication dialog using cordova-plugin-biometric-auth, allowing developers to set a specific title, subtitle, and button text. This is useful for providing context to the user during authentication, such as confirming a payment amount. It handles success and error callbacks for processing the authentication result. ```javascript // Customized authentication prompt var onSuccess = function (result) { console.log('Payment authorized:', result); processPayment(); }; var onError = function (error) { console.error('Payment authorization failed:', error); showErrorMessage('Unable to verify identity. Payment cancelled.'); }; var authParams = { title: "Authorize Payment", subtitle: "Confirm your $99.99 purchase", negativeButtonText: "Cancel", disableBackup: false // Allow fallback to device credentials }; cordova.plugins.BiometricAuth.authenticate(onSuccess, onError, authParams); function processPayment() { console.log('Processing payment...'); // Payment processing logic } function showErrorMessage(message) { console.log('Error:', message); // Display error to user } ``` -------------------------------- ### Check Biometric Availability in Cordova Source: https://context7.com/andreszs/cordova-plugin-biometric-auth/llms.txt Verifies if the device supports biometric authentication or device credential authentication and if the user has enrolled authentication methods. This function takes success and error callbacks. The success callback receives 'BIOMETRIC_SUCCESS' or 'KEYGUARD_SUCCESS', while the error callback handles various failure reasons. ```javascript var onSuccess = function (result) { console.log('Authentication available:', result); // Returns: "BIOMETRIC_SUCCESS" or "KEYGUARD_SUCCESS" }; var onError = function (error) { console.error('Authentication unavailable:', error); // Possible errors: "BIOMETRIC_ERROR_NO_HARDWARE", // "BIOMETRIC_ERROR_NONE_ENROLLED", "BIOMETRIC_ERROR_HW_UNAVAILABLE", // "BIOMETRIC_ERROR_SECURITY_UPDATE_REQUIRED", "BIOMETRIC_ERROR_UNSUPPORTED" }; cordova.plugins.BiometricAuth.isAvailable(onSuccess, onError); ``` -------------------------------- ### Biometric Authentication with Disabled Fallback via Cordova Plugin Source: https://context7.com/andreszs/cordova-plugin-biometric-auth/llms.txt Forces biometric-only authentication by disabling the device credential fallback option using cordova-plugin-biometric-auth. This enhances security by ensuring only biometric verification is accepted. The `disableBackup` parameter is set to `true`, and `negativeButtonText` becomes mandatory. Error handling is provided for scenarios where biometric authentication fails. ```javascript // Biometric authentication with no fallback option var authParams = { title: "Biometric Login", subtitle: "Place your finger on the sensor", disableBackup: true, // Remove device credential option negativeButtonText: "Cancel" // Required when disableBackup is true }; var onSuccess = function (result) { console.log('Biometric login successful:', result); loginUser(); }; var onError = function (error) { console.error('Biometric login failed:', error); // User must use biometric - no PIN/pattern fallback retryBiometricOrShowMessage(); }; cordova.plugins.BiometricAuth.authenticate(onSuccess, onError, authParams); function loginUser() { console.log('User logged in via biometric'); // Proceed to application } function retryBiometricOrShowMessage() { console.log('Biometric required. Please try again or use alternative login method.'); } ``` -------------------------------- ### Check Specific Authenticator Types Availability in Cordova Source: https://context7.com/andreszs/cordova-plugin-biometric-auth/llms.txt Checks for the availability of specific authentication types like weak biometrics or device credentials using predefined constants. It accepts optional parameters to specify the authenticator type, along with success and error callbacks to handle the results and potential errors. ```javascript var Authenticators = { KEYGUARD_MANAGER: 1, // PIN, pattern, password via KeyguardManager BIOMETRIC_STRONG: 15, // Strong biometric (Class 3) BIOMETRIC_WEAK: 255, // Weak biometric (Class 2) DEVICE_CREDENTIAL: 32768 // PIN, pattern, password }; var onSuccess = function (result) { console.log('Weak biometric available:', result); // Returns: "BIOMETRIC_SUCCESS" if available }; var onError = function (error) { console.warn('Weak biometric not available:', error); // Handle specific error codes if (error === 'BIOMETRIC_ERROR_NONE_ENROLLED') { console.log('No biometric enrolled, prompt user to enroll'); } else if (error === 'BIOMETRIC_ERROR_NO_HARDWARE') { console.log('No biometric hardware available'); } }; var optionalParams = { authenticators: Authenticators.BIOMETRIC_WEAK }; cordova.plugins.BiometricAuth.isAvailable(onSuccess, onError, optionalParams); ``` -------------------------------- ### Strong Biometric Authentication Only with Cordova Plugin Source: https://context7.com/andreszs/cordova-plugin-biometric-auth/llms.txt Enforces strong biometric authentication (Class 3) without allowing device credential fallback using cordova-plugin-biometric-auth. This is ideal for high-security operations where only robust biometrics should be accepted. The code first checks for availability of strong biometrics and then proceeds with authentication, handling cases where it's not available. ```javascript // Strong biometric only - no PIN/pattern fallback var Authenticators = { BIOMETRIC_STRONG: 15 }; // First, check if strong biometric is available cordova.plugins.BiometricAuth.isAvailable( function(result) { console.log('Strong biometric available:', result); // Proceed with authentication authenticateWithStrongBiometric(); }, function(error) { console.error('Strong biometric not available:', error); showAlternativeAuthMethod(); }, { authenticators: Authenticators.BIOMETRIC_STRONG } ); function authenticateWithStrongBiometric() { var authParams = { title: "Secure Access Required", subtitle: "Use fingerprint for high-security access", negativeButtonText: "Cancel", authenticators: 15 // BIOMETRIC_STRONG }; cordova.plugins.BiometricAuth.authenticate( function(result) { console.log('Strong authentication succeeded:', result); grantHighSecurityAccess(); }, function(error) { console.error('Strong authentication failed:', error); denyAccess(); }, authParams ); } function grantHighSecurityAccess() { console.log('Granting access to sensitive data...'); // Access sensitive resources } function denyAccess() { console.log('Access denied'); } function showAlternativeAuthMethod() { console.log('Strong biometric not available, showing alternative auth'); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.