Skip to content

Commit

Permalink
Initial work to enable requesting in v1/v2 a share with `advanced_ide…
Browse files Browse the repository at this point in the history
…ntity_profile_requirements`.

Updated examples (to be improved).
  • Loading branch information
laurent-yoti committed Oct 4, 2023
1 parent 8706361 commit 86566bd
Show file tree
Hide file tree
Showing 11 changed files with 349 additions and 13 deletions.
58 changes: 55 additions & 3 deletions examples/digital-identity/controllers/share.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,65 @@ router.get('/get-new-session-id', async (req, res) => {

const policyBuilder = new PolicyBuilder();

if (policyType === 'RTW') {
policyBuilder.withIdentityProfileRequirements({
const CASE_RTW = 'RTW';
const CASE_MTFIP = 'MTFIP';

if (policyType === CASE_RTW) {
const existingSingleIPRequirements = {
trust_framework: 'UK_TFIDA',
scheme: {
type: 'RTW',
},
});
};
policyBuilder.withIdentityProfileRequirements(existingSingleIPRequirements);
} else if (policyType === CASE_MTFIP) {
const newMultipleIPRequirements = {
profiles: [
{
trust_framework: 'UK_TFIDA',
schemes: [
{
label: 'LB912',
type: 'RTW',
},
{
label: 'LB777',
type: 'DBS',
objective: 'BASIC',
},
],
},
{
trust_framework: 'YOTI_GLOBAL',
schemes: [
{
// LABEL has to be unique across all profiles not just the schemes in this list.
label: 'LB321',
type: 'IDENTITY',
objective: 'AL_L1',
config: {
document_filter: {
allowlist: true, // only supported value for now is TRUE
documents: [
{
country_codes: [], // empty means all are accepted
document_types: ['PASSPORT'], // empty means all are accepted
},
{
country_codes: ['USA'], // empty means all are accepted
document_types: ['DRIVING_LICENCE', 'STATE_ID'], // empty means all are accepted
},
],
},
// Not to be implemented yet, TBC. If not provided default to ALL_EVIDENCE.
// "return_evidence_images": OFF | DOCUMENTS_ONLY | ALL_EVIDENCE
},
},
],
},
],
};
policyBuilder.withAdvancedIdentityProfileRequirements(newMultipleIPRequirements);
} else {
policyBuilder.withFullName()
.withEmail()
Expand Down
4 changes: 3 additions & 1 deletion examples/digital-identity/static/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@

.yoti-share-buttons-section {
display: flex;
gap: 1em
gap: 1em;
flex-wrap: wrap;
justify-content: center;
}

.yoti-share-button-container {
Expand Down
23 changes: 23 additions & 0 deletions examples/digital-identity/views/pages/share.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@
</p>
<div id="yoti-share-button-right-to-work"></div>
</div>
<div class="yoti-share-button-container">
<p>
Start the flow to assert with Multiple Identity Profile
</p>
<div id="yoti-share-button-multiple-identity-profile"></div>
</div>

</div>

Expand Down Expand Up @@ -144,6 +150,8 @@
completionHandler,
errorListener,
},
skinId: 'didc',
flow: 'REVEAL_MODAL'
})
await Yoti.createWebShare({
Expand All @@ -155,6 +163,21 @@
completionHandler,
errorListener,
},
skinId: 'didc',
flow: 'REVEAL_MODAL'
})
await Yoti.createWebShare({
name: 'share example Multiple Framework',
domId: 'yoti-share-button-multiple-identity-profile',
sdkId: "<%= yotiClientSdkId %>",
hooks: {
sessionIdResolver: ()=>sessionIdResolver('MTFIP'),
completionHandler,
errorListener,
},
skinId: 'didc',
flow: 'REVEAL_MODAL'
})
} else {
console.error('Yoti client was not found!')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,73 @@ const identityProfileRequirementsDescriptors = {
objective: 'BASIC',
},
},
MTF_BASE: {
profiles: [
{
trust_framework: 'UK_TFIDA',
schemes: [
{
label: 'LB912',
type: 'RTW',
},
{
label: 'LB777',
type: 'DBS',
objective: 'BASIC',
},
],
},
{
trust_framework: 'YOTI_GLOBAL',
schemes: [
{
// LABEL has to be unique across all profiles not just the schemes in this list.
label: 'LB321',
type: 'IDENTITY',
objective: 'AL_L1',
config: {
document_filter: {
allowlist: true, // only supported value for now is TRUE
documents: [
{
country_codes: [], // empty means all are accepted
document_types: ['PASSPORT'], // empty means all are accepted
},
{
country_codes: ['USA'], // empty means all are accepted
document_types: ['DRIVING_LICENCE', 'STATE_ID'], // empty means all are accepted
},
],
},
// "return_evidence_images": OFF | DOCUMENTS_ONLY | ALL_EVIDENCE
// Not to be implemented yet, TBC. If not provided default to ALL_EVIDENCE.
},
},
],
},
],
},
};

module.exports = async (req, res) => {
const { scheme } = req.query;
const dynamicPolicyBuilder = new Yoti.DynamicPolicyBuilder();

if (scheme === 'MTF_BASE') {
const identityProfileRequirementsDescriptor = identityProfileRequirementsDescriptors.MTF_BASE;
dynamicPolicyBuilder
.withAdvancedIdentityProfileRequirements(identityProfileRequirementsDescriptor);
} else {
dynamicPolicyBuilder
.withIdentityProfileRequirements(identityProfileRequirementsDescriptors[scheme]);
}

const identityProfileRequirementsDescriptor = identityProfileRequirementsDescriptors[scheme];
const dynamicPolicy = dynamicPolicyBuilder.build();

const subject = {
subject_id: 'subject_id_string',
};

const dynamicPolicy = new Yoti.DynamicPolicyBuilder()
.withIdentityProfileRequirements(identityProfileRequirementsDescriptor)
.build();

const dynamicScenario = new Yoti.DynamicScenarioBuilder()
.withCallbackEndpoint('/identity-profile-report')
.withPolicy(dynamicPolicy)
Expand Down
1 change: 1 addition & 0 deletions examples/profile-identity-checks/views/pages/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<option value="DBS_BASIC">DBS_BASIC</option>
<option value="RTW">RTW</option>
<option value="RTR">RTR</option>
<option value="MTF_BASE">Mutiple TF - UK_TFIDA-RTW_DBS_BASIC+YOTI_GLOBAL-IDENTITY_AL_L1</option>
</select>
</div>
<div class="yoti-sdk-integration-section">
Expand Down
11 changes: 10 additions & 1 deletion src/digital_identity_service/policy/policy.builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,14 @@ module.exports = class PolicyBuilder {
return this;
}

/**
* @param {object} advancedIdentityProfileRequirements
*/
withAdvancedIdentityProfileRequirements(advancedIdentityProfileRequirements) {
this.advancedIdentityProfileRequirements = advancedIdentityProfileRequirements;
return this;
}

/**
* @returns {Policy}
*/
Expand All @@ -320,7 +328,8 @@ module.exports = class PolicyBuilder {
Object.keys(this.wantedAttributes).map((k) => this.wantedAttributes[k]),
this.wantedAuthTypes.filter((value, index, self) => self.indexOf(value) === index),
this.wantedRememberMe,
this.identityProfileRequirements
this.identityProfileRequirements,
this.advancedIdentityProfileRequirements
);
}
};
22 changes: 21 additions & 1 deletion src/digital_identity_service/policy/policy.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ module.exports = class Policy {
* @param {integer[]} wantedAuthTypes - auth types represents the authentication type to be used.
* @param {boolean} wantedRememberMe
* @param {object} identityProfileRequirements
* @param {object} advancedIdentityProfileRequirements
*/
constructor(
wantedAttributes,
wantedAuthTypes,
wantedRememberMe = false,
identityProfileRequirements = null
identityProfileRequirements = null,
advancedIdentityProfileRequirements = null
) {
Validation.isArrayOfType(wantedAttributes, WantedAttribute, 'wantedAttribute');
this.wantedAttributes = wantedAttributes;
Expand All @@ -38,6 +40,11 @@ module.exports = class Policy {
Validation.isPlainObject(identityProfileRequirements, 'identityProfileRequirements');
this.identityProfileRequirements = identityProfileRequirements;
}

if (advancedIdentityProfileRequirements) {
Validation.isPlainObject(advancedIdentityProfileRequirements, 'advancedIdentityProfileRequirements');
this.advancedIdentityProfileRequirements = advancedIdentityProfileRequirements;
}
}

/**
Expand Down Expand Up @@ -68,6 +75,13 @@ module.exports = class Policy {
return this.identityProfileRequirements;
}

/**
* @return {Object}
*/
getAdvancedIdentityProfileRequirements() {
return this.advancedIdentityProfileRequirements;
}

/**
* @returns {Object} data for JSON.stringify()
*/
Expand All @@ -79,6 +93,12 @@ module.exports = class Policy {
wanted_remember_me_optional: false,
};
const identityProfileRequirements = this.getIdentityProfileRequirements();
const advancedIdentityProfileRequirements = this.getAdvancedIdentityProfileRequirements();
if (advancedIdentityProfileRequirements) {
return Object.assign(base, {
advanced_identity_profile_requirements: advancedIdentityProfileRequirements,
});
}
if (identityProfileRequirements) {
return Object.assign(base, { identity_profile_requirements: identityProfileRequirements });
}
Expand Down
11 changes: 10 additions & 1 deletion src/dynamic_sharing_service/policy/dynamic.policy.builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,14 @@ module.exports = class DynamicPolicyBuilder {
return this;
}

/**
* @param {object} advancedIdentityProfileRequirements
*/
withAdvancedIdentityProfileRequirements(advancedIdentityProfileRequirements) {
this.advancedIdentityProfileRequirements = advancedIdentityProfileRequirements;
return this;
}

/**
* @returns {DynamicPolicy}
*/
Expand All @@ -320,7 +328,8 @@ module.exports = class DynamicPolicyBuilder {
Object.keys(this.wantedAttributes).map((k) => this.wantedAttributes[k]),
this.wantedAuthTypes.filter((value, index, self) => self.indexOf(value) === index),
this.wantedRememberMe,
this.identityProfileRequirements
this.identityProfileRequirements,
this.advancedIdentityProfileRequirements
);
}
};
22 changes: 21 additions & 1 deletion src/dynamic_sharing_service/policy/dynamic.policy.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ module.exports = class DynamicPolicy {
* @param {integer[]} wantedAuthTypes - auth types represents the authentication type to be used.
* @param {boolean} wantedRememberMe
* @param {object} identityProfileRequirements
* @param {object} advancedIdentityProfileRequirements
*/
constructor(
wantedAttributes,
wantedAuthTypes,
wantedRememberMe = false,
identityProfileRequirements = null
identityProfileRequirements = null,
advancedIdentityProfileRequirements = null
) {
Validation.isArrayOfType(wantedAttributes, WantedAttribute, 'wantedAttribute');
this.wantedAttributes = wantedAttributes;
Expand All @@ -38,6 +40,11 @@ module.exports = class DynamicPolicy {
Validation.isPlainObject(identityProfileRequirements, 'identityProfileRequirements');
this.identityProfileRequirements = identityProfileRequirements;
}

if (advancedIdentityProfileRequirements) {
Validation.isPlainObject(advancedIdentityProfileRequirements, 'advancedIdentityProfileRequirements');
this.advancedIdentityProfileRequirements = advancedIdentityProfileRequirements;
}
}

/**
Expand Down Expand Up @@ -68,6 +75,13 @@ module.exports = class DynamicPolicy {
return this.identityProfileRequirements;
}

/**
* @return {Object}
*/
getAdvancedIdentityProfileRequirements() {
return this.advancedIdentityProfileRequirements;
}

/**
* @returns {Object} data for JSON.stringify()
*/
Expand All @@ -79,6 +93,12 @@ module.exports = class DynamicPolicy {
wanted_remember_me_optional: false,
};
const identityProfileRequirements = this.getIdentityProfileRequirements();
const advancedIdentityProfileRequirements = this.getAdvancedIdentityProfileRequirements();
if (advancedIdentityProfileRequirements) {
return Object.assign(base, {
advanced_identity_profile_requirements: advancedIdentityProfileRequirements,
});
}
if (identityProfileRequirements) {
return Object.assign(base, { identity_profile_requirements: identityProfileRequirements });
}
Expand Down
Loading

0 comments on commit 86566bd

Please sign in to comment.