Migration Guide
This acts as a reference guide for migrating from Active to Passive liveness in the Identity Verification (IDV) SDK.
Install the SDK
You will need to ensure the latest version of the Yoti backend SDK is installed.
// Get the Yoti Node SDK library via the NPM registry
npm install -S -E yoti
Session specification
Once you have added the Yoti SDK dependency to your project, you can use it to specify your IDV session with a liveness check as shown in the following code snippet(s).
Active liveness
const {
RequestedLivenessCheckBuilder,
SdkConfigBuilder,
SessionSpecificationBuilder,
} = require('yoti');
// Active liveness check with 3 retries
const livenessCheck = new RequestedLivenessCheckBuilder()
.forZoomLiveness()
.withMaxRetries(3)
.build();
// Configuration for the client SDK (Frontend)
const sdkConfig = new SdkConfigBuilder()
.withAllowsCameraAndUpload()
.withPresetIssuingCountry('GBR')
.withSuccessUrl('https://localhost:8443/success')
.withErrorUrl('https://localhost:8443/error')
.build();
// Build the Session specification
const sessionSpec = new SessionSpecificationBuilder()
.withClientSessionTokenTtl(900)
.withResourcesTtl(90000)
.withUserTrackingId('some-user-tracking-id')
.withRequestedCheck(livenessCheck)
.withSdkConfig(sdkConfig)
.build();
Passive liveness
const {
RequestedLivenessCheckBuilder,
SdkConfigBuilder,
SessionSpecificationBuilder,
} = require('yoti');
// Passive (Static) liveness check with 3 retries
const livenessCheck = new RequestedLivenessCheckBuilder()
.forStaticLiveness()
.withMaxRetries(3)
.build();
// Configuration for the client SDK (Frontend)
const sdkConfig = new SdkConfigBuilder()
.withAllowsCameraAndUpload()
.withPresetIssuingCountry('GBR')
.withSuccessUrl('/success')
.withErrorUrl('/error')
.build();
// Build the Session specification
const sessionSpec = new SessionSpecificationBuilder()
.withClientSessionTokenTtl(900)
.withResourcesTtl(90000)
.withUserTrackingId('some-user-tracking-id')
.withRequestedCheck(livenessCheck)
.withSdkConfig(sdkConfig)
.build();
Session creation
Once you have built the session specification, you can send the request to creation a session.
const path = require('path');
const fs = require("fs");
const {
IDVClient
} = require('yoti');
const CLIENT_SDK_ID = 'YOTI_CLIENT_SDK_ID'
const PEM_PATH = 'YOTI_KEY_FILE_PATH'
const PEM_KEY = fs.readFileSync(path.join(__dirname, PEM_PATH));
const idvClient = new IDVClient(CLIENT_SDK_ID, PEM_KEY);
idvClient
.createSession(sessionSpec)
.then((session) => {
const sessionId = session.getSessionId();
const clientSessionToken = session.getClientSessionToken();
})
.catch((error) => {
console.log(error)
});
Retrieve session results
After a session has been created, you can use the Yoti SDK to retrieve the session result (containing results of the liveness check and associated resources).
// Returns the session result
idvClient.getSession(sessionId).then(session => {
// Returns the session state
const state = session.getState();
// Returns all checks for the session
const checks = session.getChecks();
// Returns the session resources
const resources = session.getResources();
}).catch(error => {
console.log(error)
})
Liveness checks
The liveness checks include any attempts the user made to provide their liveness. It's possible that some of these attempts were rejected.
// Returns the liveness checks
const livenessChecks = session.getLivenessChecks();
livenessChecks.map(check => {
// Returns the id of the check
const id = check.getId();
// Returns the state of the check
const state = check.getState();
// Returns an array of resources used in the check
const resourcesUsed = check.getResourcesUsed();
// Returns the report for the check
const report = check.getReport();
// Returns the recommendation value, either APPROVE, NOT_AVAILABLE or REJECT
const recommendation = report.getRecommendation().getValue();
// Returns the report breakdown including sub-checks
const breakdown = report.getBreakdown();
breakdown.forEach(function (breakdown) {
// Returns the sub-check
const subCheck = breakdown.getSubCheck();
// Returns the sub-check result
const subCheckResult = breakdown.getResult();
});
})
Liveness resources
The liveness resources include any media resources that were captured when the user provided their liveness.
// Returns the liveness resources
const livenessResources = resources.getLivenessCapture();
livenessResources.forEach((liveness) => {
// Get the liveness id
const livenessId = liveness.getId();
// Get the liveness type
const livenessType = liveness.getLivenessType();
});
Active liveness
// Returns Active (Zoom) liveness resources
const zoomLivenessResources = resources.getZoomLivenessResources();
zoomLivenessResources.forEach((liveness) => {
// Get the liveness id
const livenessId = liveness.getId();
// Get the liveness facemap
const facemap = liveness.getFaceMap();
// Get the liveness frames
const frames = liveness.getFrames();
frames.forEach((frame) => {
// Get the frame media
const frameMedia = frame.getMedia();
// Get the frame media id
const frameMediaId = frameMedia.getId();
});
});
Passive liveness
// Returns Passive (Static) liveness resources
const staticLivenessResources = resources.getStaticLivenessResources();
staticLivenessResources.forEach((liveness) => {
// Get the liveness id
const livenessId = liveness.getId();
// Get the liveness image media
const livenessMedia = liveness.getImage();
// Get the liveness media id
const livenessMediaId = livenessMedia.getId();
});