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:
- 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
- If your device has more than one registered fingerprint you cannot tell which fingerprint was used to authenticate.
- You can only tell if the sensor has or hasn’t received a valid fingerprint.
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.
- 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
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.
- 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
- 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.
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.