Skip to content

Commit

Permalink
Update BiometricPrompt, fix fallback on Android, add face support on …
Browse files Browse the repository at this point in the history
…android

- The new BiometricPrompt API only tells you if a device has a fingerprint sensor, not if fingerprints are registered. Update the code to fallback to PIN authentication if the biometric auth fails
  • Loading branch information
bbedward committed Oct 24, 2019
1 parent 406f6f7 commit 8cc7cd3
Show file tree
Hide file tree
Showing 10 changed files with 271 additions and 166 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -381,20 +381,16 @@ class _ChangingNameSheetState extends State<ChangingNameSheet> {
}
}

Future<bool> authenticate() async {
String message = AppLocalization.of(context)
.authenticateToChangeNameParagraph
.replaceAll("%1", widget.newName.toString());
// Authenticate
AuthUtil authUtil = AuthUtil();
if (await authUtil.useBiometrics()) {
// Biometric auth
bool authenticated = await authUtil.authenticateWithBiometrics(message);
if (authenticated) {
HapticUtil.fingerprintSucess();
}
return authenticated;
} else {
Future<bool> _authenticateBiometrics(AuthUtil authUtil, String message) async {
// Biometric auth
bool authenticated = await authUtil.authenticateWithBiometrics(message);
if (authenticated) {
HapticUtil.fingerprintSucess();
}
return authenticated;
}

Future<bool> _authenticatePin(String message) async {
String expectedPin = await sl.get<Vault>().getPin();
bool result = await Navigator.of(context)
.push(MaterialPageRoute<bool>(builder: (BuildContext context) {
Expand All @@ -408,7 +404,24 @@ class _ChangingNameSheetState extends State<ChangingNameSheet> {
);
}));
await Future.delayed(Duration(milliseconds: 200));
return result != null && result;
return result != null && result;
}

Future<bool> authenticate() async {
String message = AppLocalization.of(context)
.authenticateToChangeNameParagraph
.replaceAll("%1", widget.newName.toString());
// Authenticate
AuthUtil authUtil = AuthUtil();
if (await authUtil.useBiometrics()) {
// Biometric auth
try {
return await _authenticateBiometrics(authUtil, message);
} catch (e) {
return await _authenticatePin(message);
}
} else {
return await _authenticatePin(message);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -377,18 +377,16 @@ class _DelistingForSaleSheetState extends State<DelistingForSaleSheet> {
}
}

Future<bool> authenticate() async {
String message = "Authenticate to delist account for sale";
// Authenticate
AuthUtil authUtil = AuthUtil();
if (await authUtil.useBiometrics()) {
// Biometric auth
bool authenticated = await authUtil.authenticateWithBiometrics(message);
if (authenticated) {
HapticUtil.fingerprintSucess();
}
return authenticated;
} else {
Future<bool> _authenticateBiometrics(AuthUtil authUtil, String message) async {
// Biometric auth
bool authenticated = await authUtil.authenticateWithBiometrics(message);
if (authenticated) {
HapticUtil.fingerprintSucess();
}
return authenticated;
}

Future<bool> _authenticatePin(String message) async {
String expectedPin = await sl.get<Vault>().getPin();
bool result = await Navigator.of(context)
.push(MaterialPageRoute<bool>(builder: (BuildContext context) {
Expand All @@ -402,7 +400,22 @@ class _DelistingForSaleSheetState extends State<DelistingForSaleSheet> {
);
}));
await Future.delayed(Duration(milliseconds: 200));
return result != null && result;
return result != null && result;
}

Future<bool> authenticate() async {
String message = AppLocalization.of(context).authenticateToDelistParagraph;
// Authenticate
AuthUtil authUtil = AuthUtil();
if (await authUtil.useBiometrics()) {
// Biometric auth
try {
return await _authenticateBiometrics(authUtil, message);
} catch (e) {
return await _authenticatePin(message);
}
} else {
return await _authenticatePin(message);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -486,18 +486,16 @@ class _ListingForSaleSheetState extends State<ListingForSaleSheet> {
}
}

Future<bool> authenticate() async {
String message = AppLocalization.of(context).authenticateToListForSaleParagraph;
// Authenticate
AuthUtil authUtil = AuthUtil();
if (await authUtil.useBiometrics()) {
// Biometric auth
bool authenticated = await authUtil.authenticateWithBiometrics(message);
if (authenticated) {
HapticUtil.fingerprintSucess();
}
return authenticated;
} else {
Future<bool> _authenticateBiometrics(AuthUtil authUtil, String message) async {
// Biometric auth
bool authenticated = await authUtil.authenticateWithBiometrics(message);
if (authenticated) {
HapticUtil.fingerprintSucess();
}
return authenticated;
}

Future<bool> _authenticatePin(String message) async {
String expectedPin = await sl.get<Vault>().getPin();
bool result = await Navigator.of(context)
.push(MaterialPageRoute<bool>(builder: (BuildContext context) {
Expand All @@ -511,7 +509,22 @@ class _ListingForSaleSheetState extends State<ListingForSaleSheet> {
);
}));
await Future.delayed(Duration(milliseconds: 200));
return result != null && result;
return result != null && result;
}

Future<bool> authenticate() async {
String message = AppLocalization.of(context).authenticateToListForSaleParagraph;
// Authenticate
AuthUtil authUtil = AuthUtil();
if (await authUtil.useBiometrics()) {
// Biometric auth
try {
return await _authenticateBiometrics(authUtil, message);
} catch (e) {
return await _authenticatePin(message);
}
} else {
return await _authenticatePin(message);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -541,19 +541,16 @@ class _CreatingPrivateSaleSheetState extends State<CreatingPrivateSaleSheet> {
}
}

Future<bool> authenticate() async {
String message =
AppLocalization.of(context).authenticateToCreatePrivateSaleParagraph;
// Authenticate
AuthUtil authUtil = AuthUtil();
if (await authUtil.useBiometrics()) {
// Biometric auth
bool authenticated = await authUtil.authenticateWithBiometrics(message);
if (authenticated) {
HapticUtil.fingerprintSucess();
}
return authenticated;
} else {
Future<bool> _authenticateBiometrics(AuthUtil authUtil, String message) async {
// Biometric auth
bool authenticated = await authUtil.authenticateWithBiometrics(message);
if (authenticated) {
HapticUtil.fingerprintSucess();
}
return authenticated;
}

Future<bool> _authenticatePin(String message) async {
String expectedPin = await sl.get<Vault>().getPin();
bool result = await Navigator.of(context)
.push(MaterialPageRoute<bool>(builder: (BuildContext context) {
Expand All @@ -567,7 +564,23 @@ class _CreatingPrivateSaleSheetState extends State<CreatingPrivateSaleSheet> {
);
}));
await Future.delayed(Duration(milliseconds: 200));
return result != null && result;
return result != null && result;
}

Future<bool> authenticate() async {
String message =
AppLocalization.of(context).authenticateToCreatePrivateSaleParagraph;
// Authenticate
AuthUtil authUtil = AuthUtil();
if (await authUtil.useBiometrics()) {
// Biometric auth
try {
return await _authenticateBiometrics(authUtil, message);
} catch (e) {
return await _authenticatePin(message);
}
} else {
return await _authenticatePin(message);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -384,19 +384,16 @@ class _TransferringAccountSheetState extends State<TransferringAccountSheet> {
}
}

Future<bool> authenticate() async {
String message =
AppLocalization.of(context).authenticateToTransferParagraph;
// Authenticate
AuthUtil authUtil = AuthUtil();
if (await authUtil.useBiometrics()) {
// Biometric auth
bool authenticated = await authUtil.authenticateWithBiometrics(message);
if (authenticated) {
HapticUtil.fingerprintSucess();
}
return authenticated;
} else {
Future<bool> _authenticateBiometrics(AuthUtil authUtil, String message) async {
// Biometric auth
bool authenticated = await authUtil.authenticateWithBiometrics(message);
if (authenticated) {
HapticUtil.fingerprintSucess();
}
return authenticated;
}

Future<bool> _authenticatePin(String message) async {
String expectedPin = await sl.get<Vault>().getPin();
bool result = await Navigator.of(context)
.push(MaterialPageRoute<bool>(builder: (BuildContext context) {
Expand All @@ -410,7 +407,23 @@ class _TransferringAccountSheetState extends State<TransferringAccountSheet> {
);
}));
await Future.delayed(Duration(milliseconds: 200));
return result != null && result;
return result != null && result;
}

Future<bool> authenticate() async {
String message =
AppLocalization.of(context).authenticateToTransferParagraph;
// Authenticate
AuthUtil authUtil = AuthUtil();
if (await authUtil.useBiometrics()) {
// Biometric auth
try {
return await _authenticateBiometrics(authUtil, message);
} catch (e) {
return await _authenticatePin(message);
}
} else {
return await _authenticatePin(message);
}
}
}
43 changes: 28 additions & 15 deletions lib/ui/account/send/sending_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -666,20 +666,16 @@ class _SendingSheetState extends State<SendingSheet> {
}
}

Future<bool> authenticate() async {
String message = AppLocalization.of(context)
.authenticateToSendParagraph
.replaceAll("%1", widget.amount);
// Authenticate
AuthUtil authUtil = AuthUtil();
if (await authUtil.useBiometrics()) {
// Biometric auth
bool authenticated = await authUtil.authenticateWithBiometrics(message);
if (authenticated) {
HapticUtil.fingerprintSucess();
}
return authenticated;
} else {
Future<bool> _authenticateBiometrics(AuthUtil authUtil, String message) async {
// Biometric auth
bool authenticated = await authUtil.authenticateWithBiometrics(message);
if (authenticated) {
HapticUtil.fingerprintSucess();
}
return authenticated;
}

Future<bool> _authenticatePin(String message) async {
String expectedPin = await sl.get<Vault>().getPin();
bool result = await Navigator.of(context)
.push(MaterialPageRoute<bool>(builder: (BuildContext context) {
Expand All @@ -693,7 +689,24 @@ class _SendingSheetState extends State<SendingSheet> {
);
}));
await Future.delayed(Duration(milliseconds: 200));
return result != null && result;
return result != null && result;
}

Future<bool> authenticate() async {
String message = AppLocalization.of(context)
.authenticateToSendParagraph
.replaceAll("%1", widget.amount);
// Authenticate
AuthUtil authUtil = AuthUtil();
if (await authUtil.useBiometrics()) {
// Biometric auth
try {
return await _authenticateBiometrics(authUtil, message);
} catch (e) {
return await _authenticatePin(message);
}
} else {
return await _authenticatePin(message);
}
}
}
Loading

0 comments on commit 8cc7cd3

Please sign in to comment.