oscoreio / Maui.Biometric

Provides a cross-platform implementation of biometric authentication. Continuation of the abandoned Plugin.Fingerprint in the MAUI ecosystem.
MIT License
31 stars 7 forks source link

Authentication on view appearing #3

Open gaglia opened 4 months ago

gaglia commented 4 months ago

Hi,

I'm trying to use the plugin to enable biometric authorization on the login page of my application.

So I would like the finger recognition PopUp to appear immediately when opening my Login view.

I tried to simulate this starting from your example by simply adding the AuthenticateAsync call on the OnAppearing event of the MainPage:

`protected override async void OnAppearing() { base.OnAppearing();

var type = await BiometricAuthentication.Current.GetAuthenticationTypeAsync(); AuthenticationTypeLabel.Text = $"Auth Type: {type:G}";

await AuthenticateAsync(reason: "Prove you have fingers!"); }`

Can you help me understand the problem? Thanks a lot

Steps to reproduce

  1. Run sample application on device or emulator

Expected behavior

Open biometric authentication when opening the view

Actual behavior

Authentication fails without displaying the PopUp to the user to recognize the fingerprint

Configuration

Version of the Package: 1.0.1

Platform: Android 13

Device: Nokia G50

HavenDV commented 4 months ago

Can you send an exception?

protected override async void OnAppearing()
{
    base.OnAppearing();

    try
    {
        var type = await BiometricAuthentication.Current.GetAuthenticationTypeAsync();
        AuthenticationTypeLabel.Text = $"Auth Type: {type:G}";

        await AuthenticateAsync(reason: "Prove you have fingers!");
    }
    catch(Exception exception)
    {
         // Set break point here
    }
}
gaglia commented 4 months ago

Hi,

I don't get any exceptions, BiometricAuthentication.Current.AuthenticateAsync instead exits with error status "UnknownError" with this message: FragmentManager is already executing transactions

Doing some other tests it seems that inserting a delay of 2 seconds in the OnAppearing event opens the biometric recognition PopUp correctly.

 protected override async void OnAppearing()
 {
     base.OnAppearing();

     await Task.Delay(2000);

     try
     {
         var type = await BiometricAuthentication.Current.GetAuthenticationTypeAsync();
         AuthenticationTypeLabel.Text = $"Auth Type: {type:G}";

         await AuthenticateAsync(reason: "Prove you have fingers!");
     }
     catch (Exception exception)
     {
         var x = exception.ToString();            
     }

 }