-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
83 lines (74 loc) · 2.71 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Point the Doc Scan client at the sandbox by setting environment variable YOTI_DOC_SCAN_API_URL to https://api.yoti.com/sandbox/idverify/v1
require("dotenv").config();
const fs = require("fs");
const { SandboxDocScanClientBuilder } = require("@getyoti/sdk-sandbox");
const {
SessionSpecificationBuilder,
RequestedDocumentAuthenticityCheckBuilder,
RequestedLivenessCheckBuilder,
RequestedTextExtractionTaskBuilder,
RequestedFaceMatchCheckBuilder,
SdkConfigBuilder,
NotificationConfigBuilder,
DocScanClient,
Client
} = require("yoti");
const SANDBOX_CLIENT_SDK_ID = process.env.YOTI_CLIENT_SDK_ID;
const PEM = fs.readFileSync("./path/to/pem/privateKey.pem", "utf8");
const yotiClient = new Client(SANDBOX_CLIENT_SDK_ID, PEM);
const sandboxClient = new SandboxDocScanClientBuilder()
.withClientSdkId(SANDBOX_CLIENT_SDK_ID)
.withPemString(PEM)
.build();
//Document Authenticity Check
const documentAuthenticityCheck =
new RequestedDocumentAuthenticityCheckBuilder().build();
//Liveness check with 3 retries
const livenessCheck = new RequestedLivenessCheckBuilder()
.forZoomLiveness()
.withMaxRetries(3)
.build();
//Face Match Check with manual check set to fallback
const faceMatchCheck = new RequestedFaceMatchCheckBuilder()
.withManualCheckFallback()
.build();
//ID Document Text Extraction Task with manual check set to fallback
const textExtractionTask = new RequestedTextExtractionTaskBuilder()
.withManualCheckFallback()
.build();
//Configuration for the client SDK (Frontend)
const sdkConfig = new SdkConfigBuilder()
.withAllowsCameraAndUpload()
.withPrimaryColour("#2d9fff")
.withSecondaryColour("#FFFFFF")
.withFontColour("#FFFFFF")
.withLocale("en-GB")
.withPresetIssuingCountry("GBR")
.withSuccessUrl(`${process.env.YOTI_APP_BASE_URL}/index`)
.withErrorUrl(`${process.env.YOTI_APP_BASE_URL}/profile`)
.withPrivacyPolicyUrl(`${process.env.YOTI_APP_BASE_URL}/privacy-policy`)
.withAllowHandoff(true)
.build();
//Buiding the Session with defined specification from above
const sessionSpec = new SessionSpecificationBuilder()
.withClientSessionTokenTtl(600)
.withResourcesTtl(604800)
.withUserTrackingId("some-user-tracking-id")
.withRequestedCheck(documentAuthenticityCheck)
.withRequestedCheck(livenessCheck)
.withRequestedCheck(faceMatchCheck)
.withRequestedTask(textExtractionTask)
.withSdkConfig(sdkConfig)
.build();
//Create Session
sandboxClient
.createSession(sessionSpec)
.then((session) => {
const sessionId = session.getSessionId();
console.log("SESSION ID: " + sessionId);
const clientSessionToken = session.getClientSessionToken();
const clientSessionTokenTtl = session.getClientSessionTokenTtl();
})
.catch((err) => {
// handle err
});