From f454c03c6fc8d60c74c88f86640cea49b00df199 Mon Sep 17 00:00:00 2001
From: mehmet-yoti <111424390+mehmet-yoti@users.noreply.github.com>
Date: Thu, 4 Jul 2024 18:50:28 +0300
Subject: [PATCH] =?UTF-8?q?SDK-2371=20added=20advanced=20identity=20profil?=
=?UTF-8?q?e=20to=20sharev1,example=20and=20updat=E2=80=A6=20(#359)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* SDK-2371 added advanced identity profile to sharev1,example and updated tests
* SDK-2371 updated test coverage info
* SDK-2371 updated example page title
---
.../AdvancedIdentityController.php | 68 +++++++++++++++++
.../resources/views/advanced.blade.php | 65 +++++++++++++++++
examples/profile/routes/web.php | 1 +
src/ShareUrl/Policy/DynamicPolicy.php | 21 +++++-
src/ShareUrl/Policy/DynamicPolicyBuilder.php | 20 ++++-
tests/ShareUrl/DynamicScenarioBuilderTest.php | 3 +-
.../Policy/DynamicPolicyBuilderTest.php | 73 ++++++++++++++++++-
7 files changed, 245 insertions(+), 6 deletions(-)
create mode 100644 examples/profile/app/Http/Controllers/AdvancedIdentityController.php
create mode 100644 examples/profile/resources/views/advanced.blade.php
diff --git a/examples/profile/app/Http/Controllers/AdvancedIdentityController.php b/examples/profile/app/Http/Controllers/AdvancedIdentityController.php
new file mode 100644
index 00000000..25596559
--- /dev/null
+++ b/examples/profile/app/Http/Controllers/AdvancedIdentityController.php
@@ -0,0 +1,68 @@
+ [(object)[
+
+ "trust_framework" => "YOTI_GLOBAL",
+ "schemes" => [(object)[
+
+ "label" => "identity-AL-L1",
+ "type" => "IDENTITY",
+ "objective" => "AL_L1"
+ ],
+ [
+ "label" => "identity-AL-M1",
+ "type" => "IDENTITY",
+ "objective" => "AL_M1"
+ ]
+ ]
+ ]
+ ]
+ ]
+ ;
+
+ $policy = (new DynamicPolicyBuilder())
+ ->withAdvancedIdentityProfileRequirements($advancedIdentityProfileJson)
+ ->build();
+
+ $dynamicScenario = (new DynamicScenarioBuilder())
+ ->withCallbackEndpoint("/profile")
+ ->withPolicy($policy)
+ ->withSubject((object)[
+ 'subject_id' => "some_subject_id_string"
+ ])
+ ->build();
+
+ return view('advanced', [
+ 'title' => 'Advanced Identity Share Example',
+ 'buttonConfig' => [
+ 'elements' => [
+ [
+ 'domId' => 'yoti-share-button',
+ 'clientSdkId' => config('yoti')['client.sdk.id'],
+ 'shareUrl' => $client->createShareUrl($dynamicScenario)->getShareUrl(),
+ 'button' => [
+ 'label' => 'Use Yoti',
+ 'align' => 'center',
+ 'width' => 'auto',
+ 'verticalAlign' => 'top'
+ ],
+ 'type' => 'modal'
+ ]
+ ]
+ ]
+ ]);
+ }
+}
diff --git a/examples/profile/resources/views/advanced.blade.php b/examples/profile/resources/views/advanced.blade.php
new file mode 100644
index 00000000..f158d88b
--- /dev/null
+++ b/examples/profile/resources/views/advanced.blade.php
@@ -0,0 +1,65 @@
+
+
+
+
+
+
+ {{ $title }}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/examples/profile/routes/web.php b/examples/profile/routes/web.php
index 9565f235..4a577e36 100644
--- a/examples/profile/routes/web.php
+++ b/examples/profile/routes/web.php
@@ -20,3 +20,4 @@
Route::get('/dynamic-share', 'DynamicShareController@show');
Route::get('/dbs-check', 'DbsCheckController@show');
+Route::get('/advanced-identity', 'AdvancedIdentityController@show');
diff --git a/src/ShareUrl/Policy/DynamicPolicy.php b/src/ShareUrl/Policy/DynamicPolicy.php
index 9313e4d8..7e6e81b8 100644
--- a/src/ShareUrl/Policy/DynamicPolicy.php
+++ b/src/ShareUrl/Policy/DynamicPolicy.php
@@ -33,6 +33,11 @@ class DynamicPolicy implements \JsonSerializable
*/
private $identityProfileRequirements;
+ /**
+ * @var object|null
+ */
+ private $advancedIdentityProfileRequirements;
+
/**
* @param \Yoti\ShareUrl\Policy\WantedAttribute[] $wantedAttributes
* Array of attributes to be requested.
@@ -40,12 +45,14 @@ class DynamicPolicy implements \JsonSerializable
* Auth types represents the authentication type to be used.
* @param bool $wantedRememberMe
* @param object $identityProfileRequirements
+ * @param object $advancedIdentityProfileRequirements
*/
public function __construct(
array $wantedAttributes,
array $wantedAuthTypes,
bool $wantedRememberMe = false,
- $identityProfileRequirements = null
+ $identityProfileRequirements = null,
+ $advancedIdentityProfileRequirements = null
) {
Validation::isArrayOfType($wantedAttributes, [WantedAttribute::class], 'wantedAttributes');
$this->wantedAttributes = $wantedAttributes;
@@ -55,6 +62,7 @@ public function __construct(
$this->wantedRememberMe = $wantedRememberMe;
$this->identityProfileRequirements = $identityProfileRequirements;
+ $this->advancedIdentityProfileRequirements = $advancedIdentityProfileRequirements;
}
/**
@@ -70,6 +78,7 @@ public function jsonSerialize(): stdClass
'wanted_remember_me' => $this->wantedRememberMe,
'wanted_remember_me_optional' => false,
'identity_profile_requirements' => $this->identityProfileRequirements,
+ 'advanced_identity_profile_requirements' => $this->advancedIdentityProfileRequirements,
];
}
@@ -90,4 +99,14 @@ public function getIdentityProfileRequirements()
{
return $this->identityProfileRequirements;
}
+
+ /**
+ * AdvancedIdentityProfileRequirements requested in the policy
+ *
+ * @return object|null
+ */
+ public function getAdvancedIdentityProfileRequirements()
+ {
+ return $this->advancedIdentityProfileRequirements;
+ }
}
diff --git a/src/ShareUrl/Policy/DynamicPolicyBuilder.php b/src/ShareUrl/Policy/DynamicPolicyBuilder.php
index 1dc7420d..4d3ba083 100644
--- a/src/ShareUrl/Policy/DynamicPolicyBuilder.php
+++ b/src/ShareUrl/Policy/DynamicPolicyBuilder.php
@@ -42,6 +42,11 @@ class DynamicPolicyBuilder
*/
private $identityProfileRequirements = null;
+ /**
+ * @var object|null
+ */
+ private $advancedIdentityProfileRequirements = null;
+
/**
* @param \Yoti\ShareUrl\Policy\WantedAttribute $wantedAttribute
*
@@ -400,6 +405,18 @@ public function withIdentityProfileRequirements($identityProfileRequirements): s
return $this;
}
+ /**
+ * Use an Identity Profile Requirement object for the share
+ *
+ * @param object $advancedIdentityProfileRequirements
+ * @return $this
+ */
+ public function withAdvancedIdentityProfileRequirements($advancedIdentityProfileRequirements): self
+ {
+ $this->advancedIdentityProfileRequirements = $advancedIdentityProfileRequirements;
+ return $this;
+ }
+
/**
* @return DynamicPolicy
*/
@@ -409,7 +426,8 @@ public function build(): DynamicPolicy
array_values($this->wantedAttributes),
array_values($this->wantedAuthTypes),
$this->wantedRememberMe,
- $this->identityProfileRequirements
+ $this->identityProfileRequirements,
+ $this->advancedIdentityProfileRequirements
);
}
}
diff --git a/tests/ShareUrl/DynamicScenarioBuilderTest.php b/tests/ShareUrl/DynamicScenarioBuilderTest.php
index 6b06267e..1a83f4f5 100644
--- a/tests/ShareUrl/DynamicScenarioBuilderTest.php
+++ b/tests/ShareUrl/DynamicScenarioBuilderTest.php
@@ -74,7 +74,8 @@ public function testBuild()
'wanted_auth_types' => [],
'wanted_remember_me' => false,
'wanted_remember_me_optional' => false,
- 'identity_profile_requirements' => null
+ 'identity_profile_requirements' => null,
+ 'advanced_identity_profile_requirements' => null
],
'extensions' => [
[
diff --git a/tests/ShareUrl/Policy/DynamicPolicyBuilderTest.php b/tests/ShareUrl/Policy/DynamicPolicyBuilderTest.php
index 07eb7aa8..0980b58e 100644
--- a/tests/ShareUrl/Policy/DynamicPolicyBuilderTest.php
+++ b/tests/ShareUrl/Policy/DynamicPolicyBuilderTest.php
@@ -76,6 +76,7 @@ public function testBuildWithAttributes()
'wanted_remember_me' => false,
'wanted_remember_me_optional' => false,
'identity_profile_requirements' => null,
+ 'advanced_identity_profile_requirements' => null
];
$this->assertEquals(json_encode($expectedWantedAttributeData), json_encode($dynamicPolicy));
@@ -127,6 +128,7 @@ public function testWithWantedAttributeByNameWithConstraints()
'wanted_remember_me' => false,
'wanted_remember_me_optional' => false,
'identity_profile_requirements' => null,
+ 'advanced_identity_profile_requirements' => null
];
$this->assertJsonStringEqualsJsonString(
@@ -154,6 +156,7 @@ public function testWithDuplicateAttribute()
'wanted_remember_me' => false,
'wanted_remember_me_optional' => false,
'identity_profile_requirements' => null,
+ 'advanced_identity_profile_requirements' => null
];
$this->assertEquals(json_encode($expectedWantedAttributeData), json_encode($dynamicPolicy));
@@ -215,6 +218,7 @@ public function testWithWantedAttributeByName()
'wanted_remember_me' => false,
'wanted_remember_me_optional' => false,
'identity_profile_requirements' => null,
+ 'advanced_identity_profile_requirements' => null
];
$this->assertEquals(json_encode($expectedWantedAttributeData), json_encode($dynamicPolicy));
@@ -248,6 +252,7 @@ public function testWithAttributeObjects()
'wanted_remember_me' => false,
'wanted_remember_me_optional' => false,
'identity_profile_requirements' => null,
+ 'advanced_identity_profile_requirements' => null
];
$this->assertEquals(json_encode($expectedWantedAttributeData), json_encode($dynamicPolicy));
@@ -279,6 +284,7 @@ public function testWithAgeDerivedAttributes()
'wanted_remember_me' => false,
'wanted_remember_me_optional' => false,
'identity_profile_requirements' => null,
+ 'advanced_identity_profile_requirements' => null
];
$this->assertEquals(json_encode($expectedWantedAttributeData), json_encode($dynamicPolicy));
@@ -327,6 +333,7 @@ public function testWithAgeDerivedAttributesWithConstraints()
'wanted_remember_me' => false,
'wanted_remember_me_optional' => false,
'identity_profile_requirements' => null,
+ 'advanced_identity_profile_requirements' => null
];
$this->assertJsonStringEqualsJsonString(
@@ -387,6 +394,7 @@ public function testWithDuplicateAgeDerivedAttributes()
'wanted_remember_me' => false,
'wanted_remember_me_optional' => false,
'identity_profile_requirements' => null,
+ 'advanced_identity_profile_requirements' => null
];
$this->assertEquals(json_encode($expectedWantedAttributeData), json_encode($dynamicPolicy));
@@ -411,6 +419,7 @@ public function testWithAuthTypes()
'wanted_remember_me' => false,
'wanted_remember_me_optional' => false,
'identity_profile_requirements' => null,
+ 'advanced_identity_profile_requirements' => null
];
$this->assertEquals(json_encode($expectedWantedAttributeData), json_encode($dynamicPolicy));
@@ -434,7 +443,8 @@ public function testWithAuthTypesTrue()
'wanted_auth_types' => [self::SELFIE_AUTH_TYPE, self::PIN_AUTH_TYPE, 99],
'wanted_remember_me' => false,
'wanted_remember_me_optional' => false,
- 'identity_profile_requirements' => null
+ 'identity_profile_requirements' => null,
+ 'advanced_identity_profile_requirements' => null
];
$this->assertEquals(json_encode($expectedWantedAttributeData), json_encode($dynamicPolicy));
@@ -459,6 +469,7 @@ public function testWithAuthTypesFalse()
'wanted_remember_me' => false,
'wanted_remember_me_optional' => false,
'identity_profile_requirements' => null,
+ 'advanced_identity_profile_requirements' => null
];
$this->assertEquals(json_encode($expectedWantedAttributeData), json_encode($dynamicPolicy));
@@ -483,6 +494,7 @@ public function testWithAuthEnabledThenDisabled()
'wanted_remember_me' => false,
'wanted_remember_me_optional' => false,
'identity_profile_requirements' => null,
+ 'advanced_identity_profile_requirements' => null
];
$this->assertEquals(json_encode($expectedWantedAttributeData), json_encode($dynamicPolicy));
@@ -505,6 +517,7 @@ public function testWithSameAuthTypeAddedOnlyOnce()
'wanted_remember_me' => false,
'wanted_remember_me_optional' => false,
'identity_profile_requirements' => null,
+ 'advanced_identity_profile_requirements' => null
];
$this->assertEquals(json_encode($expectedWantedAttributeData), json_encode($dynamicPolicy));
@@ -526,6 +539,7 @@ public function testWithOnlyTwoAuthTypes()
'wanted_remember_me' => false,
'wanted_remember_me_optional' => false,
'identity_profile_requirements' => null,
+ 'advanced_identity_profile_requirements' => null
];
$this->assertEquals(json_encode($expectedWantedAttributeData), json_encode($dynamicPolicy));
@@ -547,6 +561,7 @@ public function testWithNoSelfieAuthAfterRemoval()
'wanted_remember_me' => false,
'wanted_remember_me_optional' => false,
'identity_profile_requirements' => null,
+ 'advanced_identity_profile_requirements' => null
];
$this->assertEquals(json_encode($expectedWantedAttributeData), json_encode($dynamicPolicy));
@@ -568,6 +583,7 @@ public function testWithNoPinAuthAfterRemoval()
'wanted_remember_me' => false,
'wanted_remember_me_optional' => false,
'identity_profile_requirements' => null,
+ 'advanced_identity_profile_requirements' => null
];
$this->assertEquals(json_encode($expectedWantedAttributeData), json_encode($dynamicPolicy));
@@ -601,6 +617,7 @@ public function testWithRememberMe()
'wanted_remember_me' => true,
'wanted_remember_me_optional' => false,
'identity_profile_requirements' => null,
+ 'advanced_identity_profile_requirements' => null
];
$this->assertEquals(json_encode($expectedWantedAttributeData), json_encode($dynamicPolicy));
@@ -620,7 +637,8 @@ public function testWithoutRememberMe()
'wanted_auth_types' => [],
'wanted_remember_me' => false,
'wanted_remember_me_optional' => false,
- 'identity_profile_requirements' => null
+ 'identity_profile_requirements' => null,
+ 'advanced_identity_profile_requirements' => null
];
$this->assertEquals(json_encode($expectedWantedAttributeData), json_encode($dynamicPolicy));
@@ -648,7 +666,8 @@ public function testWithIdentityProfileRequirements()
'wanted_auth_types' => [],
'wanted_remember_me' => false,
'wanted_remember_me_optional' => false,
- 'identity_profile_requirements' => $identityProfileSample
+ 'identity_profile_requirements' => $identityProfileSample,
+ 'advanced_identity_profile_requirements' => null
];
$dynamicPolicy = (new DynamicPolicyBuilder())
@@ -658,4 +677,52 @@ public function testWithIdentityProfileRequirements()
$this->assertEquals(json_encode($expectedWantedAttributeData), json_encode($dynamicPolicy));
$this->assertEquals($identityProfileSample, $dynamicPolicy->getIdentityProfileRequirements());
}
+
+ /**
+ * @covers ::withAdvancedIdentityProfileRequirements
+ * @covers \Yoti\ShareUrl\Policy\DynamicPolicy::__construct
+ * @covers \Yoti\ShareUrl\Policy\DynamicPolicy::getAdvancedIdentityProfileRequirements
+ * @covers \Yoti\ShareUrl\Policy\DynamicPolicy::jsonSerialize
+ * @covers \Yoti\ShareUrl\Policy\DynamicPolicy::__toString
+ */
+ public function testWithAdvancedIdentityProfileRequirements()
+ {
+ $advancedIdentityProfileSample =
+ (object)[
+ "profiles" => [(object)[
+
+ "trust_framework" => "YOTI_GLOBAL",
+ "schemes" => [(object)[
+
+ "label" => "identity-AL-L1",
+ "type" => "IDENTITY",
+ "objective" => "AL_L1"
+ ],
+ [
+ "label" => "identity-AL-M1",
+ "type" => "IDENTITY",
+ "objective" => "AL_M1"
+ ]
+ ]
+ ]
+ ]
+ ]
+ ;
+
+ $expectedWantedAttributeData = [
+ 'wanted' => [],
+ 'wanted_auth_types' => [],
+ 'wanted_remember_me' => false,
+ 'wanted_remember_me_optional' => false,
+ 'identity_profile_requirements' => null,
+ 'advanced_identity_profile_requirements' => $advancedIdentityProfileSample
+ ];
+
+ $dynamicPolicy = (new DynamicPolicyBuilder())
+ ->withAdvancedIdentityProfileRequirements($advancedIdentityProfileSample)
+ ->build();
+
+ $this->assertEquals(json_encode($expectedWantedAttributeData), json_encode($dynamicPolicy));
+ $this->assertEquals($advancedIdentityProfileSample, $dynamicPolicy->getAdvancedIdentityProfileRequirements());
+ }
}