https://github.com/eaceto/flutter_local_authentication
A flutter plugin that allows access to Local Authentication / Biometrics on iOS, macOS, Linux and Android (Windows Hello is a work in progress).
https://github.com/eaceto/flutter_local_authentication
android biometric biometric-authentication biometric-identification dart fingerprint flutter ios local-authentication macos password plugin security
Last synced: 10 months ago
JSON representation
A flutter plugin that allows access to Local Authentication / Biometrics on iOS, macOS, Linux and Android (Windows Hello is a work in progress).
- Host: GitHub
- URL: https://github.com/eaceto/flutter_local_authentication
- Owner: eaceto
- License: mit
- Created: 2021-03-05T20:22:04.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2024-02-14T10:44:44.000Z (over 2 years ago)
- Last Synced: 2025-05-07T07:07:12.362Z (about 1 year ago)
- Topics: android, biometric, biometric-authentication, biometric-identification, dart, fingerprint, flutter, ios, local-authentication, macos, password, plugin, security
- Language: C++
- Homepage: https://eaceto.dev
- Size: 401 KB
- Stars: 4
- Watchers: 2
- Forks: 10
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Local Authentication
A flutter plugin that allows access to Local Authentication / Biometrics on iOS, macOS, Linux and Android (Windows Hello is a work in progress).
1. [Features](#features)
2. [Changelog](CHANGELOG.md)
3. [Usage](#usage)
3.1. [Initialization](#initialization)
3.2. [Localization](#localization)
3.3. [Querying support and performing Local Authentication](#querying-support-and-performing-local-authentication)
4. [Considerations](#considerations)
4.1. [canAuthenticate](#canauthenticate)
4.2. [Supported Platforms](#supported-platforms)
5. [Next Steps](#next-steps)
6. [Contribution](CONTRIBUTING.md)
7. [License](LICENSE)
8. [Code of Conduct](CODE_OF_CONDUCT.md)
---
## Features
- 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
## Usage
### Initialization
Initialize an instance of the plugin, which requires no input parameters.
```Dart
final _flutterLocalAuthenticationPlugin = FlutterLocalAuthentication();
```
### Localization
At any time a localization model can be applied. The latests applied is used by the plugin when the local authentication is performed.
```Dart
final localization = LocalizationModel(
promptDialogTitle: "title for dialog",
promptDialogReason: "reason for prompting biometric",
cancelButtonTitle: "cancel"
);
_flutterLocalAuthenticationPlugin.setLocalizationModel(localization);
```
### Querying support and performing Local Authentication
Two functions are available for the core feature of this library:
- canAuthenticate
- authenticate
Depending on each platform the behaviour of _canAuthenticate_ can differ.
```Dart
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
});
}
```
## Considerations
### canAuthenticate
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.
### Supported platforms
- iOS 12 or newer
- macOS 10.12.2 or newer
- Linux (requires libfprint)
- Android 6.0 or newer
## Next Steps
- Add support to Windows Hello