Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -856,11 +856,13 @@
"@scanBiometricHint": {},
"scanLibrary": "Scan library",
"@scanLibrary": {},
"scanYourFingerprintToAuthenticate": "Scan your fingerprint to authenticate {user}",
"@scanYourFingerprintToAuthenticate": {
"authenticateWithBiometrics": "Use biometrics to authenticate {user}",
"@authenticateWithBiometrics": {
"description": "Prompt shown to the user when biometric authentication is requested",
"placeholders": {
"user": {
"type": "String"
"type": "String",
"example": "Jane"
}
}
},
Expand Down
6 changes: 5 additions & 1 deletion lib/screens/shared/authenticate_button_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ Future<void> showAuthOptionsDialogue(
setMethod.call(currentUser.copyWith(authMethod: method));
break;
case Authentication.biometrics:
final authenticated = await AuthService.authenticateUser(context, currentUser);
final authenticated = await AuthService.authenticateUser(
context,
currentUser,
sensitiveTransaction: true,
);
if (authenticated) {
setMethod.call(currentUser.copyWith(authMethod: method));
} else if (context.mounted) {
Expand Down
23 changes: 20 additions & 3 deletions lib/util/auth_service.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// ignore_for_file: depend_on_referenced_packages

import 'dart:developer';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

Expand All @@ -11,15 +13,21 @@ import 'package:fladder/models/account_model.dart';
import 'package:fladder/util/localization_helper.dart';

class AuthService {
static Future<bool> authenticateUser(BuildContext context, AccountModel user) async {
static Future<bool> authenticateUser(
BuildContext context,
AccountModel user, {
bool stickyAuth = true,
bool sensitiveTransaction = false,
}) async {
final LocalAuthentication localAuthentication = LocalAuthentication();
bool isAuthenticated = false;
bool isBiometricSupported = await localAuthentication.isDeviceSupported();

if (isBiometricSupported) {
try {
isAuthenticated = await localAuthentication.authenticate(
localizedReason:
context.localized.scanYourFingerprintToAuthenticate("(${user.name} - ${user.credentials.serverName})"),
context.localized.authenticateWithBiometrics("(${user.name} - ${user.credentials.serverName})"),
authMessages: <AuthMessages>[
AndroidAuthMessages(
signInTitle: 'Fladder',
Expand All @@ -29,8 +37,17 @@ class AuthService {
cancelButton: context.localized.cancel,
)
],
options: AuthenticationOptions(
stickyAuth: stickyAuth,
sensitiveTransaction: sensitiveTransaction,
),
);
} on PlatformException catch (_) {}
} on PlatformException catch (e) {
debugPrint('Error during authentication: $e');
}
} else {
log('Biometric authentication is not supported on this device.');
return false;
}
return isAuthenticated;
}
Expand Down
Loading