-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathindex.controller.js
64 lines (55 loc) · 1.63 KB
/
index.controller.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
const config = require('../../config');
const {
DocScanClient,
SessionSpecificationBuilder,
SdkConfigBuilder,
} = require('yoti');
/**
* Create a Doc Scan session.
*/
async function createSession() {
const docScanClient = new DocScanClient(
config.YOTI_CLIENT_SDK_ID,
config.YOTI_PEM
);
const subject = {
subject_id: 'subject_id_string',
};
const identityProfileRequirements = {
trust_framework: 'UK_TFIDA',
scheme: {
type: 'DBS',
objective: 'BASIC',
},
};
const sessionSpec = new SessionSpecificationBuilder()
.withClientSessionTokenTtl(600)
.withResourcesTtl(90000)
.withUserTrackingId('some-user-tracking-id')
.withSubject(subject)
.withIdentityProfileRequirements(identityProfileRequirements)
.withSdkConfig(
new SdkConfigBuilder()
.withPrimaryColour('#2d9fff')
.withLocale('en-GB')
.withPresetIssuingCountry('GBR')
.withSuccessUrl(`${config.YOTI_APP_BASE_URL}/success`)
.withErrorUrl(`${config.YOTI_APP_BASE_URL}/error`)
.withAllowHandoff(true)
.build()
)
.build();
return docScanClient.createSession(sessionSpec);
}
module.exports = async (req, res) => {
try {
const session = await createSession();
req.session.DOC_SCAN_SESSION_ID = session.getSessionId();
req.session.DOC_SCAN_SESSION_TOKEN = session.getClientSessionToken();
res.render('pages/index', {
iframeUrl: `${config.YOTI_DOC_SCAN_IFRAME_URL}?sessionID=${req.session.DOC_SCAN_SESSION_ID}&sessionToken=${req.session.DOC_SCAN_SESSION_TOKEN}`,
});
} catch (error) {
res.render('pages/error', { error });
}
};