Skip to content

Commit

Permalink
Updated the example to add support to view the report containing adva…
Browse files Browse the repository at this point in the history
…nced identity profile specific properties.
  • Loading branch information
dhivya-pattabhiraman committed Jan 24, 2024
1 parent 2e8469e commit 1e6f3a5
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 36 deletions.
77 changes: 63 additions & 14 deletions examples/profile-identity-checks/controllers/report.controller.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable camelcase */
const Yoti = require('yoti');
const config = require('../config');

Expand All @@ -14,8 +15,12 @@ module.exports = async (req, res) => {

let identityAssertion = null;
let verificationReport = null;
let verificationReports = null;
let authenticationReport = null;
let authenticationReports = null;
let identityAssertionProof = null;
let documentImagesAttributes = [];
let selfieAttribute = null;
let errorDetails = null;

try {
Expand All @@ -26,22 +31,62 @@ module.exports = async (req, res) => {
const profile = activityDetails.getProfile();
const identityProfile = profile.getIdentityProfileReport().getValue();
const {
identity_assertion: assertion,
verification_report: verification,
authentication_report: authentication,
identity_assertion,
verification_report,
verification_reports,
authentication_report,
authentication_reports,
proof,
} = identityProfile;

identityAssertion = assertion;
verificationReport = verification;
authenticationReport = authentication;

const { evidence } = verificationReport;
const { documents } = evidence;
documentImagesAttributes = documents
// eslint-disable-next-line camelcase
.map(({ document_images_attribute_id }) => (document_images_attribute_id
? (profile && profile.getAttributeById(document_images_attribute_id)) : null))
.filter((documentImagesAttribute) => documentImagesAttribute);
identityAssertion = identity_assertion;
verificationReport = verification_report;
verificationReports = verification_reports;
authenticationReport = authentication_report;
authenticationReports = authentication_reports;
identityAssertionProof = proof;

if (verificationReport) {
const { evidence } = verificationReport;
const { face, documents } = evidence;

// Document images (if any)
documentImagesAttributes = documents
.map(({ document_images_attribute_id }) => (document_images_attribute_id
? (profile && profile.getAttributeById(document_images_attribute_id)) : null))
.filter((documentImagesAttribute) => documentImagesAttribute);

// Selfie image (if any)
const { selfie_attribute_id } = face;
selfieAttribute = selfie_attribute_id
? (profile && profile.getAttributeById(selfie_attribute_id))
: null;
} else if (verificationReports.length > 0) {
// Document images (if any)
const documentImagesAttributesArray = verificationReports.map((report) => {
const { evidence } = report;
const { documents } = evidence;

return documents
.map(({ document_images_attribute_id }) => (document_images_attribute_id
? (profile && profile.getAttributeById(document_images_attribute_id)) : null))
.filter((documentImagesAttribute) => documentImagesAttribute);
});
documentImagesAttributes = [].concat(...documentImagesAttributesArray);

// Selfie image (if any)
const selfieAttributeArray = verificationReports.map((report) => {
const { evidence } = report;
const { face } = evidence;
const { selfie_attribute_id } = face;

return selfie_attribute_id
? (profile && profile.getAttributeById(selfie_attribute_id))
: null;
});
// eslint-disable-next-line prefer-destructuring
selfieAttribute = selfieAttributeArray.filter((selfie) => selfie)[0];
}
} else {
errorDetails = activityDetails.getErrorDetails();
}
Expand All @@ -50,8 +95,12 @@ module.exports = async (req, res) => {
outcome,
identityAssertion,
verificationReport,
verificationReports,
authenticationReport,
authenticationReports,
identityAssertionProof,
documentImagesAttributes,
selfieAttribute,
errorDetails,
});
} catch (err) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,70 @@
<section>
<div class="yoti-report-section">
<% if (outcome === 'SUCCESS' ) { %>
<div>
<h4>Identity assertion:</h4>
<pre><%= JSON.stringify(identityAssertion, null, 2) %></pre>
</div>
<div>
<h4>Verification report:</h4>
<pre><%= JSON.stringify(verificationReport, null, 2) %></pre>
</div>
<div>
<h4>Authentication report:</h4>
<pre><%= JSON.stringify(authenticationReport, null, 2) %></pre>
</div>
<div>
<h4>Documents images attributes:</h4>
<% documentImagesAttributes.forEach((docImgAttr) => { %>
<span>Document image ID: </span>
<span><%= docImgAttr.getId() %></span>
<% if (identityAssertion ) { %>
<div>
<h4>Identity assertion:</h4>
<pre><%= JSON.stringify(identityAssertion, null, 2) %></pre>
</div>
<% } %>
<% if (verificationReport ) { %>
<div>
<h4>Verification report:</h4>
<pre><%= JSON.stringify(verificationReport, null, 2) %></pre>
</div>
<% } %>
<% if (authenticationReport ) { %>
<div>
<h4>Authentication report:</h4>
<pre><%= JSON.stringify(authenticationReport, null, 2) %></pre>
</div>
<% } %>
<% if (verificationReports && verificationReports.length !== 0 ) { %>
<div>
<h4>Verification reports:</h4>
<pre><%= JSON.stringify(verificationReports, null, 2) %></pre>
</div>
<% } %>
<% if (authenticationReports && authenticationReports.length !== 0 ) { %>
<div>
<h4>Authentication reports:</h4>
<pre><%= JSON.stringify(authenticationReports, null, 2) %></pre>
</div>
<% } %>
<% if (identityAssertionProof ) { %>
<div>
<h4>Proof:</h4>
<pre><%= JSON.stringify(identityAssertionProof, null, 2) %></pre>
</div>
<% } %>
<% if (documentImagesAttributes && documentImagesAttributes.length !== 0 ) { %>
<div>
<h4>Documents images attributes:</h4>
<% documentImagesAttributes.forEach((docImgAttr) => { %>
<span>Document image ID: </span>
<span><%= docImgAttr.getId() %></span>
<br>
<br>
<% docImgAttr.getValue().forEach((image) => { %>
<img src="<%= image.getBase64Content() %>" alt="Document image"/>
<% }) %>
<br>
<br>
<% }) %>
</div>
<% } %>
<% if (selfieAttribute ) { %>
<div>
<h4>Selfie:</h4>
<span>Selfie ID: </span>
<span><%= selfieAttribute.getId() %></span>
<br>
<br>
<% docImgAttr.getValue().forEach((image) => { %>
<img src="<%= image.getBase64Content() %>" alt="Document image"/>
<% }) %>
<% }) %>
</div>
<img src="<%= selfieAttribute.getValue().getBase64Content() %>" alt="Selfie"/>
<br>
<br>
</div>
<% } %>
<% } else { %>
<div>
<h4>Sorry, the check was not successful</h4>
Expand Down

0 comments on commit 1e6f3a5

Please sign in to comment.