face_liveness_detector 0.2.8
A Flutter plugin for AWS Rekognition Face Liveness detection.
AWS Rekognition Face Liveness Plugin for Flutter
A Flutter plugin for AWS Rekognition Face Liveness detection, allowing secure face biometric verification using AWS's Rekognition service. This package provides a bridge to the native AWS Amplify Face Liveness SDKs for both Android and iOS.
Features
- Perform face liveness detection using AWS Rekognition
- Native integration with AWS Amplify Face Liveness SDKs
- Support for both iOS and Android platforms
- Simple Flutter widget interface for easy integration
- Uses AWS Amplify for authentication and credentials
Requirements
- AWS account with Rekognition access
- AWS Amplify configuration for authentication
- Backend service to create Face Liveness sessions
Getting Started
Installation
Add this package to your pubspec.yaml:
dependencies:
face_liveness_detector: ^0.1.0
⚙️ Setup PreRequisite
Before using the package, you need to configure Amplify in your project. Follow these steps:
1️⃣ Set Up Amplify
Complete the Amplify Quickstart and Step 1: Configure Auth before proceeding.
2️⃣ Configure Authentication
Android
- Add the Amplify configuration file to your project:
- Place
amplifyconfiguration.jsoninandroid/app/src/main/res/raw/
- Place
Update android/app/build.gradle:
android { compileSdkVersion 35
defaultConfig {
minSdkVersion 24
}
} Ensure that the MainActivity class extends FlutterFragmentActivity instead of FlutterActivity: import io.flutter.embedding.android.FlutterFragmentActivity
class MainActivity : FlutterFragmentActivity() {}
####iOS Add the Amplify configuration files to your project:
Place amplifyconfiguration.json and awsconfiguration.json in the ios directory. Open Xcode and manually add these files to your project to ensure they are recognized.
Update your ios/Podfile:
platform :ios, '13.0' use_frameworks! Run: cd ios pod install cd .. 3️⃣ Grant Camera Permissions Ensure you request camera access in both platforms:
Android Add the following permission in AndroidManifest.xml:
Android Setup
-
Make sure you have the AWS Amplify configuration set up properly in your Android project.
-
Add the following dependencies to your
android/app/build.gradle:
dependencies {
// AWS Amplify Face Liveness SDK
implementation 'com.amplifyframework.ui:liveness:1.4.0'
implementation 'com.amplifyframework:core:2.27.0'
implementation 'com.amplifyframework:aws-auth-cognito:2.27.0'
}
iOS Setup
Important: The AWS Amplify Face Liveness SDK is distributed through Swift Package Manager, not CocoaPods. You need to add the dependencies manually to your iOS project.
Step 1: Add Swift Package Dependencies
- Open your iOS project in Xcode (
ios/Runner.xcworkspace) - Go to File > Add Package Dependencies...
- Add the following packages:
AWS Amplify Swift:
- URL:
https://github.com/aws-amplify/amplify-swift - Version:
2.46.1or later - Select these products:
AmplifyAWSCognitoAuthPlugin
AWS Amplify UI Liveness:
- URL:
https://github.com/aws-amplify/amplify-ui-swift-liveness - Version:
1.3.5or later - Select the
FaceLivenessproduct
Step 2: Configure Amplify
Make sure you have the AWS Amplify configuration set up properly in your iOS project as described in the AWS Amplify documentation.
Step 3: Add Configuration Files
Place your amplifyconfiguration.json and awsconfiguration.json files in the iOS directory and add them to your Xcode project.
Usage
1. Initialize AWS Amplify
First, make sure you initialize Amplify in your app as described in the AWS Amplify documentation.
2. Create a Face Liveness Session
You'll need a backend service to create a Face Liveness session. Here's an example of how to get a session ID from your backend:
Future<Map<String, String>> getSessionFromBackend() async {
final response = await http.post(
Uri.parse('https://your-backend-url.com/face-liveness/create-session'),
headers: {'Content-Type': 'application/json'},
);
if (response.statusCode == 201) {
final data = jsonDecode(response.body);
return {
'sessionId': data['sessionId'],
'region': data['region'] ?? 'us-east-1',
};
}
throw Exception('Failed to get session');
}
3. Use the FaceLivenessDetector Widget
import 'package:face_liveness_detector/face_liveness_detector.dart';
// ...
FaceLivenessDetector(
sessionId: sessionId,
region: 'us-east-1',
onComplete: () {
print('Face liveness detection completed successfully');
// Fetch results from your backend
},
onError: (errorCode) {
print('Face liveness detection error: $errorCode');
},
)
4. Fetch Liveness Results
After the liveness check is complete, you should verify the results with your backend:
Future<Map<String, dynamic>> fetchLivenessResults({
required String sessionId,
}) async {
final response = await http.get(
Uri.parse('https://your-backend-url.com/face-liveness/results?sessionId=$sessionId'),
headers: {'Content-Type': 'application/json'},
);
if (response.statusCode == 200) {
return jsonDecode(response.body);
}
throw Exception('Failed to fetch liveness results');
}
Example
Check the example directory for a complete example app.
Backend Implementation
You'll need a backend service that can:
- Create Face Liveness sessions using the AWS SDK
- Fetch Face Liveness results after completion
A simple implementation using Spring Boot is provided in the example directory.
License
This project is licensed under the MIT License - see the LICENSE file for details.