/
AuthenticationOptions.php
109 lines (89 loc) · 2.41 KB
/
AuthenticationOptions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
namespace MadWizard\WebAuthn\Server\Authentication;
use MadWizard\WebAuthn\Credential\CredentialId;
use MadWizard\WebAuthn\Credential\UserHandle;
use MadWizard\WebAuthn\Dom\UserVerificationRequirement;
use MadWizard\WebAuthn\Exception\WebAuthnException;
use MadWizard\WebAuthn\Extension\AuthenticationExtensionInputInterface;
final class AuthenticationOptions
{
/**
* @var CredentialId[]
*/
private $allowCredentials = [];
/**
* @var string|null
*/
private $userVerification;
/**
* @var int|null
*/
private $timeout;
/**
* User handle to load credentials from, or null for client side discoverable.
*
* @var UserHandle|null
*/
private $userHandle;
/**
* @var AuthenticationExtensionInputInterface[]
*/
private $extensions = [];
private function __construct(?UserHandle $userHandle)
{
$this->userHandle = $userHandle;
}
public static function createForUser(UserHandle $userHandle): self
{
return new self($userHandle);
}
public static function createForAnyUser(): self
{
return new self(null);
}
public function getUserHandle(): ?UserHandle
{
return $this->userHandle;
}
public function addAllowCredential(CredentialId $credential): void
{
$this->allowCredentials[] = $credential;
}
/**
* @return CredentialId[]
*/
public function getAllowCredentials(): array
{
return $this->allowCredentials;
}
public function getUserVerification(): ?string
{
return $this->userVerification;
}
public function setUserVerification(?string $value): void
{
if ($value !== null && !UserVerificationRequirement::isValidValue($value)) {
throw new WebAuthnException(sprintf('Value %s is not a valid UserVerificationRequirement', $value));
}
$this->userVerification = $value;
}
public function getTimeout(): ?int
{
return $this->timeout;
}
public function setTimeout(?int $timeout): void
{
$this->timeout = $timeout;
}
public function addExtensionInput(AuthenticationExtensionInputInterface $input): void
{
$this->extensions[] = $input;
}
/**
* @return AuthenticationExtensionInputInterface[]
*/
public function getExtensionInputs(): array
{
return $this->extensions;
}
}