Add Biometric Login
Overview
Authgear supports enabling biometric login in the native mobile application. You will need to
Enable biometric login in your application via the portal.
In the mobile app, use the mobile SDK to enable biometric login for your users.
A pair of cryptographic keys will be generated upon registering biometric login. The private key will be stored securely in the device (using Keystore in Android and Keychain in iOS), while the public key is stored in the Authgear server. To authenticate the user, fingerprint or face is presented to unlock the private key, and a digital signed message is sent to the server to proof the authenticity of the user.
Fig 1.0. The following figure shows the sequence for enabling Biometric Login on a supported device:

The Client App that is already logged in to a user's account will check if biometrics is supported by the user's device. If the device supports biometric login, it is then enabled. The public key is sent to Authgear server and associated with the logged-in user's account.
The flow is then completed and biometric login is enabled for the user on the Client App.
Fig 2.0. The following figure shows the sequence for a user logging in with Biometric:

With biometric login already enabled for the user, the next time they need to log in they can initiate a biometric authentication flow which will follow the sequence shown in Fig 2.0 above. Once the biometric login is successful, Authgear server will return an access token and a refresh token. The client application can then use the access token to make authenticated requests.
Sounds overwhelming? Authgear's magic handles all these for you. Follow this guide to enable biometric login with a few lines of code in your app.
Enable biometric authentication for your project
In the portal, go to Authentication > Biometric.
Turn on Enable biometric authentication.
Save the settings.
Set reasonably short token lifetimes for client applications
Biometric login is usually used when you want the user to re-login after a relatively short period of time. For sensitive applications such as financial apps, it's recommended to use a short refresh token lifetime and a short idle timeout.
In the Authgear Portal, go to Applications
Select the client application that represent the integration with the mobile app
Set a short Refresh Token Lifetime to say 3,600 seconds (1 hour)
Enable Expire after idling
Set a short Idle Timeout, to say 1,800 seconds (30 minutes)
By doing so, the end-user's session will be expired 1 hour after their login, or after 30 minutes of inactivity. The end-user will need to authenticate themself again with biometric, even if the app process has not yet been killed.
Configure SDK so users must re-login after app closed
Apart from the short token lifetimes, it's also common for sensitive apps to ask the user to re-login by biometric after the app process is killed and relaunched.
The SDK should be configured to use TransientTokenStorage so the tokens are stored in memory, and will be cleared when the app is closed. So the end-users must authenticate with biometrics again.
Enable biometric login in mobile SDK
In the following section, we will show you how to use biometric login in the SDK. In the SDK code snippet, authgear is referring to the configured Authgear container.
Biometric options
Customize the biometric options to achieve the expected user experience.
iOS
There are 4 options on iOS:
localizedReasonis the custom message to explain to the user why TouchID or FaceID is required.localizedCancelTitle(optional) customizes the cancel button label.policyconstraints how the user is authenticated locally.deviceOwnerAuthenticationWithBiometrics: The user MUST use TouchID or FaceID. This also implies the device must have TouchID or FaceID already set up. See also Error handlingdeviceOwnerAuthentication: If the device has TouchID or FaceID set up, it is used first. Otherwise, the device passcode is used. This also implies the device must have a passcode. See also Error handlingIt refers to the
LAPolicyenum on iOS, see reference in Apple Developers Doc on these options.
constraintis an enum that constraint the access of key stored under different conditions:biometryCurrentSet: The biometric login will be invalidated if the device has any changes to TouchID or FaceID. Changes include adding, or removing, re-enrolling any fingerprints or faces.biometryAny: The biometric login stays valid even if the device has any changes to TouchID or FaceID.userPresence: Either biometry or device passcode/PIN can be used to access the private key.
In summary, based on the desired behavior and business requirements, set the policy and constraint options as below.
Sign in with any currently set biometry. Re-enrollment causes reset.
deviceOwnerAuthenticationWithBiometrics
BiometryCurrentSet
Sign in with any biometry. Re-enrollment does not cause reset.
deviceOwnerAuthenticationWithBiometrics
biometryAny
Sign in with either biometry, or device passcode
deviceOwnerAuthentication
userPresence
Android
There are 6 options on Android:
titleis the Title of the biometric dialog presented to the userssubtitleis the subtitle of the biometric dialog presented to the usersdescriptionis the description of the biometric dialog presented to the usersnegativeButtonTextis what the dismiss button says in the biometric dialogallowedAuthenticatorsOnEnableis an array that defines the requirement of security level when the user enable biometric, which can beBIOMETRIC_STRONGorDEVICE_CREDENTIAL.allowedAuthenticatosOnAuthenticateis an array that defines the requirement of security level when the user authenticates with biometric.invalidatedByBiometricEnrollmentis a boolean that controls if the key pair will be invalidated if a new biometric is enrolled, or when all existing biometrics are deleted.
In summary, based on the desired behavior and business requirements, set allowedAuthenticatorsOnEnable and allowedAuthenticatosOnAuthenticate as below.
Requirement
allowedAuthenticatorsOnEnable
allowedAuthenticatosOnAuthenticate
Biometric is required during enable and subsequent biometric authentication.
[BIOMETRIC_STRONG]
[BIOMETRIC_STRONG]
Biometric is required during enable. Passcode is also allowed in subsequent biometric authentication.
[BIOMETRIC_STRONG]
[BIOMETRIC_STRONG, DEVICE_CREDENTIAL]
Passcode is allowed during enable and subsequent biometric authentication.
[BIOMETRIC_STRONG, DEVICE_CREDENTIAL]
[BIOMETRIC_STRONG, DEVICE_CREDENTIAL]
Code examples
Check support
Always check if the current device supports biometric login before calling any biometric API, including before enabling biometric login and before using biometrics to login.
Enable biometric login
Enable biometric login for logged in user
Check if biometric has been enabled before
Before asking the user to log in with biometric, Check if biometric login has been enabled on the current device. I.e. Is the key pair exist on the device (Keystore in Android and Keychain in iOS).
This method will still return true even if all the fingerprint and facial data has been removed from the device. Before this method, you should use the "checkBiometricSupported" to check if biometry is supported in the device level.
Login with biometric credentials
If biometric is supported and enabled, you can use the Authenticate Biometric method to log the user in. If the key pair is invalidated due to changes in the biometry settings, e.g added fingerprint or re-enrolled face data, the biometricPrivateKeyNotFound will be thrown. You should handle the error by the Disable Biometric method, and ask the user to register biometric login again.
Disable biometric login on the current device
Error handling
In all methods related to biometric, the SDK may throw the following errors that describe the status of the biometry enrollment or the key pair stored on the device.
Fall back to Device PIN/Password when Biometric Verification fails
You may want to provide an alternative means for users to log in when biometric verification fails on their devices. For example, in a case where a user's finger is dirty (touch-based) or when the user's face is covered (Face ID).
On iOS, you use deviceOwnerAuthenticationWithBiometrics during enable, and use deviceOwnerAuthentication during subsequent authentication.
On Android, you set allowedAuthenticatorsOnEnable and allowedAuthenticatosOnAuthenticate according to the example below.
The biometric pop-up will look like this after a failed biometric log-in attempt with BiometricLAPolicy.deviceOwnerAuthentication policy on iOS:

With the BiometricLAPolicy.deviceOwnerAuthenticationWithBiometrics policy, the biometric login pop-up will not include the Enter Passcode button. An example is shown below:

Last updated
Was this helpful?