Introduction :
In today’s digital age, where security threats loom large, ensuring robust authentication processes is paramount. Traditional methods like passwords and PINs are prone to breaches, leading to a surge in demand for more secure and seamless authentication solutions. Biometric authentication has emerged as a game-changer, offering enhanced security and user convenience. Leveraging this trend, Salesforce has introduced the Lightning Web Component Biometrics Service API, providing developers with powerful tools to integrate biometric authentication seamlessly into their applications. In this blog post, we’ll delve into the capabilities of the Lightning Web Component Biometric Service API and explore how it can be leveraged within Salesforce environments.
Understanding Biometric Authentication :
Biometric authentication utilizes unique biological characteristics, such as fingerprints, facial features, iris patterns, or voiceprints, to verify a user’s identity. Unlike passwords or tokens, which can be forgotten, stolen, or duplicated, biometric data is inherently tied to an individual and difficult to replicate. This makes it an ideal candidate for strengthening authentication mechanisms in various applications, from mobile banking to healthcare.
What is Biometrics Service API ?
The Biometrics Service API is a featured introduced within Lightning web component that uses a device’s biometrics functionality to prompt a user to confirm their identity. When these biometrics-related actions occur, the result is returned to the Lightning web component that invoked it.
Biometrics checks are managed locally on the mobile device, and don’t need a network connection. However, Biometrics Service requires access to platform-specific APIs that are available only within compatible Salesforce mobile apps.
Benefits of Biometric Authentication :
- Enhanced Security : Biometric authentication adds an extra layer of security, making it harder for unauthorized individuals to access your app.
- Improved User Experience : Biometric authentication streamlines the login process, offering a frictionless user experience. Users no longer need to remember complex passwords, leading to increased convenience and satisfaction.
Getting Started :
Ready to unlock the power of Biometrics Service API? Here’s how:
- Import the API : Use
import { getBiometricsService } from 'lightning/mobileCapabilities';
in your component’s JavaScript file. - Check availability : Ensure the API is available before using it with
getBiometricsService().isAvailable()
- Check Biometrics availability : Ensure that a device has biometrics functionality and that it’s setup for use with
getBiometricsService().isBiometricsReady(options)
- Prompt a Biometric check : Prompt a device biometrics check with
getBiometricsService().checkUserIsDeviceOwner(options)
Biometrics Service API Example :
<!--biometricCmp.html-->
<template>
<lightning-card title="Biometrics Service Demo" icon-name="custom:privately_shared">
<div class="slds-var-m-around_medium">
Use device biometrics capabilities to verify current user is indeed device owner:
<lightning-button
variant="brand"
label="Verify"
title="Verify device ownership using biometrics"
onclick={handleVerifyClick}
class="slds-var-m-left_x-small">
</lightning-button>
</div>
<div class="slds-var-m-around_medium">
<lightning-formatted-text value={status}></lightning-formatted-text>
</div>
</lightning-card>
</template>
import { LightningElement } from 'lwc';
import { getBarcodeScanner, getBiometricsService } from 'lightning/mobileCapabilities';
export default class BiometricCmp extends LightningElement {
status;
biometricsService;
connectedCallback(){
this.barcodeScanner = getBarcodeScanner();
this.biometricsService = getBiometricsService();
}
handleVerifyClick(){
if(this.biometricsService.isAvailable()){
const options = {
permissionRequestBody: "Required to confirm device ownership.",
additionalSupportedPolicies: ['PIN_CODE']
};
this.biometricsService.checkUserIsDeviceOwner(options)
.then((result) => {
// Do something with the result
if (result === true) {
this.status = "✔ Current user is device owner."
} else {
this.status = "𐄂 Current user is NOT device owner."
}
})
.catch((error) => {
// Handle errors
this.status = 'Error code: ' + error.code + '\nError message: ' + error.message;
});
}else{
//Biometric service is not enabled
this.status = 'Problem initiating Biometrics service. Are you using a mobile device?';
}
}
}
Considerations and Limitations :
- Biometrics Service API is accessible when it runs within a compatible Salesforce mobile app.
- Salesforce Mobile app
- Mobile Publisher for Experience Cloud
- Biometrics Service is built on top of mobile operating system and device features capabilities therefore depend on Android or iOS features.
References :
- https://developer.salesforce.com/docs/platform/lwc/guide/reference-lightning-biometricsservice.html
- https://developer.salesforce.com/docs/atlas.en-us.mobile_offline.meta/mobile_offline/use_biometricsservice.htm