Skip to content

Commit

Permalink
SDK-2265 removed profile attributes, updated namings, removed unneces…
Browse files Browse the repository at this point in the history
…sary comments
  • Loading branch information
mehmet-yoti committed Jun 18, 2024
1 parent f63db10 commit 3fce5f2
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 51 deletions.
3 changes: 1 addition & 2 deletions examples/digitalidentity/.env.example
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
# This file is a template for defining the environment variables
# Set the application config values here

YOTI_SCENARIO_ID=xxxxxxxxxxxxxxxx
YOTI_SDK_ID=xxxxxxxxxxxxxxxxxxxxx

# Below is the private key (in .pem format) associated with the Yoti Application you created on Yoti Hub
YOTI_KEY_FILE_PATH=./keys/php-sdk-access-security.pem

# Laravel config:
APP_NAME=yoti.sdk.profile.demo
APP_NAME=yoti.sdk.digitalidentity.demo
APP_ENV=local
APP_KEY=
APP_DEBUG=true
Expand Down
9 changes: 3 additions & 6 deletions examples/digitalidentity/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Profile Example
# Digital Identity Example

## Requirements

Expand All @@ -8,11 +8,10 @@ This example requires [Docker](https://docs.docker.com/)

* Create your application in the [Yoti Hub](https://hub.yoti.com) (this requires having a Yoti account)
* Set the application domain of your app to `localhost:4002`
* Set the scenario callback URL to `/digitalidentity`
* Do the steps below inside the [examples/digitaledentity](./) folder
* Do the steps below inside the [examples/digitalidentity](./) folder
* Put `your-application-pem-file.pem` file inside the [keys](keys) folder, as Docker requires the `.pem` file to reside within the same location where it's run from.
* Copy `.env.example` to `.env`
* Open `.env` file and fill in the environment variables `YOTI_SCENARIO_ID`, `YOTI_SDK_ID`
* Open `.env` file and fill in the environment variable `YOTI_SDK_ID`
* Set `YOTI_KEY_FILE_PATH` to `./keys/your-application-pem-file.pem`
* Install dependencies `docker-compose up composer`
* Run the `docker-compose up --build` command
Expand All @@ -23,5 +22,3 @@ This example requires [Docker](https://docs.docker.com/)
## Digital Identity Example
* Visit [/generate-share](https://localhost:4002/generate-share)

> To see how to create a dynamic scenario, refer to the [Digital Identity controller](app/Http/Controllers/IdentityController.php)
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

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;
Expand All @@ -12,7 +13,7 @@

class IdentityController extends BaseController
{
public function show(DigitalIdentityClient $client)
public function generateSession(DigitalIdentityClient $client)
{
try {

Expand All @@ -36,39 +37,20 @@ public function show(DigitalIdentityClient $client)
->withPolicy($policy)
->withRedirectUri($redirectUri)
->build();

$session = $client->createShareSession($shareSessionRequest);

$createdQrCode = $client->createShareQrCode($session->getId());

$fetchedQrCode = $client->fetchShareQrCode($createdQrCode->getId());

$sessionFetched = $client->fetchShareSession($session->getId());

return $session->getId();
}
catch (\Throwable $e) {
Log::error($e->getTraceAsString());
throw new BadRequestHttpException($e->getMessage());
}
}
public function show(DigitalIdentityClient $client)
{
try {
return view('identity', [
'title' => 'Digital Identity Complete Example',
// Creating session
'sessionId' => $session->getId(),
'sessionStatus' => $session->getStatus(),
'sessionExpiry' => $session->getExpiry(),
// Creating QR code
'createdQrCodeId' => $createdQrCode->getId(),
'createdQrCodeUri' => $createdQrCode->getUri(),
// Fetch QR code
'fetchedQrCodeExpiry' => $fetchedQrCode->getExpiry(),

'fetchedQrCodeRedirectUri' => $fetchedQrCode->getRedirectUri(),
'fetchedQrCodeSessionId' => $fetchedQrCode->getSession()->getId(),
'fetchedQrCodeSessionStatus' => $fetchedQrCode->getSession()->getStatus(),
'fetchedQrCodeSessionExpiry' => $fetchedQrCode->getSession()->getExpiry(),
// Fetch session
'fetchedSessionId' => $sessionFetched->getId(),
'fetchedSessionStatus' => $sessionFetched->getStatus(),
'fetchedSessionExpiry' => $sessionFetched->getExpiry(),
'fetchedSessionCreated' => $sessionFetched->getCreated(),
'fetchedSessionUpdated' => $sessionFetched->getUpdated(),
'sdkId' => $client->id

]);
} catch (\Throwable $e) {
Log::error($e->getTraceAsString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@ public function show(Request $request, DigitalIdentityClient $client, ?LoggerInt
$logger = $logger ?? new Logger();

$logger->warning("Unknown Content Type parsing as a String");
$activityDetails = $client->fetchShareReceipt($request->query('ReceiptID'));
$shareReceipt = $client->fetchShareReceipt($request->query('ReceiptID'));

// error_log("-------" . $activityDetails->getProfile()->getFullName()->getValue());

$profile = $activityDetails->getProfile();
$profile = $shareReceipt->getProfile();

return view('receipt', [
'fullName' => $profile->getFullName(),
Expand Down
1 change: 0 additions & 1 deletion examples/digitalidentity/config/yoti.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

return [
'client.sdk.id' => env('YOTI_SDK_ID'),
'scenario.id' => env('YOTI_SCENARIO_ID'),
'pem.file.path' => (function($filePath) {
return strpos($filePath, '/') === 0 ? $filePath : base_path($filePath);
})(env('YOTI_KEY_FILE_PATH')),
Expand Down
16 changes: 8 additions & 8 deletions examples/digitalidentity/resources/views/identity.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
</head>

<body class="yoti-body">
<main>


<main>
<section class="yoti-top-section">
<div class="yoti-logo-section">
Expand Down Expand Up @@ -47,14 +44,19 @@
</div>
</section>
</main>
<script>async function onSessionIdResolver(id) {
return '{{$sessionId}}'
<script>async function onSessionIdResolver() {
const response = await fetch('/generate-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;
}
Expand Down Expand Up @@ -83,7 +85,5 @@ function onErrorListener(...data) {
await onReadyToStart()
}</script>
<script src="https://www.yoti.com/share/client/v2" onload="onClientLoaded()"></script>

</body>

</html>
1 change: 1 addition & 0 deletions examples/digitalidentity/routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@

Route::get('/generate-share', 'IdentityController@show');
Route::get('/receipt-info', 'ReceiptController@show');
Route::get('/generate-session', 'IdentityController@generateSession');

0 comments on commit 3fce5f2

Please sign in to comment.