|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace MadWizard\WebAuthn\Dom; |
|
4
|
|
|
|
|
5
|
|
|
use MadWizard\WebAuthn\Exception\WebAuthnException; |
|
6
|
|
|
use MadWizard\WebAuthn\Format\ByteBuffer; |
|
7
|
|
|
|
|
8
|
|
|
final class PublicKeyCredentialRequestOptions extends AbstractDictionary |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* @var ByteBuffer |
|
12
|
|
|
*/ |
|
13
|
|
|
private $challenge; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @var int|null |
|
17
|
|
|
*/ |
|
18
|
|
|
private $timeout; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @var string|null |
|
22
|
|
|
*/ |
|
23
|
|
|
private $rpId; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var PublicKeyCredentialDescriptor[]|null |
|
27
|
|
|
*/ |
|
28
|
|
|
private $allowCredentials; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var string|null |
|
32
|
|
|
* |
|
33
|
|
|
* @see UserVerificationRequirement |
|
34
|
|
|
*/ |
|
35
|
|
|
private $userVerification; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @var AuthenticationExtensionsClientInputs|null |
|
39
|
|
|
*/ |
|
40
|
|
|
private $extensions; |
|
41
|
|
|
|
|
42
|
1 |
|
public function __construct(ByteBuffer $challenge) |
|
43
|
|
|
{ |
|
44
|
1 |
|
$this->challenge = $challenge; |
|
45
|
1 |
|
} |
|
46
|
|
|
|
|
47
|
1 |
|
public function addAllowedCredential(PublicKeyCredentialDescriptor $credentialDescriptor): void |
|
48
|
|
|
{ |
|
49
|
1 |
|
if ($this->allowCredentials === null) { |
|
50
|
1 |
|
$this->allowCredentials = []; |
|
51
|
|
|
} |
|
52
|
1 |
|
$this->allowCredentials[] = $credentialDescriptor; |
|
53
|
1 |
|
} |
|
54
|
|
|
|
|
55
|
1 |
|
public function getAsArray(): array |
|
56
|
|
|
{ |
|
57
|
|
|
$map = [ |
|
58
|
1 |
|
'challenge' => $this->challenge, |
|
59
|
|
|
]; |
|
60
|
|
|
|
|
61
|
1 |
|
$map = array_merge( |
|
62
|
1 |
|
$map, |
|
63
|
1 |
|
self::removeNullValues([ |
|
64
|
1 |
|
'timeout' => $this->timeout, |
|
65
|
1 |
|
'rpId' => $this->rpId, |
|
66
|
1 |
|
'allowCredentials' => $this->allowCredentials, |
|
67
|
1 |
|
'userVerification' => $this->userVerification, |
|
68
|
1 |
|
'extensions' => $this->extensions, |
|
69
|
|
|
]) |
|
70
|
|
|
); |
|
71
|
|
|
|
|
72
|
1 |
|
return $map; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
1 |
|
public function getRpId(): ?string |
|
76
|
|
|
{ |
|
77
|
1 |
|
return $this->rpId; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
1 |
|
public function setRpId(?string $rpId): void |
|
81
|
|
|
{ |
|
82
|
1 |
|
$this->rpId = $rpId; |
|
83
|
1 |
|
} |
|
84
|
|
|
|
|
85
|
|
|
public function getTimeout(): ?int |
|
86
|
|
|
{ |
|
87
|
|
|
return $this->timeout; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
1 |
|
public function setTimeout(?int $timeout): void |
|
91
|
|
|
{ |
|
92
|
1 |
|
$this->timeout = $timeout; |
|
93
|
1 |
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* @return PublicKeyCredentialDescriptor[]|null |
|
97
|
|
|
*/ |
|
98
|
1 |
|
public function getAllowCredentials(): ?array |
|
99
|
|
|
{ |
|
100
|
1 |
|
return $this->allowCredentials; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
1 |
|
public function getChallenge(): ByteBuffer |
|
104
|
|
|
{ |
|
105
|
1 |
|
return $this->challenge; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
public function getUserVerification(): ?string |
|
109
|
|
|
{ |
|
110
|
|
|
return $this->userVerification; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
1 |
|
public function setUserVerification(?string $value): void |
|
114
|
|
|
{ |
|
115
|
1 |
|
if ($value !== null && !UserVerificationRequirement::isValidValue($value)) { |
|
116
|
|
|
throw new WebAuthnException(sprintf('Value %s is not a valid UserVerificationRequirement', $value)); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
1 |
|
$this->userVerification = $value; |
|
120
|
1 |
|
} |
|
121
|
|
|
|
|
122
|
|
|
public function getExtensions(): ?AuthenticationExtensionsClientInputs |
|
123
|
|
|
{ |
|
124
|
|
|
return $this->extensions; |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
public function setExtensions(?AuthenticationExtensionsClientInputs $extensions): void |
|
128
|
|
|
{ |
|
129
|
|
|
$this->extensions = $extensions; |
|
130
|
|
|
} |
|
131
|
|
|
} |
|
132
|
|
|
|