How to use biometric authentication in .NET MAUI

Biometric authentication has become an increasingly integral part of mobile apps to ensure that the user is the rightful owner of the device that they’re using. Here’s how you can authenticate via Face ID (iOS) or fingerprint (Android / iOS) in your .NET MAUI app.

Add the package

In your .NET MAUI project, install the Plugin.Fingerprint NuGet package. You’ll need version 3.0.0-beta.1, which is currently in pre-release, so remember to check “Include prerelease”:

The Plugin.Fingerprint package in the NuGet Package Manager.

Follow the guide on GitHub for how to set it up for your .NET MAUI project. The guide is currently located under the maui-support branch, so if the link doesn’t work it’s already been merged in and you can use the previously provided link.

Add a button with a click handler. Inside the event handler in the code-behind, add the following code:

Now when you click the button, you will be asked to authenticate yourself via facial recognition or fingerprint. Check the video below to see how it works on Android:

Fingerprint authentication on an Android emulator.

You can also do the same with dependency injection by using the IFingerprint interface and resolving it to CrossFingerprint.Current. See my GitHub code example for a full sample on how to do this. Note that this may not be best practice when it comes to using DI – I am only using this to provide a simple sample on how you could do this yourself.

Thoughts

I am always blown away at the community around Xamarin/.NET MAUI and how much work is put in by individuals who want to help out. If you found the package provided here useful, be sure to check the repository for the package and give it a star. As the package is still in beta for MAUI, make sure to provide feedback if you notice something.

As always, I’ve provided a code example on my GitHub that you can check out if you’d like. This sample was also featured on the .NET MAUI Community Standup for May 2022.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.