### Install Cordova Plugin Fingerprint AIO Source: https://github.com/niklasmerz/cordova-plugin-fingerprint-aio/blob/master/README.md Instructions for installing the plugin via NPM, including options for setting FaceID descriptions and using release candidates or the GitHub repository. ```bash cordova plugin add cordova-plugin-fingerprint-aio --save cordova plugin add cordova-plugin-fingerprint-aio --variable FACEID_USAGE_DESCRIPTION="Login now...." cordova plugin add cordova-plugin-fingerprint-aio@rc cordova plugin add https://github.com/NiklasMerz/cordova-plugin-fingerprint-aio.git ``` -------------------------------- ### Authenticate User with Biometric Source: https://context7.com/niklasmerz/cordova-plugin-fingerprint-aio/llms.txt Displays the biometric authentication prompt with customizable title and description text. Validates biometric availability before attempting authentication and executes success or error callbacks based on the authentication result. Returns true on successful authentication. ```javascript authenticate: function(callback) { if (!BiometricAuth.isAvailable) { return callback(new Error('Biometric authentication not available')); } Fingerprint.show( { title: "My Secure App", description: "Authenticate to access your account", fallbackButtonTitle: "Use Password", disableBackup: false }, function() { console.log('Authentication successful'); BiometricAuth.isAuthenticated = true; callback(null, true); }, function(error) { console.error('Authentication failed: ' + error.message); BiometricAuth.isAuthenticated = false; callback(error); } ); } ``` -------------------------------- ### Display Biometric Authentication Prompt using JavaScript Source: https://context7.com/niklasmerz/cordova-plugin-fingerprint-aio/llms.txt Displays a biometric authentication dialog for user verification. It can include customizable titles, subtitles, descriptions, and fallback/cancel button titles. Options like 'disableBackup' and 'confirmationRequired' can be set. Handles success and failure scenarios, including errors like BIOMETRIC_DISMISSED or BIOMETRIC_LOCKED_OUT. ```javascript // Basic authentication Fingerprint.show( { description: "Confirm your identity to continue" }, function() { console.log("Authentication successful"); // Proceed with authenticated action loadUserData(); navigateToSecureSection(); }, function(error) { console.error("Authentication failed: " + error.message); console.error("Error code: " + error.code); // Handle different failure scenarios if (error.code === Fingerprint.BIOMETRIC_DISMISSED) { console.log("User cancelled authentication"); } else if (error.code === Fingerprint.BIOMETRIC_LOCKED_OUT) { alert("Too many failed attempts. Please try again later."); } else if (error.code === Fingerprint.BIOMETRIC_AUTHENTICATION_FAILED) { alert("Authentication failed. Please try again."); } } ); // Advanced authentication with full options Fingerprint.show( { title: "Employee Portal Login", subtitle: "Secure Access Required", description: "Place your finger on the sensor to access your account", fallbackButtonTitle: "Use PIN Code", cancelButtonTitle: "Cancel", disableBackup: false, // Allow PIN/pattern fallback confirmationRequired: true // Android: require explicit user confirmation }, function() { console.log("User authenticated successfully"); sessionStorage.setItem('authenticated', 'true'); window.location.href = 'dashboard.html'; }, function(error) { console.error("Authentication error: " + error.message); logAuthenticationAttempt('failed', error.code); } ); // Authentication with backup disabled (biometrics only) Fingerprint.show( { description: "Scan fingerprint for secure transaction", disableBackup: true, // No PIN/password fallback cancelButtonTitle: "Cancel Transaction" }, function() { processPayment(); }, function(error) { if (error.code === Fingerprint.BIOMETRIC_DISMISSED) { console.log("Transaction cancelled by user"); } } ); ``` -------------------------------- ### Complete Biometric Login Flow with API Integration Source: https://context7.com/niklasmerz/cordova-plugin-fingerprint-aio/llms.txt Executes end-to-end biometric login by loading credentials, authenticating against a remote API, and handling success/failure scenarios. Detects missing credentials scenario and differentiates from authentication failures. Makes POST request to login endpoint with loaded credentials. ```javascript performBiometricLogin: function(successCallback, errorCallback) { BiometricAuth.loadCredentials(function(error, credentials) { if (error) { if (error.code === Fingerprint.BIOMETRIC_SECRET_NOT_FOUND) { console.log('No credentials saved - showing manual login'); return errorCallback(new Error('No saved credentials')); } return errorCallback(error); } console.log('Logging in as: ' + credentials.username); fetch('https://api.example.com/login', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ username: credentials.username, password: credentials.password }) }) .then(response => response.json()) .then(data => { if (data.success) { console.log('Login successful'); successCallback(data); } else { errorCallback(new Error('Login failed')); } }) .catch(errorCallback); }); } ``` -------------------------------- ### Initialize Biometric Authentication with Fallback Logic - JavaScript Source: https://context7.com/niklasmerz/cordova-plugin-fingerprint-aio/llms.txt Initializes the BiometricAuth plugin and determines available biometric type. Checks if biometric login is enabled and conditionally renders UI elements for biometric or password login. Handles initialization errors by falling back to password-only authentication. ```javascript BiometricAuth.init(function(error, biometricType) { if (error) { console.log('Biometric not available, using password only'); showPasswordLogin(); return; } console.log('Biometric type: ' + biometricType); if (BiometricAuth.isBiometricLoginEnabled()) { document.getElementById('biometric-login-btn').style.display = 'block'; } }); ``` -------------------------------- ### Show Biometric Authentication Dialogue (JavaScript) Source: https://github.com/niklasmerz/cordova-plugin-fingerprint-aio/blob/master/README.md Shows how to trigger the biometric authentication dialog using the Fingerprint plugin. It provides a success callback for successful authentication and an error callback for failures. ```javascript Fingerprint.show({ description: "Some biometric description" }, successCallback, errorCallback); function successCallback(){ alert("Authentication successful"); } function errorCallback(error){ alert("Authentication invalid " + error.message); } ``` -------------------------------- ### Perform Biometric Login with Success and Error Callbacks - JavaScript Source: https://context7.com/niklasmerz/cordova-plugin-fingerprint-aio/llms.txt Executes biometric authentication when user clicks the biometric login button. Handles successful authentication by navigating to dashboard with user data. Manages authentication failures with error messaging and fallback to password login. ```javascript document.getElementById('biometric-login-btn').addEventListener('click', function() { BiometricAuth.performBiometricLogin( function(data) { console.log('Biometric login successful'); navigateToDashboard(data); }, function(error) { console.error('Biometric login failed: ' + error.message); alert('Biometric login failed. Please use password.'); showPasswordLogin(); } ); }); ``` -------------------------------- ### Initialize and Check Biometric Availability Source: https://context7.com/niklasmerz/cordova-plugin-fingerprint-aio/llms.txt Detects available biometric authentication methods (fingerprint or face recognition) on the device and updates the UI accordingly. Handles both success and error cases, storing availability status and biometric type for later use. Requires the Fingerprint plugin to be available. ```javascript var BiometricAuth = { init: function(callback) { console.log('Initializing biometric authentication...'); Fingerprint.isAvailable( function(biometricType) { console.log('Biometric available: ' + biometricType); BiometricAuth.isAvailable = true; BiometricAuth.biometricType = biometricType; var iconClass = biometricType === 'face' ? 'face-icon' : 'fingerprint-icon'; document.getElementById('biometric-icon').className = iconClass; if (callback) callback(null, biometricType); }, function(error) { console.error('Biometric not available: ' + error.message); BiometricAuth.isAvailable = false; BiometricAuth.error = error; if (callback) callback(error); }, { requireStrongBiometrics: true } ); } }; ``` -------------------------------- ### Implement Comprehensive Biometric Error Handler - Cordova Fingerprint Source: https://context7.com/niklasmerz/cordova-plugin-fingerprint-aio/llms.txt Provides a complete error handling function that maps error codes to user-friendly messages and determines appropriate recovery actions (retry, navigate to settings, or dismiss). Logs analytics data for debugging and triggers platform-specific responses such as device settings navigation or retry delays. Handles 8+ distinct error scenarios including authentication failures, hardware unavailability, and lockout conditions. ```javascript function handleBiometricError(error) { console.error('Biometric error occurred:', error); var userMessage = ''; var shouldRetry = false; var shouldNavigateToSettings = false; switch(error.code) { case Fingerprint.BIOMETRIC_UNKNOWN_ERROR: userMessage = 'An unknown error occurred. Please try again.'; shouldRetry = true; break; case Fingerprint.BIOMETRIC_UNAVAILABLE: userMessage = 'Biometric authentication is currently unavailable.'; break; case Fingerprint.BIOMETRIC_AUTHENTICATION_FAILED: userMessage = 'Authentication failed. Please try again.'; shouldRetry = true; break; case Fingerprint.BIOMETRIC_HARDWARE_NOT_SUPPORTED: userMessage = 'This device does not support biometric authentication.'; break; case Fingerprint.BIOMETRIC_NOT_ENROLLED: userMessage = 'No biometric credentials are enrolled on this device.'; shouldNavigateToSettings = true; break; case Fingerprint.BIOMETRIC_DISMISSED: userMessage = 'Authentication was cancelled.'; break; case Fingerprint.BIOMETRIC_LOCKED_OUT: userMessage = 'Too many failed attempts. Please wait and try again.'; break; case Fingerprint.BIOMETRIC_LOCKED_OUT_PERMANENT: userMessage = 'Biometric authentication is locked. Please use your device password.'; break; case Fingerprint.BIOMETRIC_SECRET_NOT_FOUND: userMessage = 'No secure credentials found. Please register first.'; break; default: userMessage = 'Authentication error: ' + error.message; } alert(userMessage); logEvent('biometric_error', { code: error.code, message: error.message, timestamp: new Date().toISOString() }); if (shouldNavigateToSettings) { if (confirm(userMessage + '\n\nWould you like to go to settings?')) { openDeviceSettings(); } } else if (shouldRetry) { setTimeout(function() { retryAuthentication(); }, 1000); } } ``` -------------------------------- ### Define Biometric Type Constants - Cordova Fingerprint Source: https://context7.com/niklasmerz/cordova-plugin-fingerprint-aio/llms.txt Creates a mapping of biometric authentication types (fingerprint, face recognition, or generic) supported by the device. Enables platform-agnostic detection and display of available biometric modalities. Used in conjunction with Fingerprint.isAvailable() to determine device capabilities. ```javascript var biometricTypes = { FINGERPRINT: Fingerprint.BIOMETRIC_TYPE_FINGERPRINT, // "finger" FACE: Fingerprint.BIOMETRIC_TYPE_FACE, // "face" GENERIC: Fingerprint.BIOMETRIC_TYPE_COMMON // "biometric" }; ``` -------------------------------- ### Check Fingerprint Availability (JavaScript) Source: https://github.com/niklasmerz/cordova-plugin-fingerprint-aio/blob/master/README.md Demonstrates how to check if a fingerprint scanner is available on the device using the Fingerprint plugin. It includes success and error callback functions to handle the result. ```javascript Fingerprint.isAvailable(isAvailableSuccess, isAvailableError, optionalParams); function isAvailableSuccess(result) { /* result depends on device and os. iPhone X will return 'face' other Android or iOS devices will return 'finger' Android P+ will return 'biometric' */ alert("Fingerprint available"); } function isAvailableError(error) { // 'error' will be an object with an error code and message alert(error.message); } ``` -------------------------------- ### Register Biometric Credentials After Password Login - JavaScript Source: https://context7.com/niklasmerz/cordova-plugin-fingerprint-aio/llms.txt Handles form submission for password login and offers to register biometric credentials after successful authentication. Uses BiometricAuth.registerCredentials() to securely store username and password for future biometric authentication. Displays confirmation dialog to user before enrollment. ```javascript document.getElementById('login-form').addEventListener('submit', function(e) { e.preventDefault(); var username = document.getElementById('username').value; var password = document.getElementById('password').value; loginWithPassword(username, password, function(error, success) { if (success) { if (confirm('Enable biometric login for next time?')) { BiometricAuth.registerCredentials(username, password, function(err) { if (!err) { alert('Biometric login enabled!'); } }); } navigateToDashboard(); } }); }); ``` -------------------------------- ### Register and Encrypt Biometric Credentials Source: https://context7.com/niklasmerz/cordova-plugin-fingerprint-aio/llms.txt Securely stores username and password credentials using biometric authentication. Encodes credentials as JSON, converts to Base64, and registers with the biometric secret storage system. Marks credentials for invalidation on biometric enrollment changes and enables localStorage flag for login detection. ```javascript registerCredentials: function(username, password, callback) { var credentials = JSON.stringify({ username: username, password: password, timestamp: new Date().toISOString() }); Fingerprint.registerBiometricSecret( { title: "Save Credentials", description: "Authenticate to securely save your login credentials", secret: btoa(credentials), invalidateOnEnrollment: true, disableBackup: true }, function() { console.log('Credentials registered successfully'); localStorage.setItem('biometric_enabled', 'true'); callback(null, true); }, function(error) { console.error('Failed to register credentials: ' + error.message); callback(error); } ); } ``` -------------------------------- ### Check and Display Available Biometric Type - Cordova Fingerprint Source: https://context7.com/niklasmerz/cordova-plugin-fingerprint-aio/llms.txt Queries device biometric capabilities using Fingerprint.isAvailable() and displays human-readable descriptions of detected biometric modalities (fingerprint, face ID, or generic). Implements error handling via callback to manage unavailable or unsupported scenarios. Output is logged to console for debugging. ```javascript Fingerprint.isAvailable( function(biometricType) { var typeDescription = ''; if (biometricType === biometricTypes.FINGERPRINT) { typeDescription = 'Fingerprint sensor detected'; } else if (biometricType === biometricTypes.FACE) { typeDescription = 'Face ID available'; } else if (biometricType === biometricTypes.GENERIC) { typeDescription = 'Biometric authentication available'; } console.log(typeDescription); }, handleBiometricError ); ``` -------------------------------- ### Load Biometric Secret with Authentication Dialog - Cordova JavaScript Source: https://github.com/niklasmerz/cordova-plugin-fingerprint-aio/blob/master/README.md Loads a previously registered biometric secret by calling Fingerprint.loadBiometricSecret() with configuration options and callbacks. Displays an authentication dialog prompting user biometric verification. Success callback receives the decrypted secret string, error callback handles authentication failures. ```javascript Fingerprint.loadBiometricSecret({ description: "Some biometric description", disableBackup: true, // always disabled on Android }, successCallback, errorCallback); function successCallback(secret){ alert("Authentication successful, secret: " + secret); } function errorCallback(error){ alert("Authentication invalid " + error.message); } ``` -------------------------------- ### Load and Decrypt Biometric Credentials Source: https://context7.com/niklasmerz/cordova-plugin-fingerprint-aio/llms.txt Retrieves and decrypts previously stored biometric credentials through authentication. Decodes Base64-encoded secret, parses JSON credentials, and handles parsing errors gracefully. Returns credential object containing username, password, and original registration timestamp. ```javascript loadCredentials: function(callback) { Fingerprint.loadBiometricSecret( { title: "Login", description: "Authenticate to load your saved credentials", disableBackup: true }, function(secret) { console.log('Credentials loaded'); try { var credentialsJson = atob(secret); var credentials = JSON.parse(credentialsJson); callback(null, credentials); } catch (parseError) { console.error('Failed to parse credentials: ' + parseError.message); callback(parseError); } }, function(error) { console.error('Failed to load credentials: ' + error.message); callback(error); } ); } ``` -------------------------------- ### Fingerprint Authentication Constants Source: https://github.com/niklasmerz/cordova-plugin-fingerprint-aio/blob/master/README.md These constants represent various error codes and states related to biometric authentication. They are crucial for handling different scenarios and providing informative feedback to the user or for debugging purposes. ```javascript BIOMETRIC_UNKNOWN_ERROR = -100; BIOMETRIC_UNAVAILABLE = -101; BIOMETRIC_AUTHENTICATION_FAILED = -102; BIOMETRIC_SDK_NOT_SUPPORTED = -103; BIOMETRIC_HARDWARE_NOT_SUPPORTED = -104; BIOMETRIC_PERMISSION_NOT_GRANTED = -105; BIOMETRIC_NOT_ENROLLED = -106; BIOMETRIC_INTERNAL_PLUGIN_ERROR = -107; BIOMETRIC_DISMISSED = -108; BIOMETRIC_PIN_OR_PATTERN_DISMISSED = -109; BIOMETRIC_SCREEN_GUARD_UNSECURED = -110; BIOMETRIC_LOCKED_OUT = -111; BIOMETRIC_LOCKED_OUT_PERMANENT = -112; BIOMETRIC_SECRET_NOT_FOUND = -113; ``` -------------------------------- ### Define Error Code Constants - Cordova Fingerprint Plugin Source: https://context7.com/niklasmerz/cordova-plugin-fingerprint-aio/llms.txt Establishes a comprehensive mapping of standardized error codes for biometric authentication failures across platforms. Each constant represents a specific error condition (-100 to -113) that can occur during fingerprint, face, or generic biometric authentication. Used to enable consistent error handling and user feedback throughout the application. ```javascript var errorCodes = { UNKNOWN: Fingerprint.BIOMETRIC_UNKNOWN_ERROR, // -100 UNAVAILABLE: Fingerprint.BIOMETRIC_UNAVAILABLE, // -101 AUTH_FAILED: Fingerprint.BIOMETRIC_AUTHENTICATION_FAILED, // -102 SDK_NOT_SUPPORTED: Fingerprint.BIOMETRIC_SDK_NOT_SUPPORTED, // -103 NO_HARDWARE: Fingerprint.BIOMETRIC_HARDWARE_NOT_SUPPORTED, // -104 NO_PERMISSION: Fingerprint.BIOMETRIC_PERMISSION_NOT_GRANTED, // -105 NOT_ENROLLED: Fingerprint.BIOMETRIC_NOT_ENROLLED, // -106 PLUGIN_ERROR: Fingerprint.BIOMETRIC_INTERNAL_PLUGIN_ERROR, // -107 DISMISSED: Fingerprint.BIOMETRIC_DISMISSED, // -108 PIN_DISMISSED: Fingerprint.BIOMETRIC_PIN_OR_PATTERN_DISMISSED, // -109 NOT_SECURED: Fingerprint.BIOMETRIC_SCREEN_GUARD_UNSECURED, // -110 LOCKED_OUT: Fingerprint.BIOMETRIC_LOCKED_OUT, // -111 LOCKED_PERMANENT: Fingerprint.BIOMETRIC_LOCKED_OUT_PERMANENT, // -112 NO_SECRET: Fingerprint.BIOMETRIC_SECRET_NOT_FOUND // -113 }; ``` -------------------------------- ### Load Encrypted Secret Source: https://context7.com/niklasmerz/cordova-plugin-fingerprint-aio/llms.txt Retrieves and decrypts a previously stored secret after biometric authentication. This function can be used for various purposes, including loading user secrets, API tokens, or encryption keys. It provides detailed error handling for different biometric authentication scenarios. ```APIDOC ## POST /biometric/loadSecret ### Description Retrieves and decrypts a previously stored secret after biometric authentication. This function can be used for various purposes, including loading user secrets, API tokens, or encryption keys. It provides detailed error handling for different biometric authentication scenarios. ### Method POST ### Endpoint /biometric/loadSecret ### Parameters #### Request Body - **options** (object) - Optional - Configuration options for the biometric prompt. - **description** (string) - Optional - The text displayed to the user describing the authentication purpose. - **title** (string) - Optional - The title of the authentication prompt. - **disableBackup** (boolean) - Optional - If true, disables fallback to device password authentication. - **cancelButtonTitle** (string) - Optional - The text for the cancel button. - **confirmationRequired** (boolean) - Optional - If true, requires explicit user confirmation after biometric match. ### Request Example ```json { "options": { "description": "Authenticate to access your secure data", "title": "Access Required", "disableBackup": false, "cancelButtonTitle": "Cancel", "confirmationRequired": false } } ``` ### Response #### Success Response (200) - **secret** (string) - The decrypted secret data. #### Error Response (e.g., 400, 500) - **message** (string) - A description of the error. - **code** (number) - An error code indicating the type of error (e.g., BIOMETRIC_SECRET_NOT_FOUND, BIOMETRIC_DISMISSED, BIOMETRIC_LOCKED_OUT_PERMANENT, BIOMETRIC_AUTHENTICATION_FAILED, BIOMETRIC_LOCKED_OUT). ### Response Example (Success) ```json { "secret": "decrypted_secret_data_string" } ``` ### Response Example (Error - Secret Not Found) ```json { "message": "No secret registered yet", "code": 100 // BIOMETRIC_SECRET_NOT_FOUND } ``` ### Response Example (Error - User Cancelled) ```json { "message": "User cancelled authentication", "code": 101 // BIOMETRIC_DISMISSED } ``` ### Response Example (Error - Permanently Locked) ```json { "message": "Biometric authentication locked. Please use device password.", "code": 102 // BIOMETRIC_LOCKED_OUT_PERMANENT } ``` ### Response Example (Error - Authentication Failed) ```json { "message": "Authentication failed", "code": 103 // BIOMETRIC_AUTHENTICATION_FAILED } ``` ### Response Example (Error - Temporarily Locked) ```json { "message": "Temporarily locked out", "code": 104 // BIOMETRIC_LOCKED_OUT } ``` ``` -------------------------------- ### Load Encrypted Secret with Biometric Authentication (JavaScript) Source: https://context7.com/niklasmerz/cordova-plugin-fingerprint-aio/llms.txt Retrieves and decrypts a previously stored secret after biometric authentication. This function takes configuration options for the biometric prompt, a success callback, and an error callback. It handles various error codes, including secret not found, user dismissal, and permanent lockout. ```javascript Fingerprint.loadBiometricSecret( { description: "Authenticate to access your secure data" }, function(secret) { console.log("Secret loaded successfully: " + secret); // Use the decrypted secret authenticateWithServer(secret); initializeSecureSession(secret); }, function(error) { console.error("Failed to load secret: " + error.message); console.error("Error code: " + error.code); if (error.code === Fingerprint.BIOMETRIC_SECRET_NOT_FOUND) { console.log("No secret registered yet"); // Prompt user to register showRegistrationScreen(); } else if (error.code === Fingerprint.BIOMETRIC_DISMISSED) { console.log("User cancelled authentication"); } else if (error.code === Fingerprint.BIOMETRIC_LOCKED_OUT_PERMANENT) { alert("Biometric authentication locked. Please use device password."); } } ); // Load API token with full error handling Fingerprint.loadBiometricSecret( { title: "Access Required", description: "Authenticate to load your API credentials", disableBackup: true, cancelButtonTitle: "Cancel" }, function(apiToken) { console.log("API token retrieved"); // Configure HTTP client with token setAuthorizationHeader('Bearer ' + apiToken); // Make authenticated API calls fetch('https://api.example.com/user/profile', { headers: { 'Authorization': 'Bearer ' + apiToken } }) .then(response => response.json()) .then(data => { console.log('Profile loaded:', data); displayUserProfile(data); }) .catch(error => { console.error('API call failed:', error); }); }, function(error) { console.error("Could not load API token: " + error.message); // Handle specific error scenarios switch(error.code) { case Fingerprint.BIOMETRIC_SECRET_NOT_FOUND: console.log("No token registered - starting registration flow"); registerNewApiToken(); break; case Fingerprint.BIOMETRIC_AUTHENTICATION_FAILED: console.log("Authentication failed - incrementing attempt counter"); incrementFailedAttempts(); break; case Fingerprint.BIOMETRIC_LOCKED_OUT: console.log("Temporarily locked out"); showTemporaryLockoutMessage(); break; default: console.log("Unhandled error - using fallback authentication"); showPasswordLoginScreen(); } } ); // Load encryption key for decrypting local data Fingerprint.loadBiometricSecret( { description: "Unlock your encrypted data", confirmationRequired: true }, function(encryptionKey) { console.log("Encryption key retrieved"); // Decrypt local database try { var decryptedData = decryptLocalDatabase(encryptionKey); console.log("Database unlocked successfully"); // Access decrypted data loadUserPreferences(decryptedData); displayDashboard(decryptedData); } catch (decryptError) { console.error("Decryption failed:", decryptError); alert("Could not decrypt local data"); } }, function(error) { console.error("Could not load encryption key: " + error.message); // Cannot access encrypted data without the key showDataUnavailableMessage(); } ); ``` -------------------------------- ### Check Biometric Login Enabled Status Source: https://context7.com/niklasmerz/cordova-plugin-fingerprint-aio/llms.txt Verifies whether biometric-based login has been previously configured by checking localStorage flag. Returns boolean indicating if user has registered biometric credentials for automatic login. ```javascript isBiometricLoginEnabled: function() { return localStorage.getItem('biometric_enabled') === 'true'; } ``` -------------------------------- ### Check Biometric Availability using JavaScript Source: https://context7.com/niklasmerz/cordova-plugin-fingerprint-aio/llms.txt Checks if biometric authentication is available on the device and returns the type of biometric authenticator present ('finger', 'face', or 'biometric'). It can also take optional parameters like 'allowBackup' and 'requireStrongBiometrics'. Errors are handled with specific codes like BIOMETRIC_UNAVAILABLE or BIOMETRIC_NOT_ENROLLED. ```javascript Fingerprint.isAvailable( function(result) { // result can be: 'finger', 'face', or 'biometric' // 'finger' = fingerprint sensor (Android < P or iOS TouchID) // 'face' = Face ID (iPhone X+) // 'biometric' = Android P+ generic biometric console.log('Biometric type available: ' + result); document.getElementById('status').innerHTML = 'Ready to authenticate'; }, function(error) { // Error codes: BIOMETRIC_UNAVAILABLE, BIOMETRIC_NOT_ENROLLED, etc. console.error('Biometric not available: ' + error.message); console.error('Error code: ' + error.code); // Handle specific error codes if (error.code === Fingerprint.BIOMETRIC_NOT_ENROLLED) { alert('Please enroll a fingerprint in device settings'); } else if (error.code === Fingerprint.BIOMETRIC_HARDWARE_NOT_SUPPORTED) { alert('This device does not support biometric authentication'); } } ); // Check with optional parameters Fingerprint.isAvailable( function(result) { console.log('Biometric or backup authentication available: ' + result); }, function(error) { console.error('Authentication not available: ' + error.message); }, { allowBackup: true, // iOS only: check for passcode backup option requireStrongBiometrics: true // Android only: require Class 3 biometrics } ); ``` -------------------------------- ### Register Biometric Secret with Authentication - Cordova JavaScript Source: https://github.com/niklasmerz/cordova-plugin-fingerprint-aio/blob/master/README.md Registers a biometric secret by calling Fingerprint.registerBiometricSecret() with configuration options and callbacks. This method may display an authentication prompt and encrypts the provided secret using biometric data. Success callback confirms registration, error callback handles authentication failures with error messages. ```javascript Fingerprint.registerBiometricSecret({ description: "Some biometric description", secret: "my-super-secret", invalidateOnEnrollment: true, disableBackup: true, // always disabled on Android }, successCallback, errorCallback); function successCallback(){ alert("Authentication successful"); } function errorCallback(error){ alert("Authentication invalid " + error.message); } ``` -------------------------------- ### Register Biometric Secret with Cordova Fingerprint Plugin Source: https://context7.com/niklasmerz/cordova-plugin-fingerprint-aio/llms.txt Encrypts and stores a secret (e.g., token, key) using biometric authentication. It handles success and error callbacks, allowing for options like invalidating the secret on biometric enrollment changes or disabling backup. This function is crucial for securing sensitive data within a mobile application. ```javascript // Register a simple secret Fingerprint.registerBiometricSecret( { description: "Authenticate to save your encryption key", secret: "my-secret-token-12345", invalidateOnEnrollment: true, // Delete secret if biometrics change disableBackup: true // Always disabled on Android for security }, function() { console.log("Secret registered successfully"); console.log("Secret is encrypted and stored in secure hardware"); alert("Your authentication key has been securely saved"); }, function(error) { console.error("Failed to register secret: " + error.message); if (error.code === Fingerprint.BIOMETRIC_AUTHENTICATION_FAILED) { alert("Authentication failed. Secret not saved."); } } ); // Register API token with full configuration var apiToken = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9"; Fingerprint.registerBiometricSecret( { title: "Secure API Access", subtitle: "Biometric Protection", description: "Authenticate to encrypt your API token", secret: apiToken, invalidateOnEnrollment: true, // Re-register if user adds new fingerprint disableBackup: true, cancelButtonTitle: "Skip for now" }, function() { console.log("API token encrypted and stored"); // Store a flag that secret is registered localStorage.setItem('biometric_secret_registered', 'true'); localStorage.setItem('registration_date', new Date().toISOString()); }, function(error) { console.error("Registration failed: " + error.message); localStorage.setItem('biometric_secret_registered', 'false'); // Handle key invalidation errors if (error.code === Fingerprint.BIOMETRIC_UNKNOWN_ERROR) { alert("Could not register secret. Please try again."); } } ); // Register encryption key for secure storage var encryptionKey = generateRandomKey(); // Your key generation function Fingerprint.registerBiometricSecret( { description: "Secure your local data encryption key", secret: encryptionKey, invalidateOnEnrollment: false, // Keep secret even if biometrics change confirmationRequired: false // Android: don't require explicit confirmation }, function() { console.log("Encryption key secured"); // Now you can encrypt local data with this key encryptLocalDatabase(encryptionKey); }, function(error) { console.error("Could not secure encryption key: " + error.message); // Fall back to alternative security method usePasswordBasedEncryption(); } ); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.