Reusable Digital ID
Install the SDK
Once you have added the Yoti SDK dependency to your project, it’s time to initialise a Yoti client as shown in the code snippet below.
Once you have a working Yoti QR/button, you can move on to installing the SDK.
To successfully integrate you will need the following information about your application from Yoti Hub:
- SDK ID
- Your application key pair
The Yoti SDKs are available via popular dependency management systems. Further details can be found on the pages of the specific projects.
To install the Yoti SDK:
// Get the Yoti Node SDK library via the NPM registry
npm install -S -E yoti
Once you have added the Yoti SDK dependency to your project, you can initialise the Yoti Digital Identity Client as shown below:
const Yoti = require('yoti')
const CLIENT_SDK_ID = 'YOTI_CLIENT_SDK_ID'
const PEM_PATH = 'YOTI_KEY_FILE_PATH'
const PEM_KEY = fs.readFileSync(PEM_PATH)
const yotiClient = new Yoti.DigitalIdentityClient(CLIENT_SDK_ID, PEM_KEY)
Using Yoti SDK
The description on how to use the SDK can be found here:
Please read the above for a full description and understanding, below we’ll provide examples on how those requests will expose the new functionality.
const identityProfileRequirements = {
trust_framework: 'UK_TFIDA',
scheme: {
type: 'DBS',
objective: 'STANDARD',
}
};
const subject = {
subject_id: 'subject_id_string',
};
const policy = new Yoti.PolicyBuilder()
.withIdentityProfileRequirements(identityProfileRequirements)
.build();
const notification = new Yoti.ShareSessionNotificationBuilder()
.withUrl("notification-webhook")
.withMethod("POST")
.build();
const shareSessionConfig = new Yoti.ShareSessionConfigurationBuilder()
.withRedirectUri("/your-callback-url")
.withSubject(subject)
.withPolicy(policy)
.withNotification(notification)
.build();
async function getShareSession() {
const shareSession = await yotiClient.createShareSession(shareSessionConfig);
return shareSession;
}
Identity Profile Requirements Explained
Field | Value | Description |
---|---|---|
trust_framework | String | Defines under which trust framework this identity profile should be verified. Enum: UK_TFIDA |
scheme | Object | Defines which scheme this identity profile should satisfy. The scheme must be supported by the specified trust framework otherwise the request is considered invalid. |
type | String | Defines which scheme this identity profile should satisfy. Enum: DBS, RTW, RTR, DBS_RTW |
objective | String | Defines the objective to be achieved for the particular scheme. It must be provided for those schemes where it is mandatory. Example, this is mandatory for DBS and the possible values are: ”BASIC”, “STANDARD”, “ENHANCED”. |
Subject Id Explained
Field | Description |
---|---|
subject_id | allows the RP to track a subject across session creation and session retrieval |
The dynamicScenario can be used to get a shareURL which will be used by the Yoti scripts to generate a Yoti QR code.
Client side view
Once you have the Share session, you can use it on the frontend for it to render a Yoti QR code. Please see example below using the modal QR code.
<head>
<script src="https://www.yoti.com/share/client/v2"></script>
</head>
<body>
<!-- Yoti element will be rendered inside this DOM node -->
<div id="xxx"></div>
<!-- This script snippet will also be required in your HTML body -->
<script>
async function onSessionIdResolver() {
// Make a call to your backend, and return a 'sessionId'
const response = await fetch('http://localhost:3000/sessions', { method: 'POST' });
const data = await response.json();
return data.sessionId;
}
function onErrorListener(data) {
console.warn('onErrorListener:', data);
}
const loadYoti = async () => {
const { Yoti } = window;
if (Yoti) {
console.info('Waiting for Yoti...');
await Yoti.ready()
console.info('Yoti is now ready');
} else {
console.error('Yoti client was not found!');
}
}
const createYotiWebShare = async () => {
const { Yoti } = window;
if (Yoti) {
await Yoti.createWebShare({
name: 'yoti-share',
domId: 'xxx',
sdkId: 'xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
skinId: 'digital-id-uk',
hooks: {
sessionIdResolver: onSessionIdResolver,
errorListener: onErrorListener
}
})
}
}
const start = async () => {
await loadYoti();
await createYotiWebShare();
}
start().catch((e) => console.error(`Could not create Yoti WebShare: `, e));
</script>
</body>
Query parameters
You can append query params to the landing page URL that displays the Yoti QR/button. These will be added to the redirect URI.
For example if you load the landing page containing the Yoti button as follows:
https://example.com/?iso=test&user_id=6667
The query parameters (iso=test&user_id=6667) will be returned in the callback URL.
Response
Further details on how to use the SDK to get shared attributes can be found here:
In case of a successful transaction, once the profile is retrieved, the identity profile report can be accessed.
yotiClient.getShareReceipt(receiptId)
.then((shareReceipt) => {
const sessionId = shareReceipt.getSessionId();
const rememberMeId = shareReceipt.getRememberMeId();
const parentRememberMeId = shareReceipt.getParentRememberMeId();
const profile = shareReceipt.getProfile();
const selfieImageData = profile.getSelfie().getValue();
const base64SelfieUri = selfieImageData.getBase64Content();
const documentDetails = profile.getDocumentDetails().getValue();
const hasIdentityProfile = Boolean(profile.getIdentityProfileReport());
if (hasIdentityProfile) {
const identityProfileReport = profile.getIdentityProfileReport().getValue();
}
})
The identity profile report contains the verified identity details and the verification report that certifies how the identity was verified and how the verification level was achieved.
User experience
There will be instances where we have exhausted all available ‘routes’ to help a user achieve compliance with the requested scheme and not been successful. In these cases the user will not be able to complete the ‘share’, and will be shown a screen which informs them that they cannot continue with the journey in our app. This will trigger a failure sharing scenario, responding back with an associated error code.