Face Comparison
The Identity Verification (IDV) service also provides a face comparison check that can be used to authenticate a user by using their selfie. This check does a AI comparison between live user selfie and the reference face image to return a confidence score.
Session specification
To use the Face comparison service, you have to create session specification with at least two checks - Liveness and Face Comparison. You can also set the maximum retries for liveness and manual check option for face comparison checks.
const {
SessionSpecificationBuilder,
RequestedLivenessCheckBuilder,
RequestedFaceComparisonCheckBuilder,
SdkConfigBuilder
} = require('yoti');
// Liveness check with 3 retries
const livenessCheck = new RequestedLivenessCheckBuilder()
.forStaticLiveness()
.withMaxRetries(3)
.build();
// Face Comparison check with manual check set to never
const faceComparisonCheck = new RequestedFaceComparisonCheckBuilder()
.withManualCheckNever()
.build();
// Configuration for the client SDK (Frontend)
const sdkConfig = new SdkConfigBuilder()
.withAllowsCameraAndUpload()
.withLocale("en-GB")
.withPresetIssuingCountry('GBR')
.withSuccessUrl('/success')
.withErrorUrl('/error')
.withPrivacyPolicyUrl('/privacy-policy')
.withAllowHandoff(true)
.build();
// Buiding the Session with defined specification from above
const sessionSpec = new SessionSpecificationBuilder()
.withClientSessionTokenTtl(600)
.withResourcesTtl(90000)
.withUserTrackingId('some-user-tracking-id')
.withRequestedCheck(livenessCheck)
.withRequestedCheck(faceComparisonCheck)
.withSdkConfig(sdkConfig)
.build();
Initialise the Yoti client
The included DocScan/IDV Client includes several helper methods to interact with the Yoti's API. You can initialise the client using your unique SDK ID and PEM file.
const path = require('path');
const fs = require('fs');
const { IDVClient } = require('yoti');
const YOTI_CLIENT_SDK_ID = 'YOTI_CLIENT_SDK_ID';
const YOTI_PEM = fs.readFileSync(path.join(__dirname, '/path/to/pem'));
const idvClient = new IDVClient(YOTI_CLIENT_SDK_ID, YOTI_PEM);
Create a session
You can use the createSession method from the above client to create a Yoti session. Session specification needs to be passed as an argument. After the session is successfully created, you will get a Session ID that can be used to retrieve the Session configuration.
let sessionId, clientSessionToken;
idvClient
.createSession(sessionSpec)
.then((session) => {
sessionId = session.getSessionId();
clientSessionToken = session.getClientSessionToken();
})
.catch((err) => {
console.log(err)
});
const sessionConfig = await idvClient.getSessionConfiguration(sessionId);
Create a Face Capture resource
Before uploading the reference face image, you have to create a Face capture resource. To do this, a Requirement ID from the Face Capture requirements needs to retrieved. This can then be used to create a face capture resource. If successful, you will receive a Resource Id.
const {
CreateFaceCaptureResourcePayloadBuilder,
UploadFaceCaptureImagePayloadBuilder,
} = require('yoti');
const resourceRequirements = sessionConfiguration.getCapture().getFaceCaptureResourceRequirements()[0];
const requirementId = resourceRequirements.getId();
const faceCapturePayload = new CreateFaceCaptureResourcePayloadBuilder()
.withRequirementId(requirementId)
.build();
const faceCaptureResource = await idvClient.createFaceCaptureResource(sessionId, faceCapturePayload);
const resourceId = faceCaptureResource.getId();
Uploading a reference image
To do an accurate face comparison, a reference selfie image of the user is required. You have to get the contents of this image which can then be uploaded using the Doc Scan Client. You also have to pass in the Resource Id retrieved earlier.
const fs = require('fs');
const imageBuffer = fs.readFileSync('path-to-selfie-jpeg');
const faceCaptureImagePayload = new UploadFaceCaptureImagePayloadBuilder()
.forJpegImage()
.withImageContents(imageBuffer)
.build();
await idvClient.uploadFaceCaptureImage(sessionId, resourceId, faceCaptureImagePayload);