Quick start
Here is a quick reference to kickstart your SDK integration. For detailed information, we suggest you read through the step by step integration guide.
Please see below for integration code snippets and example projects.
You will need to access your Yoti Hub account with an e-mail & password or using the Yoti mobile app and to have registered your business with Yoti. Check the below links for more info.
Integration process
An example integration will include the steps highlighted in this section. We have provided code snippets in different languages to integrate Digital ID.
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
Client initialisation
Initialise the Yoti Digital Identity Client using your SDK ID and PEM Key file.
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)
Create share session
Use the Yoti client to configure and create a share session.
const {
DigitalIdentityBuilders: {
PolicyBuilder,
ShareSessionConfigurationBuilder,
}
} = require('yoti');
const policy = new PolicyBuilder()
// using a predefined method to add an attribute
.withFullName()
.withEmail()
// if you wish the user to prove it's them by taking a selfie on share
.withSelfieAuthentication()
.build();
const shareSessionConfig = new ShareSessionConfigurationBuilder()
.withRedirectUri("/your-callback")
.withPolicy(policy)
.build();
yotiClient.createShareSession(shareSessionConfig)
.then((shareSessionResult) => {
const shareSession = shareSessionResult;
const shareSessionId = shareSession.getId();
}).catch((error) => {
console.error(error.message);
});
Client side view
Yoti provides a client-side script that you can include in your html file to display a Yoti button or inline QR code.
In the example below, use the modal button, but please feel free to look at our examples in our integration guide.
<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: 'test',
domId: 'xxx',
sdkId: 'xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
hooks: {
sessionIdResolver: onSessionIdResolver,
errorListener: onErrorListener
},
skinId: 'yoti / digital-id-uk'
})
}
}
const start = async () => {
await loadYoti();
await createYotiWebShare();
}
start().catch((e) => console.error(`Could not create Yoti WebShare: `, e));
</script>
</body>
Retrieve profile
When a share is completed, the webpage where Yoti button/QR is rendered will automatically be redirected to the URL specified in the session configuration. The query parameter of redirectId will be attached to this URL.
You will then use use the receipt id to retrieve a user profile:
yotiClient.getShareReceipt(receiptId)
.then((shareReceipt) => {
const sessionId = shareReceipt.getSessionId();
const rememberMeId = shareReceipt.getRememberMeId();
const parentRememberMeId = shareReceipt.getParentRememberMeId();
const profile = shareReceipt.getProfile();
const fullName = profile.getFullName().value;
const dateOfBirth = profile.getDateOfBirth().getValue();
const gender = profile.getGender().getValue();
const nationality = profile.getNationality().getValue();
const postalAddress = profile.getPostalAddress().getValue();
const emailAddress = profile.getEmailAddress().getValue();
const phoneNumber = profile.getPhoneNumber().getValue();
const selfieImageData = profile.getSelfie().getValue();
const base64SelfieUri = selfieImageData.getBase64Content();
const documentDetails = profile.getDocumentDetails().getValue();
})
Web examples
Our Github links below provide examples for the Digital ID Integration. Please select your preferred language to continue.