-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* SDK-2265-examples - updated routes * SDK-2265 anchor updates * SDK-2265 removed profile attributes, updated namings, removed unnecessary comments
- Loading branch information
1 parent
3dcc7a7
commit a6d34f6
Showing
84 changed files
with
3,420 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# This file is a template for defining the environment variables | ||
# Set the application config values here | ||
|
||
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.digitalidentity.demo | ||
APP_ENV=local | ||
APP_KEY= | ||
APP_DEBUG=true | ||
APP_URL=http://localhost |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/node_modules | ||
/public/hot | ||
/public/storage | ||
/storage/*.key | ||
/vendor | ||
.env | ||
.env.backup | ||
.phpunit.result.cache | ||
Homestead.json | ||
Homestead.yaml | ||
npm-debug.log | ||
yarn-error.log | ||
|
||
*.pem | ||
keys/*.pem | ||
sdk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Digital Identity Example | ||
|
||
## Requirements | ||
|
||
This example requires [Docker](https://docs.docker.com/) | ||
|
||
## Setup | ||
|
||
* 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` | ||
* 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 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 | ||
* Visit [https://localhost:4002](https://localhost:4002) | ||
* Run the `docker-compose stop` command to stop the containers. | ||
|
||
> To see how to retrieve activity details using the one time use token, refer to the [digitalidentity controller](app/Http/Controllers/IdentityController.php) | ||
## Digital Identity Example | ||
* Visit [/generate-share](https://localhost:4002/generate-share) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace App\Console; | ||
|
||
use Illuminate\Console\Scheduling\Schedule; | ||
use Illuminate\Foundation\Console\Kernel as ConsoleKernel; | ||
|
||
class Kernel extends ConsoleKernel | ||
{ | ||
/** | ||
* The Artisan commands provided by your application. | ||
* | ||
* @var array | ||
*/ | ||
protected $commands = [ | ||
// | ||
]; | ||
|
||
/** | ||
* Define the application's command schedule. | ||
* | ||
* @param \Illuminate\Console\Scheduling\Schedule $schedule | ||
* @return void | ||
*/ | ||
protected function schedule(Schedule $schedule) | ||
{ | ||
// $schedule->command('inspire')->hourly(); | ||
} | ||
|
||
/** | ||
* Register the commands for the application. | ||
* | ||
* @return void | ||
*/ | ||
protected function commands() | ||
{ | ||
$this->load(__DIR__.'/Commands'); | ||
|
||
require base_path('routes/console.php'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
namespace App\Exceptions; | ||
|
||
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; | ||
use Throwable; | ||
|
||
class Handler extends ExceptionHandler | ||
{ | ||
/** | ||
* A list of the exception types that are not reported. | ||
* | ||
* @var array | ||
*/ | ||
protected $dontReport = [ | ||
// | ||
]; | ||
|
||
/** | ||
* A list of the inputs that are never flashed for validation exceptions. | ||
* | ||
* @var array | ||
*/ | ||
protected $dontFlash = [ | ||
'password', | ||
'password_confirmation', | ||
]; | ||
|
||
/** | ||
* Report or log an exception. | ||
* | ||
* @param \Throwable $exception | ||
* @return void | ||
* | ||
* @throws \Exception | ||
*/ | ||
public function report(Throwable $exception) | ||
{ | ||
parent::report($exception); | ||
} | ||
|
||
/** | ||
* Render an exception into an HTTP response. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @param \Throwable $exception | ||
* @return \Symfony\Component\HttpFoundation\Response | ||
* | ||
* @throws \Throwable | ||
*/ | ||
public function render($request, Throwable $exception) | ||
{ | ||
return parent::render($request, $exception); | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
examples/digitalidentity/app/Http/Controllers/IdentityController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?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 IdentityController extends BaseController | ||
{ | ||
public function generateSession(DigitalIdentityClient $client) | ||
{ | ||
try { | ||
|
||
$policy = (new PolicyBuilder()) | ||
->withFamilyName() | ||
->withGivenNames() | ||
->withFullName() | ||
->withDateOfBirth() | ||
->withGender() | ||
->withNationality() | ||
->withPhoneNumber() | ||
->withSelfie() | ||
->withEmail() | ||
->withDocumentDetails() | ||
->withDocumentImages() | ||
->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('identity', [ | ||
'title' => 'Digital Identity Complete Example', | ||
'sdkId' => $client->id | ||
]); | ||
} catch (\Throwable $e) { | ||
Log::error($e->getTraceAsString()); | ||
throw new BadRequestHttpException($e->getMessage()); | ||
} | ||
} | ||
} |
124 changes: 124 additions & 0 deletions
124
examples/digitalidentity/app/Http/Controllers/ReceiptController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use Yoti\DigitalIdentityClient; | ||
use Yoti\YotiClient; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Routing\Controller as BaseController; | ||
use Yoti\Profile\Attribute; | ||
use Yoti\Profile\UserProfile; | ||
use Yoti\Util\Logger; | ||
class ReceiptController extends BaseController | ||
{ | ||
public function show(Request $request, DigitalIdentityClient $client, ?LoggerInterface $logger = null) | ||
{ | ||
$logger = $logger ?? new Logger(); | ||
|
||
$logger->warning("Unknown Content Type parsing as a String"); | ||
$shareReceipt = $client->fetchShareReceipt($request->query('ReceiptID')); | ||
|
||
$profile = $shareReceipt->getProfile(); | ||
|
||
return view('receipt', [ | ||
'fullName' => $profile->getFullName(), | ||
'selfie' => $profile->getSelfie(), | ||
'profileAttributes' => $this->createAttributesDisplayList($profile), | ||
]); | ||
} | ||
|
||
/** | ||
* Create attributes display list. | ||
* | ||
* @param UserProfile $profile | ||
* | ||
* @return array | ||
*/ | ||
private function createAttributesDisplayList(UserProfile $profile): array | ||
{ | ||
$profileAttributes = []; | ||
foreach ($profile->getAttributesList() as $attribute) { | ||
switch ($attribute->getName()) { | ||
case UserProfile::ATTR_SELFIE: | ||
case UserProfile::ATTR_FULL_NAME: | ||
// Selfie and full name are handled separately. | ||
break; | ||
case UserProfile::ATTR_GIVEN_NAMES: | ||
$profileAttributes[] = $this->createAttributeDisplayItem($attribute, 'Given names', 'yoti-icon-profile'); | ||
break; | ||
case UserProfile::ATTR_FAMILY_NAME: | ||
$profileAttributes[] = $this->createAttributeDisplayItem($attribute, 'Family names', 'yoti-icon-profile'); | ||
break; | ||
case UserProfile::ATTR_DATE_OF_BIRTH: | ||
$profileAttributes[] = $this->createAttributeDisplayItem($attribute, 'Date of Birth', 'yoti-icon-calendar'); | ||
break; | ||
case UserProfile::ATTR_GENDER: | ||
$profileAttributes[] = $this->createAttributeDisplayItem($attribute, 'Gender', 'yoti-icon-gender'); | ||
break; | ||
case UserProfile::ATTR_STRUCTURED_POSTAL_ADDRESS: | ||
$profileAttributes[] = $this->createAttributeDisplayItem($attribute, 'Structured Postal Address', 'yoti-icon-address'); | ||
break; | ||
case UserProfile::ATTR_POSTAL_ADDRESS: | ||
$profileAttributes[] = $this->createAttributeDisplayItem($attribute, 'Address', 'yoti-icon-address'); | ||
break; | ||
case UserProfile::ATTR_PHONE_NUMBER: | ||
$profileAttributes[] = $this->createAttributeDisplayItem($attribute, 'Mobile number', 'yoti-icon-phone'); | ||
break; | ||
case UserProfile::ATTR_NATIONALITY: | ||
$profileAttributes[] = $this->createAttributeDisplayItem($attribute, 'Nationality', 'yoti-icon-nationality'); | ||
break; | ||
case UserProfile::ATTR_EMAIL_ADDRESS: | ||
$profileAttributes[] = $this->createAttributeDisplayItem($attribute, 'Email address', 'yoti-icon-email'); | ||
break; | ||
case UserProfile::ATTR_DOCUMENT_DETAILS: | ||
$profileAttributes[] = $this->createAttributeDisplayItem($attribute, 'Document Details', 'yoti-icon-profile'); | ||
break; | ||
case UserProfile::ATTR_DOCUMENT_IMAGES: | ||
$profileAttributes[] = $this->createAttributeDisplayItem($attribute, 'Document Images', 'yoti-icon-profile'); | ||
break; | ||
default: | ||
// Skip age verifications (name containing ":"). | ||
if (strpos($attribute->getName(), ':') === false) { | ||
$profileAttributes[] = $this->createAttributeDisplayItem( | ||
$attribute, | ||
ucwords(str_replace('_', ' ', $attribute->getName())), | ||
'yoti-icon-profile' | ||
); | ||
} | ||
} | ||
} | ||
|
||
// Add age verifications. | ||
$ageVerifications = $profile->getAgeVerifications(); | ||
if ($ageVerifications) { | ||
foreach ($ageVerifications as $ageVerification) { | ||
$profileAttributes[] = [ | ||
'name' => 'Age Verification', | ||
'obj' => $ageVerification->getAttribute(), | ||
'age_verification' => $ageVerification, | ||
'icon' => 'yoti-icon-profile', | ||
]; | ||
} | ||
} | ||
|
||
return $profileAttributes; | ||
} | ||
|
||
/** | ||
* Create attribute display item. | ||
* | ||
* @param Attribute $attribute | ||
* @param string $displayName | ||
* @param string $iconClass | ||
* | ||
* @return array | ||
*/ | ||
private function createAttributeDisplayItem(Attribute $attribute, string $displayName, string $iconClass): array | ||
{ | ||
return [ | ||
'name' => $displayName, | ||
'obj' => $attribute, | ||
'icon' => $iconClass, | ||
]; | ||
} | ||
} |
Oops, something went wrong.