User authentication with system biometric authenticators
Introduction
The OneWelcome React Native SDK allows you to authenticate users with the system biometric authenticators. These authenticators are provided by the device's operating system (iOS - Touch ID and Face ID, Android - fingerprint) if they are available on the device. System biometric authenticators can be used for both: regular and mobile authentication. Users will be able to retry system biometric authentication as many times as the OS allows them to. If the OS system's biometric authenticators API returns an error for any reason (for example in case of too many failed attempts), the OneWelcome React Native SDK will revoke system biometric authenticator and will perform a fallback to PIN authentication.
Requirements
FaceID
iOS needs to have configured message displayed on FaceID alert. It's configurable by adding NSFaceIDUsageDescription
in your Info.plist
file.
Example configuration
Not specifying this property in your configuration will crash your application when you will try to use Face ID authentication.
Differences between Android and iOS
It should be noted that there are significant differences between Fingerprint on Android and Touch ID on iOS. As a result, some methods may be available on only one of the operating systems. This will be specified where applicable.
Enabling system biometric authenticator authentication
In order to enable fingerprint authenticator authentication for a user, the OneWelcome React Native SDK provides the registerAuthenticator to which you need to pass authenticatorId
. This function requires the user to authenticate with PIN.
Example code for registering the system biometric authenticator:
You have to also listen for PIN events in case of fallback.
Fingerprint authentication may not be available on every device. In this case, or if the authenticator has already been registered, the above method will reject with an error.
To request a list of available authenticators, the plugin exposes the getAllAuthenticators function. If the device does not meet the fingerprint requirements, the fingerprint authenticator will not be present in the returned array of authenticators.
Note that registering a new authenticator does not set it as the preferred authenticator for the user, which is PIN by default. To change the preffered authenticator setPreferredAuthenticator can be used.
Example code to set fingerprint as the preferred authenticator:
Authenticate with fingerprint
There are two ways to start a fingerprint authentication flow.
- You register fingerprint as the preferred authenticator using setPreferredAuthenticator and call
authenticateUser
withnull
as the second argument. - You get the authenticatorId for fingerprint authentication and pass that into the second argument of
authenticateUser
Android
For authentication with fingerprint, similar to pin, you will need to handle the FingerprintNotificationEvent
see addEventListener for more details. You can listen for this event and handle it as follows.
The SDK fires four events actions which notify you about the status of the fingerprint authentication.
Fingerprint Event | Description |
---|---|
StartAuthentication | Fired when a new fingerprint authentication request is made, providing an UserProfile object containing the profileId |
OnNextAuthenticationAttempt | Fired when user provided incorrect fingerprint but still haven't reach the failed attempts limit, |
OnFingerprintCaptured | Fired when user scanned his fingerprint and the fingerprint validation is performed. That's a good moment to show an update on the UI informing user about received attempt. |
FinishAuthentication | Fired when fingerprint scanning finished either with success or an error. |
There are 3 methods to communicate the fingerprint flow to the SDK after fingerprint authentication has started.
SDK method | Description |
---|---|
OnewelcomeSdk.submitFingerprintAcceptAuthenticationRequest() | Should be called when user accepts fingerprint authentication request. |
OnewelcomeSdk.submitFingerprintDenyAuthenticationRequest() | Should be called when user denies the fingerprint authentication request. |
OnewelcomeSdk.submitFingerprintFallbackToPin() | Should be called when user decides to resign from fingerprint authentication and wants to enter his PIN to finish authentication. |
In order to start the fingerprint authentication you need to call submitFingerprintAcceptAuthenticationRequest(). This can be done when you receive the
startAuthentication
event action.
If the user fails to authenticate using fingerprint too many times (this limit is set by the OS), the fingerprint authenticator is automatically deregistered and the relevant tokens are revoked by the OneWelcome React Native SDK. At this point, a fallback to PIN is performed, and the user is requested to enter PIN.
iOS
When starting biometric authentication on iOS the user will be prompted to authenticate with TouchId or FaceId with a native prompt from the OS. Due to differences between how biometric authentication works on Android and iOS we do not need any event listeners for iOS, the flow is handled by the promise from authenticateUser resolving. The user can press the cancel button on the native biometric prompt which will perform a fallback to PIN.