| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace Webauthn; |
| 6 |
|
| 7 |
use function in_array; |
| 8 |
use InvalidArgumentException; |
| 9 |
use function is_string; |
| 10 |
use function sprintf; |
| 11 |
use Webauthn\AuthenticationExtensions\AuthenticationExtension; |
| 12 |
use Webauthn\AuthenticationExtensions\AuthenticationExtensions; |
| 13 |
|
| 14 |
abstract class PublicKeyCredentialOptions |
| 15 |
{ |
| 16 |
public const HINT_SECURITY_KEY = 'security-key'; |
| 17 |
|
| 18 |
public const HINT_CLIENT_DEVICE = 'client-device'; |
| 19 |
|
| 20 |
public const HINT_HYBRID = 'hybrid'; |
| 21 |
|
| 22 |
public const HINTS = [self::HINT_SECURITY_KEY, self::HINT_CLIENT_DEVICE, self::HINT_HYBRID]; |
| 23 |
|
| 24 |
public AuthenticationExtensions $extensions; |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
public function __construct( |
| 33 |
public string $challenge, |
| 34 |
public null|int $timeout = null, |
| 35 |
null|array|AuthenticationExtensions $extensions = null, |
| 36 |
public array $hints = [], |
| 37 |
) { |
| 38 |
($this->timeout === null || $this->timeout > 0) || throw new InvalidArgumentException('Invalid timeout'); |
| 39 |
if ($extensions === null) { |
| 40 |
$this->extensions = AuthenticationExtensions::create(); |
| 41 |
} elseif ($extensions instanceof AuthenticationExtensions) { |
| 42 |
$this->extensions = $extensions; |
| 43 |
} else { |
| 44 |
$this->extensions = AuthenticationExtensions::create($extensions); |
| 45 |
} |
| 46 |
|
| 47 |
foreach ($this->hints as $hint) { |
| 48 |
is_string($hint) || throw new InvalidArgumentException('Invalid hint: hints must be strings'); |
| 49 |
in_array($hint, self::HINTS, true) || throw new InvalidArgumentException( |
| 50 |
sprintf('Invalid hint "%s". Allowed values are: %s', $hint, implode(', ', self::HINTS)) |
| 51 |
); |
| 52 |
} |
| 53 |
} |
| 54 |
} |