| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace Webauthn\ClientDataCollector; |
| 6 |
|
| 7 |
use function in_array; |
| 8 |
use function sprintf; |
| 9 |
use Webauthn\AuthenticatorResponse; |
| 10 |
use Webauthn\CollectedClientData; |
| 11 |
use Webauthn\Exception\AuthenticatorResponseVerificationException; |
| 12 |
use Webauthn\PublicKeyCredentialOptions; |
| 13 |
|
| 14 |
final class WebauthnAuthenticationCollector implements ClientDataCollector |
| 15 |
{ |
| 16 |
public function supportedTypes(): array |
| 17 |
{ |
| 18 |
return ['webauthn.get', 'webauthn.create']; |
| 19 |
} |
| 20 |
|
| 21 |
public function verifyCollectedClientData( |
| 22 |
CollectedClientData $collectedClientData, |
| 23 |
PublicKeyCredentialOptions $publicKeyCredentialOptions, |
| 24 |
AuthenticatorResponse $authenticatorResponse, |
| 25 |
string $host |
| 26 |
): void { |
| 27 |
in_array( |
| 28 |
$collectedClientData->type, |
| 29 |
$this->supportedTypes(), |
| 30 |
true |
| 31 |
) || throw AuthenticatorResponseVerificationException::create( |
| 32 |
sprintf('The client data type is not "%s" supported.', implode('", "', $this->supportedTypes())) |
| 33 |
); |
| 34 |
} |
| 35 |
} |