| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace Webauthn\ClientDataCollector; |
| 6 |
|
| 7 |
use function in_array; |
| 8 |
use Webauthn\AuthenticatorResponse; |
| 9 |
use Webauthn\CollectedClientData; |
| 10 |
use Webauthn\Exception\AuthenticatorResponseVerificationException; |
| 11 |
use Webauthn\PublicKeyCredentialOptions; |
| 12 |
|
| 13 |
final readonly class ClientDataCollectorManager |
| 14 |
{ |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
public function __construct( |
| 19 |
private iterable $clientDataCollectors, |
| 20 |
) { |
| 21 |
} |
| 22 |
|
| 23 |
public function collect( |
| 24 |
CollectedClientData $collectedClientData, |
| 25 |
PublicKeyCredentialOptions $publicKeyCredentialOptions, |
| 26 |
AuthenticatorResponse $authenticatorResponse, |
| 27 |
string $host |
| 28 |
): void { |
| 29 |
foreach ($this->clientDataCollectors as $clientDataCollector) { |
| 30 |
if (in_array($collectedClientData->type, $clientDataCollector->supportedTypes(), true)) { |
| 31 |
$clientDataCollector->verifyCollectedClientData( |
| 32 |
$collectedClientData, |
| 33 |
$publicKeyCredentialOptions, |
| 34 |
$authenticatorResponse, |
| 35 |
$host |
| 36 |
); |
| 37 |
return; |
| 38 |
} |
| 39 |
} |
| 40 |
|
| 41 |
throw AuthenticatorResponseVerificationException::create('No client data collector found.'); |
| 42 |
} |
| 43 |
} |