diff --git a/examples/digitalidentity/app/Http/Controllers/AdvancedIdentityController.php b/examples/digitalidentity/app/Http/Controllers/AdvancedIdentityController.php index 18490105..cdfda0f6 100644 --- a/examples/digitalidentity/app/Http/Controllers/AdvancedIdentityController.php +++ b/examples/digitalidentity/app/Http/Controllers/AdvancedIdentityController.php @@ -16,29 +16,30 @@ 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" - } + $advancedIdentityProfileJson = + (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" + ] ] - } + ] + ] ] - }'; + ; $policy = (new PolicyBuilder()) - ->withAdvancedIdentityProfileRequirements($advancedIdentityProfileJson) + ->withAdvancedIdentityProfileRequirements((object)$advancedIdentityProfileJson) ->build(); $redirectUri = 'https://host/redirect/'; diff --git a/examples/digitalidentity/resources/views/advancedidentity.blade.php b/examples/digitalidentity/resources/views/advancedidentity.blade.php index 1bdea270..289e9e1e 100644 --- a/examples/digitalidentity/resources/views/advancedidentity.blade.php +++ b/examples/digitalidentity/resources/views/advancedidentity.blade.php @@ -18,7 +18,7 @@ alt="Yoti"/> -

Digital Identity(Advanced)4 Share Example

+

Digital Identity(Advanced) Share Example

diff --git a/src/Identity/Policy/Policy.php b/src/Identity/Policy/Policy.php index 62ade060..a71e1fdc 100644 --- a/src/Identity/Policy/Policy.php +++ b/src/Identity/Policy/Policy.php @@ -26,19 +26,26 @@ class Policy implements \JsonSerializable */ private $identityProfileRequirements; + /** + * @var object|null + */ + private $advancedIdentityProfileRequirements; + /** * @param WantedAttribute[] $wantedAttributes * Array of attributes to be requested. * @param int[] $wantedAuthTypes * Auth types represents the authentication type to be used. * @param object $identityProfileRequirements + * @param object $advancedidentityProfileRequirements */ public function __construct( array $wantedAttributes, array $wantedAuthTypes, bool $wantedRememberMe = false, bool $wantedRememberMeOptional = false, - $identityProfileRequirements = null + $identityProfileRequirements = null, + $advancedIdentityProfileRequirements = null ) { Validation::isArrayOfType($wantedAttributes, [WantedAttribute::class], 'wantedAttributes'); $this->wantedAttributes = $wantedAttributes; @@ -49,6 +56,7 @@ public function __construct( $this->wantedRememberMe = $wantedRememberMe; $this->wantedRememberMeOptional = $wantedRememberMeOptional; $this->identityProfileRequirements = $identityProfileRequirements; + $this->advancedIdentityProfileRequirements = $advancedIdentityProfileRequirements; } @@ -60,6 +68,7 @@ public function jsonSerialize(): stdClass 'wanted_remember_me' => $this->wantedRememberMe, 'wanted_remember_me_optional' => $this->wantedRememberMeOptional, 'identity_profile_requirements' => $this->identityProfileRequirements, + 'advanced_identity_profile_requirements' => $this->advancedIdentityProfileRequirements, ]; } @@ -72,4 +81,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/Identity/Policy/PolicyBuilder.php b/src/Identity/Policy/PolicyBuilder.php index 46e8e8fd..a3b8f479 100644 --- a/src/Identity/Policy/PolicyBuilder.php +++ b/src/Identity/Policy/PolicyBuilder.php @@ -331,8 +331,6 @@ public function withAdvancedIdentityProfileRequirements($advancedIdentityProfile return $this; } - - public function build(): Policy { return new Policy( @@ -340,7 +338,8 @@ public function build(): Policy array_values($this->wantedAuthTypes), $this->wantedRememberMe, $this->wantedRememberMeOptional, - $this->identityProfileRequirements + $this->identityProfileRequirements, + $this->advancedIdentityProfileRequirements ); } } diff --git a/tests/Identity/Policy/PolicyBuilderTest.php b/tests/Identity/Policy/PolicyBuilderTest.php index d223bd79..58b7968e 100644 --- a/tests/Identity/Policy/PolicyBuilderTest.php +++ b/tests/Identity/Policy/PolicyBuilderTest.php @@ -75,6 +75,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($policy)); @@ -124,6 +125,7 @@ public function testWithWantedAttributeByNameWithConstraints() 'wanted_remember_me' => false, 'wanted_remember_me_optional' => false, 'identity_profile_requirements' => null, + 'advanced_identity_profile_requirements' => null ]; $this->assertJsonStringEqualsJsonString( @@ -151,6 +153,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($policy)); @@ -205,6 +208,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($policy)); @@ -238,6 +242,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($policy)); @@ -269,6 +274,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($policy)); @@ -314,6 +320,7 @@ public function testWithAgeDerivedAttributesWithConstraints() 'wanted_remember_me' => false, 'wanted_remember_me_optional' => false, 'identity_profile_requirements' => null, + 'advanced_identity_profile_requirements' => null ]; $this->assertJsonStringEqualsJsonString( @@ -343,6 +350,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($policy)); @@ -367,6 +375,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($policy)); @@ -390,7 +399,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($policy)); @@ -415,6 +425,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($policy)); @@ -439,6 +450,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($policy)); @@ -461,6 +473,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($policy)); @@ -482,6 +495,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($policy)); @@ -503,6 +517,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($policy)); @@ -524,6 +539,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($policy)); @@ -545,6 +561,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($policy)); @@ -564,7 +581,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($policy)); @@ -585,6 +603,7 @@ public function testWithRememberMeOptional() 'wanted_remember_me' => false, 'wanted_remember_me_optional' => true, 'identity_profile_requirements' => null, + 'advanced_identity_profile_requirements' => null ]; $this->assertEquals(json_encode($expectedWantedAttributeData), json_encode($policy)); @@ -604,7 +623,8 @@ public function testWithoutRememberMeOptional() '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($policy)); @@ -631,7 +651,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 ]; $policy = (new PolicyBuilder()) @@ -641,4 +662,51 @@ public function testWithIdentityProfileRequirements() $this->assertEquals(json_encode($expectedWantedAttributeData), json_encode($policy)); $this->assertEquals($identityProfileSample, $policy->getIdentityProfileRequirements()); } + + /** + * @covers ::withAdvancedIdentityProfileRequirements + * @covers \Yoti\Identity\Policy\Policy::__construct + * @covers \Yoti\Identity\Policy\Policy::getAdvancedIdentityProfileRequirements + * @covers \Yoti\Identity\Policy\Policy::jsonSerialize + */ + 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 + ]; + + $policy = (new PolicyBuilder()) + ->withAdvancedIdentityProfileRequirements($advancedIdentityProfileSample) + ->build(); + + $this->assertEquals(json_encode($expectedWantedAttributeData), json_encode($policy)); + $this->assertEquals($advancedIdentityProfileSample, $policy->getAdvancedIdentityProfileRequirements()); + } }