2

I'm working on a .NET MAUI project and trying to implement Face ID authentication using the Plugin.Fingerprint library. However, it seems the library prompts for fingerprint authentication instead of Face ID. Here's the code I have so far:

private async Task<bool> AuthenticateUsingFaceId()
{
    try
    {
        var authRequestConfig = new AuthenticationRequestConfiguration("Face ID Authentication", "Authenticate to enable face ID login")
        {
            AllowAlternativeAuthentication = false,
        };
        
        var isFaceIdAvailable = await Plugin.Fingerprint.CrossFingerprint.Current.IsAvailableAsync(true);
        if (!isFaceIdAvailable)
        {
            await Shell.Current.DisplayAlert("Error", "Face ID is not supported on this device", "OK");
            return false;
        }

        var result = await Plugin.Fingerprint.CrossFingerprint.Current.AuthenticateAsync(authRequestConfig, CancellationToken.None);
        if (!result.Authenticated)
        {
            await Shell.Current.DisplayAlert("Error", "Face ID authentication failed", "OK");
            return false;
        }

        var pin = await SecureStorage.GetAsync("saved_pin");
        var password = await SecureStorage.GetAsync("saved_password");

        if (string.IsNullOrEmpty(pin) || string.IsNullOrEmpty(password))
        {
            await Shell.Current.DisplayAlert("Error", "No saved credentials for face ID login", "OK");
            return false;
        }

        var tokenResponse = await _authenticationService.AuthenticateAsync(pin!, password!);
        if (tokenResponse == null)
        {
            await Shell.Current.DisplayAlert("Error", "Automatic login failed", "OK");
            return false;
        }

        await SecureStorage.SetAsync("access_token", tokenResponse.JwtToken!);
        await SecureStorage.SetAsync("refresh_token", tokenResponse.RefreshToken!);

        await Shell.Current.DisplayAlert("Success", "Logged in using face ID authentication", "OK");

        await Shell.Current.GoToAsync(nameof(NotificationPage));
        return true;
    }
    catch (Exception ex)
    {
        await Shell.Current.DisplayAlert("Error", ex.Message, "OK");
        return false;
    }
}

I have set AllowAlternativeAuthentication to false, hoping it would force Face ID authentication, but it still prompts for fingerprint. My understanding is that the library may not fully support Face ID.

Is there a way to configure Plugin.Fingerprint to prioritize Face ID over fingerprint authentication? Or do I have to use an alternative library or method to implement Face ID authentication in .NET MAUI?

6
  • This is not the issue with your plugin but the issue with Google and Android, I have a biometric plugin with the latest APIs, Gerald even made a video on it, but it has the same issue github.com/FreakyAli/Plugin.Maui.Biometric/issues/4 Commented Jun 10, 2024 at 13:57
  • It supports Face ID. When both are available, Touch ID is preferred, because it's more secure. However, you should be able to select the authentication method in the iOS settings, I think. Commented Jun 10, 2024 at 19:39
  • 1
    @Julian I have researched this, Fingerprint does not exist in the latest iOS versions so that's out of the picture. On Android there are two methods of authentication, weak and strong if you select strong face will never be considered at all, whereas if you select weak, the OS decides which one to display, since the fingerprint is stronger between the two it's chosen over face always. Google does not give you the option to choose between the two, so basically, face id will only be shown if you never configure your finger on the Android Commented Jun 11, 2024 at 6:28
  • @FreakyAli Yes, that makes. Commented Jun 11, 2024 at 7:28
  • Check the URL above it has a link to the google issue that tracks this @Julian Commented Jun 11, 2024 at 7:39

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.