A flutter plugin that allows access to Local Authentication / Biometrics on iOS, macOS, Linux and Android (Windows Hello is a work in progress).
- Features
- Changelog
- Usage 3.1. Initialization 3.2. Localization 3.3. Querying support and performing Local Authentication
- Considerations 4.1. canAuthenticate 4.2. Supported Platforms
- Next Steps
- Contribution
- License
- Code of Conduct
-
Detects if biometric authentication can be done in the current platform (canAuthenticate).
-
Triggers platform's native authentication for the current user (authenticate).
-
Read/Write macOS/iOS touchIDAuthenticationAllowableReuseDuration value
-
Localized messages for iOS, macOS and Android
Initialize an instance of the plugin, which requires no input parameters.
final _flutterLocalAuthenticationPlugin = FlutterLocalAuthentication();
At any time a localization model can be applied. The latests applied is used by the plugin when the local authentication is performed.
final localization = LocalizationModel(
promptDialogTitle: "title for dialog",
promptDialogReason: "reason for prompting biometric",
cancelButtonTitle: "cancel"
);
_flutterLocalAuthenticationPlugin.setLocalizationModel(localization);
Two functions are available for the core feature of this library:
- canAuthenticate
- authenticate
Depending on each platform the behaviour of canAuthenticate can differ.
bool canAuthenticate;
try {
// Query suppor for Local Authentication
canAuthenticate = await _flutterLocalAuthenticationPlugin.canAuthenticate();
// Setup TouchID Allowable Reuse duration
// It works only in iOS and macOS, but it's safe to call it even on other platforms.
await _flutterLocalAuthenticationPlugin.setTouchIDAuthenticationAllowableReuseDuration(30);
} on Exception catch (error) {
debugPrint("Exception checking support. $error");
canAuthenticate = false;
}
if (canAuthenticate) {
// Perform Local Authentication
_flutterLocalAuthenticationPlugin.authenticate().then((authenticated) {
String result = 'Authenticated: $authenticated';
// handle result
}).catchError((error) {
String result = 'Exception: $error';
// handle error
});
}
The function canAuthenticate will return true in the following scenarios.
-
Android: true if BiometricManager returns that it can authenticate with one of the following allowed authenticators:
- BiometricManager.Authenticators.BIOMETRIC_STRONG
- BiometricManager.Authenticators.BIOMETRIC_WEAK
- BiometricManager.Authenticators.DEVICE_CREDENTIAL
-
iOS: true if LAContext.supportsLocalAuthentication returns true for device policy:
- deviceOwnerAuthenticationWithBiometrics
-
macOS: true if LAContext.supportsLocalAuthentication returns true for device policy:
- deviceOwnerAuthentication
-
linux: true if fprintd-verify is installed and user can execute it.
- iOS 12 or newer
- macOS 10.12.2 or newer
- Linux (requires libfprint)
- Android 6.0 or newer
- Add support to Windows Hello