Skip to content

Commit 8459a64

Browse files
LuborRodRodion Liuborets
andauthored
SDK-2075-2085 Add subject and identity profile requirements (#275)
Co-authored-by: Rodion Liuborets <[email protected]>
1 parent 0d99730 commit 8459a64

File tree

6 files changed

+141
-6
lines changed

6 files changed

+141
-6
lines changed

src/ShareUrl/DynamicScenario.php

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ class DynamicScenario implements \JsonSerializable
3131
*/
3232
private $extensions;
3333

34+
/**
35+
* @var object|null
36+
*/
37+
private $subject;
38+
3439
/**
3540
* @param string $callbackEndpoint
3641
* The device's callback endpoint. Must be a URL relative to the Application
@@ -39,14 +44,21 @@ class DynamicScenario implements \JsonSerializable
3944
* The customisable DynamicPolicy to use in the share.
4045
* @param \Yoti\ShareUrl\Extension\Extension[] $extensions
4146
* List of Extension to be activated for the application.
47+
* @param object $subject
48+
* Set of data required to represent an identity profile
4249
*/
43-
public function __construct(string $callbackEndpoint, DynamicPolicy $dynamicPolicy, array $extensions)
44-
{
50+
public function __construct(
51+
string $callbackEndpoint,
52+
DynamicPolicy $dynamicPolicy,
53+
array $extensions,
54+
$subject = null
55+
) {
4556
$this->callbackEndpoint = $callbackEndpoint;
4657
$this->dynamicPolicy = $dynamicPolicy;
4758

4859
Validation::isArrayOfType($extensions, [Extension::class], 'extensions');
4960
$this->extensions = $extensions;
61+
$this->subject = $subject;
5062
}
5163

5264
/**
@@ -60,6 +72,7 @@ public function jsonSerialize(): stdClass
6072
'callback_endpoint' => $this->callbackEndpoint,
6173
'policy' => $this->dynamicPolicy,
6274
'extensions' => $this->extensions,
75+
'subject' => $this->subject,
6376
];
6477
}
6578

@@ -70,4 +83,12 @@ public function __toString(): string
7083
{
7184
return Json::encode($this);
7285
}
86+
87+
/**
88+
* @return object|null
89+
*/
90+
public function getSubject()
91+
{
92+
return $this->subject;
93+
}
7394
}

src/ShareUrl/DynamicScenarioBuilder.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ class DynamicScenarioBuilder
2727
*/
2828
private $extensions = [];
2929

30+
/**
31+
* @var object|null
32+
*/
33+
private $subject = null;
34+
3035
/**
3136
* @param string $callbackEndpoint
3237
*
@@ -60,11 +65,22 @@ public function withExtension(Extension $extension): self
6065
return $this;
6166
}
6267

68+
/**
69+
* @param object $subject
70+
*
71+
* @return $this
72+
*/
73+
public function withSubject($subject): self
74+
{
75+
$this->subject = $subject;
76+
return $this;
77+
}
78+
6379
/**
6480
* @return \Yoti\ShareUrl\DynamicScenario
6581
*/
6682
public function build(): DynamicScenario
6783
{
68-
return new DynamicScenario($this->callbackEndpoint, $this->dynamicPolicy, $this->extensions);
84+
return new DynamicScenario($this->callbackEndpoint, $this->dynamicPolicy, $this->extensions, $this->subject);
6985
}
7086
}

src/ShareUrl/Policy/DynamicPolicy.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,24 @@ class DynamicPolicy implements \JsonSerializable
2828
*/
2929
private $wantedRememberMe;
3030

31+
/**
32+
* @var object|null
33+
*/
34+
private $identityProfileRequirements;
35+
3136
/**
3237
* @param \Yoti\ShareUrl\Policy\WantedAttribute[] $wantedAttributes
3338
* Array of attributes to be requested.
3439
* @param int[] $wantedAuthTypes
3540
* Auth types represents the authentication type to be used.
3641
* @param bool $wantedRememberMe
42+
* @param object $identityProfileRequirements
3743
*/
3844
public function __construct(
3945
array $wantedAttributes,
4046
array $wantedAuthTypes,
41-
bool $wantedRememberMe = false
47+
bool $wantedRememberMe = false,
48+
$identityProfileRequirements = null
4249
) {
4350
Validation::isArrayOfType($wantedAttributes, [WantedAttribute::class], 'wantedAttributes');
4451
$this->wantedAttributes = $wantedAttributes;
@@ -47,6 +54,7 @@ public function __construct(
4754
$this->wantedAuthTypes = $wantedAuthTypes;
4855

4956
$this->wantedRememberMe = $wantedRememberMe;
57+
$this->identityProfileRequirements = $identityProfileRequirements;
5058
}
5159

5260
/**
@@ -61,6 +69,7 @@ public function jsonSerialize(): stdClass
6169
'wanted_auth_types' => $this->wantedAuthTypes,
6270
'wanted_remember_me' => $this->wantedRememberMe,
6371
'wanted_remember_me_optional' => false,
72+
'identity_profile_requirements' => $this->identityProfileRequirements,
6473
];
6574
}
6675

@@ -71,4 +80,14 @@ public function __toString(): string
7180
{
7281
return Json::encode($this);
7382
}
83+
84+
/**
85+
* IdentityProfileRequirements requested in the policy
86+
*
87+
* @return object|null
88+
*/
89+
public function getIdentityProfileRequirements()
90+
{
91+
return $this->identityProfileRequirements;
92+
}
7493
}

src/ShareUrl/Policy/DynamicPolicyBuilder.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ class DynamicPolicyBuilder
3636
*/
3737
private $wantedRememberMe = false;
3838

39+
/**
40+
* @var object|null
41+
*/
42+
private $identityProfileRequirements = null;
43+
3944
/**
4045
* @param \Yoti\ShareUrl\Policy\WantedAttribute $wantedAttribute
4146
*
@@ -378,14 +383,27 @@ public function withWantedRememberMe(bool $wantedRememberMe): self
378383
}
379384

380385
/**
381-
* @return \Yoti\ShareUrl\Policy\DynamicPolicy
386+
* Use an Identity Profile Requirement object for the share
387+
*
388+
* @param object $identityProfileRequirements
389+
* @return $this
390+
*/
391+
public function withIdentityProfileRequirements($identityProfileRequirements): self
392+
{
393+
$this->identityProfileRequirements = $identityProfileRequirements;
394+
return $this;
395+
}
396+
397+
/**
398+
* @return DynamicPolicy
382399
*/
383400
public function build(): DynamicPolicy
384401
{
385402
return new DynamicPolicy(
386403
array_values($this->wantedAttributes),
387404
array_values($this->wantedAuthTypes),
388-
$this->wantedRememberMe
405+
$this->wantedRememberMe,
406+
$this->identityProfileRequirements
389407
);
390408
}
391409
}

tests/ShareUrl/DynamicScenarioBuilderTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,18 @@ class DynamicScenarioBuilderTest extends TestCase
2323
* @covers ::withCallbackEndpoint
2424
* @covers ::withPolicy
2525
* @covers ::withExtension
26+
* @covers ::withSubject
2627
* @covers \Yoti\ShareUrl\DynamicScenario::__construct
2728
* @covers \Yoti\ShareUrl\DynamicScenario::__toString
2829
* @covers \Yoti\ShareUrl\DynamicScenario::jsonSerialize
30+
* @covers \Yoti\ShareUrl\DynamicScenario::getSubject
2931
*/
3032
public function testBuild()
3133
{
34+
$subjectSample = (object)[
35+
'subject_id' => 'SOME_STRING'
36+
];
37+
3238
$somePolicy = (new DynamicPolicyBuilder())
3339
->withFullName()
3440
->withGivenNames()
@@ -49,6 +55,7 @@ public function testBuild()
4955
->withPolicy($somePolicy)
5056
->withExtension($someExtension1)
5157
->withExtension($someExtension2)
58+
->withSubject($subjectSample)
5259
->build();
5360

5461
$expectedJsonData = [
@@ -67,6 +74,7 @@ public function testBuild()
6774
'wanted_auth_types' => [],
6875
'wanted_remember_me' => false,
6976
'wanted_remember_me_optional' => false,
77+
'identity_profile_requirements' => null
7078
],
7179
'extensions' => [
7280
[
@@ -82,10 +90,12 @@ public function testBuild()
8290
],
8391
],
8492
],
93+
'subject' => $subjectSample
8594
];
8695

8796
$this->assertEquals(json_encode($expectedJsonData), json_encode($dynamicScenario));
8897
$this->assertEquals(json_encode($expectedJsonData), $dynamicScenario);
98+
$this->assertEquals($subjectSample, $dynamicScenario->getSubject());
8999
}
90100

91101
/**

0 commit comments

Comments
 (0)