Skip to content

IBiometric

Gulam Ali H edited this page Jun 9, 2024 · 2 revisions

IBiometric Interface

The IBiometric interface defines methods for biometric authentication.

Methods:

Task<BiometricHwStatus> GetAuthenticationStatusAsync(AuthenticatorStrength authStrength = AuthenticatorStrength.Strong)

  • Description: Asynchronously retrieves the hardware status of biometric authentication.
  • Parameters:
    • authStrength: (Optional) The strength of the biometric authentication. Defaults to AuthenticatorStrength.Strong. (This is only relevant on Android)
  • Returns:
    • A Task<BiometricHwStatus> represents biometric authentication's hardware status.

Task<AuthenticationResponse> AuthenticateAsync(AuthenticationRequest request, CancellationToken token)

  • Description: Asynchronously performs biometric authentication based on the provided AuthenticationRequest.
  • Parameters:
    • request: An AuthenticationRequest object specifying the authentication parameters.
    • token: A CancellationToken is used to cancel the authentication process.
  • Returns:
    • A Task<AuthenticationResponse> represents the authentication attempt's result.

Task<List<BiometricType>> GetEnrolledBiometricTypesAsync()

  • Description: Asynchronously retrieves a list of enrolled biometric options available on this device. (This does not dictate what will be challenged to the user at the time of authentication)
  • Returns:
    • A Task<List<BiometricType>> which retrieves all the available enrolled authentication options.

Example Usage:

  var biometricStatus = await biometricService.GetAuthenticationStatusAsync();
  // Handle biometricStatus based on the application's logic

  if(biometricStatus!= BiometricStatus.Success)
     return;

   var authenticationRequest = new AuthenticationRequest
   {
       AllowPasswordAuth = true, // A chance to fallback to password auth
       Title = "Authenticate", // On iOS only the title is relevant, everything else is unused. 
       Subtitle = "Please authenticate using your biometric data",
       NegativeText = "Use Password", // if AllowPasswordAuth is set to true don't use this it will throw an exception on Android
       Description = "Biometric authentication is required for access",
       AuthStrength = AuthenticatorStrength.Strong // Only relevant on Android
   };

   var authenticationResponse = await biometricService.AuthenticateAsync(authenticationRequest, cancellationToken);