You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
2.2 KiB
Dart
70 lines
2.2 KiB
Dart
import 'dart:io';
|
|
|
|
import 'package:device_info_plus/device_info_plus.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:huawei_fido/huawei_fido.dart';
|
|
import 'package:local_auth/local_auth.dart';
|
|
import 'package:local_auth_android/local_auth_android.dart';
|
|
import 'package:local_auth_darwin/types/auth_messages_ios.dart';
|
|
import 'package:mc_common_app/main.dart';
|
|
|
|
abstract class CommonAuthServices {
|
|
Future<bool> authenticate();
|
|
|
|
Future<List<BiometricType>> getAvailBio();
|
|
}
|
|
|
|
class CommonAuthImp implements CommonAuthServices {
|
|
final LocalAuthentication localAuth = LocalAuthentication();
|
|
|
|
Future<bool> authenticate() async {
|
|
try {
|
|
final availableBiometrics = await localAuth.getAvailableBiometrics();
|
|
if (availableBiometrics == null || availableBiometrics.isEmpty) {
|
|
return false;
|
|
}
|
|
|
|
final didAuthenticate = await localAuth.authenticate(
|
|
localizedReason: "Scan your fingerprint or face ID to authenticate",
|
|
options: const AuthenticationOptions(
|
|
stickyAuth: false,
|
|
biometricOnly: true,
|
|
sensitiveTransaction: true,
|
|
useErrorDialogs: true,
|
|
),
|
|
authMessages: [
|
|
const AndroidAuthMessages(
|
|
cancelButton: 'Cancel',
|
|
biometricHint: 'Please use your fingerprint or face ID',
|
|
goToSettingsButton: 'Settings',
|
|
goToSettingsDescription: 'Please set up your Touch ID.',
|
|
),
|
|
const IOSAuthMessages(
|
|
cancelButton: 'Cancel',
|
|
goToSettingsButton: 'Settings',
|
|
goToSettingsDescription: 'Please set up your Touch ID.',
|
|
lockOut: 'Please reenable your Touch ID',
|
|
),
|
|
],
|
|
);
|
|
|
|
return didAuthenticate;
|
|
} on PlatformException catch (e) {
|
|
print('Error during authentication: $e');
|
|
return false;
|
|
}
|
|
}
|
|
|
|
Future<List<BiometricType>> getAvailBio() async {
|
|
return await localAuth.getAvailableBiometrics();
|
|
}
|
|
|
|
Future<void> getHuaweiAuth() async {
|
|
DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
|
|
AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo;
|
|
// if (androidInfo.brand == "HUAWEI") {
|
|
// huawei.canAuth();
|
|
// }
|
|
}
|
|
}
|