| Crates.io | tauri-plugin-biometry |
| lib.rs | tauri-plugin-biometry |
| version | 0.2.4 |
| created_at | 2025-09-05 15:24:44.799122+00 |
| updated_at | 2025-09-15 13:27:42.845704+00 |
| description | A Tauri v2 plugin for biometric authentication (Touch ID, Face ID, fingerprint) on Android, macOS, iOS and Windows. |
| homepage | |
| repository | https://github.com/Choochmeque/tauri-plugin-biometry |
| max_upload_size | |
| id | 1825712 |
| size | 276,463 |
A Tauri plugin for biometric authentication (Touch ID, Face ID, Windows Hello, fingerprint, etc.) with support for macOS, Windows, iOS, and Android.
Add the plugin to your Cargo.toml:
[dependencies]
tauri-plugin-biometry = "0.2"
Install the JavaScript/TypeScript API:
npm install @choochmeque/tauri-plugin-biometry-api
# or
yarn add @choochmeque/tauri-plugin-biometry-api
# or
pnpm add @choochmeque/tauri-plugin-biometry-api
Register the plugin in your Tauri app:
fn main() {
tauri::Builder::default()
.plugin(tauri_plugin_biometry::init())
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
Add NSFaceIDUsageDescription to your Info.plist:
<key>NSFaceIDUsageDescription</key>
<string>This app uses Face ID to secure your data</string>
The plugin automatically handles the necessary permissions for Android.
Configure the plugin permissions in your capabilities/default.json:
{
"permissions": {
["biometry:default"]
}
}
import { checkStatus } from '@choochmeque/tauri-plugin-biometry-api';
const status = await checkStatus();
console.log('Biometry available:', status.isAvailable);
console.log('Biometry type:', status.biometryType); // 0: None, 1: TouchID, 2: FaceID, 3: Iris, 4: Auto (Windows Hello)
if (status.error) {
console.error('Error:', status.error);
console.error('Error code:', status.errorCode);
}
import { authenticate } from '@choochmeque/tauri-plugin-biometry-api';
try {
await authenticate('Please authenticate to continue', {
allowDeviceCredential: true,
cancelTitle: 'Cancel',
fallbackTitle: 'Use Passcode',
title: 'Authentication Required',
subtitle: 'Access your secure data',
confirmationRequired: false
});
console.log('Authentication successful');
} catch (error) {
console.error('Authentication failed:', error);
}
import { setData, getData, hasData, removeData } from '@choochmeque/tauri-plugin-biometry-api';
// Store data with biometric protection
await setData({
domain: 'com.myapp',
name: 'api_key',
data: 'secret-api-key-123'
});
// Check if data exists
const exists = await hasData({
domain: 'com.myapp',
name: 'api_key'
});
// Retrieve data (will prompt for biometric authentication)
if (exists) {
const response = await getData({
domain: 'com.myapp',
name: 'api_key',
reason: 'Access your API key'
});
console.log('Retrieved data:', response.data);
}
// Remove data
await removeData({
domain: 'com.myapp',
name: 'api_key'
});
enum BiometryType {
None = 0,
TouchID = 1,
FaceID = 2,
Iris = 3,
Auto = 4 // Windows Hello (auto-detects available biometry)
}
interface Status {
isAvailable: boolean;
biometryType: BiometryType;
error?: string;
errorCode?: string;
}
interface AuthOptions {
allowDeviceCredential?: boolean; // Allow fallback to device passcode
cancelTitle?: string; // iOS/Android: Cancel button text
fallbackTitle?: string; // iOS only: Fallback button text
title?: string; // Android only: Dialog title
subtitle?: string; // Android only: Dialog subtitle
confirmationRequired?: boolean; // Android only: Require explicit confirmation
}
checkStatus(): Promise<Status>Checks if biometric authentication is available on the device.
authenticate(reason: string, options?: AuthOptions): Promise<void>Prompts the user for biometric authentication.
hasData(options: DataOptions): Promise<boolean>Checks if secure data exists for the given domain and name.
getData(options: GetDataOptions): Promise<DataResponse>Retrieves secure data after biometric authentication.
setData(options: SetDataOptions): Promise<void>Stores data with biometric protection.
removeData(options: RemoveDataOptions): Promise<void>Removes secure data.
NSFaceIDUsageDescription in Info.plist for Face IDfallbackTitletitle and subtitleconfirmationRequired for additional securitysetData will prompt for Windows Hello authentication when storing dataBiometryType.Auto as it uses Windows Hello's automatic selectionCommon error codes returned by the plugin:
userCancel - User cancelled the authenticationauthenticationFailed - Authentication failed (wrong biometric)biometryNotAvailable - Biometry is not available on devicebiometryNotEnrolled - No biometric data is enrolledbiometryLockout - Too many failed attempts, biometry is lockedsystemCancel - System cancelled the operation (device busy)appCancel - Application cancelled the operationinvalidContext - Invalid authentication contextnotInteractive - Non-interactive authentication not allowedpasscodeNotSet - Device passcode not setuserFallback - User chose to use fallback authenticationitemNotFound - Keychain item not found (macOS/iOS)authenticationRequired - Authentication required but UI interaction not allowedkeychainError - Generic keychain operation errorinternalError - Internal plugin errornotSupported - Operation not supported on this platformContributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License.
Built with Tauri - Build smaller, faster and more secure desktop applications with a web frontend.