|
| 1 | +const { |
| 2 | + IDVClient, |
| 3 | + SessionSpecificationBuilder, |
| 4 | + SdkConfigBuilder, |
| 5 | + RequiredIdDocumentBuilder, |
| 6 | + RequestedDocumentAuthenticityCheckBuilder, |
| 7 | + RequestedTextExtractionTaskBuilder, |
| 8 | +} = require('yoti'); |
| 9 | +const config = require('../../../config'); |
| 10 | + |
| 11 | +/** |
| 12 | + * Create an IDV session. |
| 13 | + */ |
| 14 | +async function createSession() { |
| 15 | + const idvClient = new IDVClient( |
| 16 | + config.YOTI_CLIENT_SDK_ID, |
| 17 | + config.YOTI_PEM |
| 18 | + ); |
| 19 | + |
| 20 | + const sessionSpec = new SessionSpecificationBuilder() |
| 21 | + .withClientSessionTokenTtl(600) // 10 minutes |
| 22 | + .withResourcesTtl(90000) // session TTL(10 minutes) + 24 hours(minimum required) |
| 23 | + .withUserTrackingId('some-user-tracking-id') |
| 24 | + .withRequestedCheck( |
| 25 | + new RequestedDocumentAuthenticityCheckBuilder() |
| 26 | + .withManualCheckFallback() |
| 27 | + .build() |
| 28 | + ) |
| 29 | + .withRequestedTask( |
| 30 | + new RequestedTextExtractionTaskBuilder() |
| 31 | + .withManualCheckFallback() |
| 32 | + .withChipDataDesired() |
| 33 | + .withCreateExpandedDocumentFields(true) // default is false |
| 34 | + .build() |
| 35 | + ) |
| 36 | + .withSdkConfig( |
| 37 | + new SdkConfigBuilder() |
| 38 | + .withAllowsCameraAndUpload() |
| 39 | + .withPrimaryColour('#2d9fff') |
| 40 | + .withSecondaryColour('#FFFFFF') |
| 41 | + .withFontColour('#FFFFFF') |
| 42 | + .withLocale('en-GB') |
| 43 | + .withPresetIssuingCountry('GBR') |
| 44 | + .withSuccessUrl(`${config.YOTI_APP_BASE_URL}/success`) |
| 45 | + .withErrorUrl(`${config.YOTI_APP_BASE_URL}/error`) |
| 46 | + .withAllowHandoff(true) |
| 47 | + .withIdDocumentTextExtractionGenericRetries(3) |
| 48 | + .withIdDocumentTextExtractionReclassificationRetries(3) |
| 49 | + .withSuppressedScreens([ |
| 50 | + 'ID_DOCUMENT_EDUCATION', |
| 51 | + 'ID_DOCUMENT_REQUIREMENTS', |
| 52 | + ]) |
| 53 | + .build() |
| 54 | + ) |
| 55 | + .withRequiredDocument( |
| 56 | + (new RequiredIdDocumentBuilder()).build() |
| 57 | + ) |
| 58 | + .build(); |
| 59 | + |
| 60 | + return idvClient.createSession(sessionSpec); |
| 61 | +} |
| 62 | + |
| 63 | +module.exports = async (req, res) => { |
| 64 | + try { |
| 65 | + const session = await createSession(); |
| 66 | + |
| 67 | + req.session.IDV_SESSION_ID = session.getSessionId(); |
| 68 | + req.session.IDV_SESSION_TOKEN = session.getClientSessionToken(); |
| 69 | + |
| 70 | + res.render('pages/session', { |
| 71 | + sessionId: req.session.IDV_SESSION_ID, |
| 72 | + iframeUrl: `${config.YOTI_IDV_IFRAME_URL}?sessionID=${req.session.IDV_SESSION_ID}&sessionToken=${req.session.IDV_SESSION_TOKEN}`, |
| 73 | + }); |
| 74 | + } catch (error) { |
| 75 | + res.render('pages/error', { error }); |
| 76 | + } |
| 77 | +}; |
0 commit comments