Skip to content

Commit

Permalink
SDK-2420 Added support for advanced identity profile and examples
Browse files Browse the repository at this point in the history
  • Loading branch information
mehmet-yoti committed Jul 2, 2024
1 parent 399e849 commit 272c8cc
Show file tree
Hide file tree
Showing 5 changed files with 175 additions and 1 deletion.
1 change: 0 additions & 1 deletion .php-cs-fixer.cache

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Routing\Controller as BaseController;
use Illuminate\Support\Facades\Log;
use mysql_xdevapi\Exception;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Yoti\DigitalIdentityClient;
use Yoti\Identity\Policy\PolicyBuilder;
use Yoti\Identity\ShareSessionRequestBuilder;
use Yoti\YotiClient;

class AdvancedIdentityController extends BaseController
{
public function generateSession(DigitalIdentityClient $client)
{
try {
$advancedIdentityProfileJson = '
{
"profiles": [
{
"trust_framework": "YOTI_GLOBAL",
"schemes": [
{
"label": "identity-AL-L1",
"type": "IDENTITY",
"objective": "AL_L1"
},
{
"label": "identity-AL-M1",
"type": "IDENTITY",
"objective": "AL_M1"
}
]
}
]
}';

$policy = (new PolicyBuilder())
->withAdvancedIdentityProfileRequirements($advancedIdentityProfileJson)
->build();

$redirectUri = 'https://host/redirect/';

$shareSessionRequest = (new ShareSessionRequestBuilder())
->withPolicy($policy)
->withRedirectUri($redirectUri)
->build();
$session = $client->createShareSession($shareSessionRequest);
return $session->getId();
}
catch (\Throwable $e) {
Log::error($e->getTraceAsString());
throw new BadRequestHttpException($e->getMessage());
}
}
public function show(DigitalIdentityClient $client)
{
try {
return view('advancedidentity', [
'title' => 'Digital Identity(Advanced) Complete Example',
'sdkId' => $client->id
]);
} catch (\Throwable $e) {
Log::error($e->getTraceAsString());
throw new BadRequestHttpException($e->getMessage());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<!DOCTYPE html>
<html class="yoti-html">

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>{{ $title }}</title>
<link rel="stylesheet" type="text/css" href="assets/css/index.css">
<link href="https://fonts.googleapis.com/css?family=Roboto:400,700" rel="stylesheet">
</head>

<body class="yoti-body">
<main>
<section class="yoti-top-section">
<div class="yoti-logo-section">
<a href="https://www.yoti.com" target="_blank">
<img class="yoti-logo-image" src="assets/images/logo.png" srcset="assets/images/[email protected] 2x"
alt="Yoti"/>
</a>
</div>
<h1 class="yoti-top-header">Digital Identity(Advanced)4 Share Example</h1>

<div class="yoti-sdk-integration-section">
<div id="webshare-target"></div>
</div>

</section>

<section class="yoti-sponsor-app-section">
<h3 class="yoti-sponsor-app-header">The Yoti app is free to download and use:</h3>

<div class="yoti-store-buttons-section">
<a href="https://itunes.apple.com/us/app/yoti/id983980808?ls=1&mt=8" class="yoti-app-button-link">
<img src="assets/images/app-store-badge.png"
srcset="assets/images/[email protected] 2x"
alt="Download on the App Store" />
</a>

<a href="https://play.google.com/store/apps/details?id=com.yoti.mobile.android.live" class="yoti-app-button-link">
<img src="assets/images/google-play-badge.png"
srcset="assets/images/[email protected] 2x"
alt="get it on Google Play" />
</a>
</div>
</section>
</main>
<script>async function onSessionIdResolver() {
const response = await fetch('/generate-advanced-identity-session');
if (!response.ok) {
throw new Error('Response was not ok');
}
const result = await response.text();
console.log("session id %s", result);
return result;
}
async function completionHandler(receivedReceiptId) {
console.log('completion handler:', receivedReceiptId)
const url = '/receipt-info?ReceiptID=' + encodeURIComponent(receivedReceiptId);
window.location.href = url;
}
function onErrorListener(...data) {
console.warn('onErrorListener:', ...data)
}
async function onReadyToStart() {
const { Yoti } = window
await Yoti.createWebShare({
name: 'Use Yoti',
domId: 'webshare-target',
sdkId: '{{$sdkId}}',
hooks: {
sessionIdResolver: onSessionIdResolver,
errorListener: onErrorListener,
completionHandler,
},
flow: "REVEAL_MODAL"
})
}
async function onClientLoaded() {
const { Yoti } = window
await Yoti.ready()
await onReadyToStart()
}</script>
<script src="https://www.yoti.com/share/client/v2" onload="onClientLoaded()"></script>
</body>
</html>
2 changes: 2 additions & 0 deletions examples/digitalidentity/routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@
Route::get('/generate-share', 'IdentityController@show');
Route::get('/receipt-info', 'ReceiptController@show');
Route::get('/generate-session', 'IdentityController@generateSession');
Route::get('/generate-advanced-identity-share', 'AdvancedIdentityController@show');
Route::get('/generate-advanced-identity-session', 'AdvancedIdentityController@generateSession');
14 changes: 14 additions & 0 deletions src/Identity/Policy/PolicyBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class PolicyBuilder
private bool $wantedRememberMeOptional = false;

private ?object $identityProfileRequirements = null;
private ?object $advancedIdentityProfileRequirements = null;

public function withWantedAttribute(WantedAttribute $wantedAttribute): self
{
Expand Down Expand Up @@ -318,6 +319,19 @@ public function withIdentityProfileRequirements($identityProfileRequirements): s
return $this;
}

/**
* Use an Advanced Identity Profile Requirement object for the share
*
* @param object $advancedIdentityProfileRequirements
* @return $this
*/
public function withAdvancedIdentityProfileRequirements($advancedIdentityProfileRequirements): self
{
$this->advancedIdentityProfileRequirements = $advancedIdentityProfileRequirements;
return $this;
}



public function build(): Policy
{
Expand Down

0 comments on commit 272c8cc

Please sign in to comment.