Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[local_auth] canCheckBiometrics returns false when Face ID permission isn't granted #160083

Open
MohsinIkram-Auxilium opened this issue Dec 11, 2024 · 12 comments · May be fixed by flutter/packages#8348
Labels
p: local_auth Plugin for local authentification package flutter/packages repository. See also p: labels. platform-ios iOS applications specifically team-ios Owned by iOS platform team

Comments

@MohsinIkram-Auxilium
Copy link

MohsinIkram-Auxilium commented Dec 11, 2024

Use case

I mistakenly disable the Face ID permission to my app. Now I'm unable to know how can i ask to the user you disable the permission. Basically I'm showing the Face Icon on these methods.

  Future<bool> isDeviceSupported() async {
    try {
      Debugger.log("isDeviceSupported ${await _auth.isDeviceSupported()}");
      return await _auth.isDeviceSupported();
    } catch (e) {
      Debugger.log("Error checking device support: $e");
      return false;
    }
  }

  Future<bool> canCheckBiometrics() async {
    try {
      Debugger.log("canCheckBiometrics ${await _auth.canCheckBiometrics}");
      return await _auth.canCheckBiometrics;
    } catch (e) {
      Debugger.log("Error checking biometrics: $e");
      return false;
    }
  }

isDeviceSupported this is gives me true but canCheckBiometrics this always give me false when I'm not enable the Face ID. So i just need to know how can i check if the user disbale the Face ID. so I asked him to go to setting and enable it.

Need urgent help on this.
Thanks

Proposal

  Future<bool> isDeviceSupported() async {
   try {
     Debugger.log("isDeviceSupported ${await _auth.isDeviceSupported()}");
     return await _auth.isDeviceSupported();
   } catch (e) {
     Debugger.log("Error checking device support: $e");
     return false;
   }
 }

 Future<bool> canCheckBiometrics() async {
   try {
     Debugger.log("canCheckBiometrics ${await _auth.canCheckBiometrics}");
     return await _auth.canCheckBiometrics;
   } catch (e) {
     Debugger.log("Error checking biometrics: $e");
     return false;
   }
 }
@maheshj01 maheshj01 added the in triage Presently being triaged by the triage team label Dec 12, 2024
@maheshj01
Copy link
Member

maheshj01 commented Dec 12, 2024

Hi @MohsinIkram-Auxilium, Thanks for filing the issue. I believe you should use getAvailableBiometrics to get the list of enrolled biometrics on the device.

Future<void> _getAvailableBiometrics() async {
    late List<BiometricType> availableBiometrics;
    try {
      availableBiometrics = await auth.getAvailableBiometrics();
    } on PlatformException catch (e) {
      availableBiometrics = <BiometricType>[];
      print(e);
    }
    if (!mounted) {
      return;
    }

    setState(() {
      _availableBiometrics = availableBiometrics;
    });
  }

source: https://pub.dev/packages/local_auth/example

@maheshj01 maheshj01 added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Dec 12, 2024
@maheshj01
Copy link
Member

Incase that doesn't work this could be the reason #117309

@MohsinIkram-Auxilium
Copy link
Author

@maheshj01 when user not enable the Face ID then the getAvailableBiometrics list always empty.

I have added different checks like
1- Is Device supported the Biometrics
2- Is getAvailableBiometrics are available or not

I need to add check at the very top of these like User enabled the Face ID permission or not, if not then simply i would show error message to user please go to setting and enable Face ID. Thats it.

It would be better if package developers team can add Face ID check permission. So it would be for us to show appropriate error message.
What do you think?

@github-actions github-actions bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Dec 12, 2024
@maheshj01
Copy link
Member

@MohsinIkram-Auxilium

when user not enable the Face ID then the getAvailableBiometrics list always empty.

getAvailableBiometrics is supposed to return the enrolled biometrics on device, meaning list of biometrics user has setup on their device. The result is empty here is because of this issue #117309

I need to add check at the very top of these like User enabled the Face ID permission or not, if not then simply i would show error message to user please go to setting and enable Face ID. Thats it.

I believe you should be able to detect this once the referred issue has been solved. But I agree there should be a way to detect which biometrics are enabled something like getEnabledBiometrics

getAvailableBiometrics gives a list of enrolled biometrics but does not guarantee that the biometrics is enabled by user on device.

Labeling this issue as a proposal to provide an api to determine if a particular biometric is enrolled and enabled to authenticate.

@maheshj01 maheshj01 added c: new feature Nothing broken; request for a new capability p: local_auth Plugin for local authentification package flutter/packages repository. See also p: labels. c: proposal A detailed proposal for a change to Flutter and removed in triage Presently being triaged by the triage team labels Dec 12, 2024
@MohsinIkram-Auxilium
Copy link
Author

Sorry I think you didn't get my point. I have a simple question. Let me clarify again.

Lets suppose I have enrolled face and finger auth in the mobile.
And when very first time open the Flutter IOS app, It asked me to enable Face ID like as IOS ask for Photo and location.
When you enable the photo library then i allow us to choose images from the photo library.

So now I disable the FaceID and trying to call again auth method. Now there is no way to check user disable the FaceID.
So need to add check here, the user disbale the FaceID, i will show the error message "Go to settings and enable the FaceID".

Thats it.
I just need to check either user enable the Face ID or not.

@MohsinIkram-Auxilium
Copy link
Author

@maheshj01 any update on my feedback please?

@maheshj01
Copy link
Member

So now I disable the FaceID and trying to call again auth method. Now there is no way to check user disable the FaceID.
So need to add check here, the user disbale the FaceID, i will show the error message "Go to settings and enable the FaceID".

@MohsinIkram-Auxilium, I have marked this issue as a proposal to have some way to know which biometric is enabled/disabled. If there are any further updates on this issue you will see them here.

@MohsinIkram-Auxilium
Copy link
Author

Thanks @maheshj01.
Waiting for your response because our app going to be live in this week with Auth feature.
So we need to give best user experience to our daily users.

@nickolight
Copy link

nickolight commented Dec 20, 2024

I was faced with unpredictable behavior. Sometimes the canCheckBiometrics method returns "false" even when everything is enabled and configured. And for some reason, after some time it returns "true" again

@maheshj01 maheshj01 added platform-ios iOS applications specifically team-ecosystem Owned by Ecosystem team labels Dec 20, 2024
@stuartmorgan
Copy link
Contributor

stuartmorgan commented Dec 22, 2024

isDeviceSupported this is gives me true but canCheckBiometrics this always give me false when I'm not enable the Face ID.

This is a bug; canCheckBiometrics should be returning true in this case (per the README, this is intended to indicate that the hardware supports biometrics). The combination of canCheckBiometrics being true and the list of available biometrics being enrolled being empty is how developers are intended to detect a case like this.

Someone will need to see what error is returned in this code when the permission isn't granted, and we can special-case it.

@stuartmorgan stuartmorgan added team-ios Owned by iOS platform team and removed c: new feature Nothing broken; request for a new capability c: proposal A detailed proposal for a change to Flutter team-ecosystem Owned by Ecosystem team labels Dec 22, 2024
@stuartmorgan stuartmorgan changed the title [local_auth] Need to know user grant the Face ID permission or not [local_auth] canCheckBiometrics returns false when Face ID permission isn't granted Dec 22, 2024
@MohsinIkram-Auxilium
Copy link
Author

Yeah @stuartmorgan. You are right.
There should be error messages while if any of these methods not working. So user can see appropriate message.
Although all these functions return only Boolean value which should be changed with any error message in case of false.

@jmagman
Copy link
Member

jmagman commented Dec 26, 2024

I enabled FaceID in my phone settings. Then I ran the example app. When I selected "Authenticate" in the app I denied permission. Then I checked biometrics, and it returned -6 so LAErrorBiometryNotAvailable. Which is annoying because I believe that would be the same error code on a device that doesn't have biometry hardware available.

However, a better way to detect the permission denied case might be if LAErrorBiometryNotAvailable and context.biometryType isn't LABiometryTypeNone. In my testing above it returned LABiometryTypeTouchID.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p: local_auth Plugin for local authentification package flutter/packages repository. See also p: labels. platform-ios iOS applications specifically team-ios Owned by iOS platform team
Projects
None yet
5 participants