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.
Sounds overwhelming? Authgear's magic handle all these for you. Follow this guide to enable biometric login in your app with a few lines of code.
Enable biometric authentication for your project
In the portal, go to Authentication > Biometric.
Turn on Enable biometric authentication.
Save the settings.
authentication:
identities:
...
# Add biometric along with the other enabled identities
- biometric
identity:
biometric:
# Enable listing biometric login in user setting page, default false
list_enabled: trueSet 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
In the SDKs, a set of biometric options is required to check the support or enable biometric on the device.
iOS
There are two options on iOS:
localizedReasonis the message string the user will see when FaceID or TouchID is presentedconstraintis an enum that constraint the access of key stored under different conditions:biometryAny: The key is still accessible by Touch ID if fingers are added or removed, or by Face ID if the user is re-enrolledBiometricCurrentSet: The key is invalidated if fingers are added or removed for Touch ID, or if the user re-enrolls for Face ID
See reference in Apple Developers Doc on biometryAny and biometryCurrentSet.
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 dialogconstraintis an array defines the requirement of security level, which can beBIOMETRIC_STRONG,BIOMETRIC_WEAK,DEVICE_CREDENTIAL. See reference in Android developers documentation onBiometricManager.Authenticators``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. See reference in Android developers documentation onKeyGenParameterSpec.Builder.
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 biometric 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.
Last updated
Was this helpful?