Salesforce BiometricsService Mobile Capability
What is a Biometrics Service?
A Biometrics Service is a software component or system that provides functionality for biometric authentication. Biometric authentication involves using unique biological characteristics of individuals, such as fingerprints, facial features, iris patterns, or voiceprints, to verify their identity.
Why is Biometrics Service important?
The Biometrics Service is an essential tool that provides a highly secure, convenient, and reliable method for verifying individuals based on unique biological characteristics like fingerprints, facial features, or iris patterns. By using biometric authentication, organizations can improve security, reduce fraud and identity theft, comply with regulations, enhance operational efficiency, and offer a seamless user experience across various applications and industries. Biometrics offers a future-proof solution for identity verification that is adaptable to different use cases and scalable to accommodate large user bases and transaction volumes. In summary, the Biometrics Service plays a crucial role in ensuring the integrity, confidentiality, and accessibility of sensitive data and resources.
Please note that Salesforce BiometricsService cannot function in a web browser, whether on a desktop or mobile device.BiometricsService is a mobile-only capability via LWC. It does not support biometrics unlock of LWCs when configured via web devices using features like fingerprint scan via Touch ID on a desktop.
Salesforce is introduced BiometricsService mobile capabilities in Spring '24. Developers can add additional security measures to data stored on Lightning web components (LWCs).
Biometrics Usecase
Let's say you want to create an LWC to store sensitive information, such as a contact's physical address and identification details. However, you don't want this information to be accessible to anyone. By using BiometricsService, you can implement additional security measures like FaceID and fingerprint scanning to protect the data being processed within your Salesforce mobile apps.
Biometric authentication can secure access to documents stored on mobile devices, such as PDFs, spreadsheets, or presentations. Users can authenticate themselves using biometrics to unlock and view sensitive documents, ensuring confidentiality and privacy of information.
Salesforce BiometricsService Example
Below is a sample Lightning web component that verifies device ownership using a device's biometric features. The component's minimal HTML template includes a "Verify" button to initiate the biometrics check.
<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>
This code example utilizes BiometricsService to prompt the user for a biometric check. The function returns a status message indicating whether or not the check was successful.
import { LightningElement } from 'lwc';import { getBiometricsService } from 'lightning/mobileCapabilities';
export default class NimbusPluginBiometricsService extends LightningElement {
status;
biometricsService;
connectedCallback() {
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 {
// service not available
this.status = 'Problem initiating Biometrics service. Are you using a mobile device?';
}
}
}
Additional Details
The options constant is a required parameter. When checking device ownership, the addionalSupportedPolicies object allows you to configure the fallback options in the event that the biometrics scan fails. In this case, adding PIN_CODE in the object array will alert BiometricsService to prompt for the device PIN code as the fallback.
If the barcode scan fails, it will return a set of failure codes. Reference BiometricsServiceFailureCodes for more details.
Here is the list of functions available with BiometricsService API
getBiometricsService - import the getBiometricsService() factory function from the lightning/mobileCapabilities module.
import { getBiometricsService } from 'lightning/mobileCapabilities';
After importing into your component, use the factory function to get an instance of BiometricsService. Use the utility functions and constants to verify availability, then use the feature functions to perform the associated functionality.
isAvailable() - BiometricsService relies on the hardware of the physical device and platform features. A component that uses BiometricsService may display without errors on a desktop computer or mobile browser, but the biometrics-checking functions may not work. To prevent these errors, it is recommended to check if BiometricsService functionality is available before using it.
handleCheckBiometricsClick(event) {const myBiometricsService = getBiometricsService();
if(myBiometricsService.isAvailable()) {
// Perform biometrics-checking operations
}
else {
// BiometricsService not available, or consuming app hasn’t implemented it
// Not running on hardware with biometrics functionality, etc.
// Handle with message, error, beep, and so on
}
}
isBiometricsReady() - Use isBiometricsReady() to check if the device has biometric functionality and is set up for use.
// Check for device biometrics functionality, console log the resultsmyBiometricsService.isBiometricsReady(options)
.then((results) => {
console.log(results);
})
.catch((error) => {
// Handle cancellation or other errors here
console.error('Error code: ' + error.code); +
console.error('Error message: ' + error.message);
});
CheckUserIsDeviceOwner() - Verify whether the user is the device owner by using the device's biometric hardware or pin code.
// Get events from a specified date range from the specified calendar(s), and then process them
myBiometricsService.checkUserIsDeviceOwner(options).then((results) => {
// Do something with the event(s) data
this.events = results;
console.log(results);
})
.catch((error) => {
// Handle cancellation or other errors here
this.events = [];
console.error('Error code: ' + error.code); +
console.error('Error message: ' + error.message);
});
For the latest Mobile Capabilities, Please access Use Mobile Device Features in Mobile Apps
References
Introducing the BiometricsService Mobile Capability
Comments
Post a Comment