DEV Community

Enmanuel Toribio
Enmanuel Toribio

Posted on • Originally published at blog.torib.io on

Adding fingerprint authentication in Xamarin Forms

Adding a fingerprint authentication for multiplatform projects have never been easier than with the Plugin.Fingerprint nuget package.

But first…

A few things to clarify about biometric/fingerprint authentication. These are implementation limitations by the technology itself and not introduced in any way by the Xamarin Forms implementation:

  1. You cannot save “the fingerprint”. There are two reasons for this:
    • The detection of the fingerprint is done inside the hardware that reads the finger.
    • By law you cannot , should not and for now, won’t have access to this information
  2. If your device has more than one registered fingerprint you cannot tell which fingerprint was used to authenticate.
  3. You can only tell if the sensor has or hasn’t received a valid fingerprint.

Now to the main event

To start you want to include the Plugin.Fingerprint into all your solution projects.

Then you have to do a little bit of setup. Don’t be scared it’s just three lines for Android and a couple lines for iOS.

On Android:

  • Request the permissions needed inside your AndroidManifest.xml
  • Set the Activity running the app so the plugin can show the request dialog when asking for the fingerprint. In the plugin repository, they use the CurrentActivity plugin but I noticed that you can just set it up inside the MainActivity by adding the this keyword

    On iOS:

  • Because this plugin works for both Face and Fingerprint authentication, according to the iOS documentation, you need to add an entry for NSFaceIDUsageDescription into the Info. plist file. If you do not add this entry the plugin simply won’t work and your app may even crash. This entry describes what you will be using the face id for in case you were to use the face authentication.

After the setup is done you need to call the AuthenticateAsync method. You should pass the text you want the user to see when you ask them to authenticate. The return is a boolean value that indicates whether the fingerprint was of a valid user or the user canceled the dialog. It also returns a false right away if there are no registered fingerprints.

Running the example on a OnePlus6

Bonus content: Configuring your emulators and simulators for fingerprint authentication

On the iOS simulator:

  • Make sure you “enroll” the Touch ID.
  • To send a valid or invalid Touch ID you can use the options in the menu or the following keyboard shortcuts Shft+Cmd+M and Shift+Cmd+N

Enrolling the Touch ID on an iPhone 8 plus simulator

On the Android emulator:

  • Just go to the emulator options and see the Fingerprints section. From there you get access to a fixed number of the fingerprint.
  • Proceed to register them into the device.

Looking for the fingerprint management section

Configuring the fingerprint. Just tap the “Touch this sensor” button from the emulator options whenever you get asked

I hope you find this useful. I think something like this could be very useful to include in Xamarin.Essentials. From what I’ve gathered they are in plans of adding it but haven’t yet so maybe this is a good chance to do something about it… Anyways, have a good day and if you liked this article I encourage you to share it on social media or fax it to your dad and your mom, they will probably love it, trust me.

The post Adding fingerprint authentication in Xamarin Forms appeared first on Enmanuel Toribio.

Top comments (0)