2022-02-13 19:15:18 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Services\Users\SecurityKeys;
|
|
|
|
|
|
|
|
use Pterodactyl\Models\User;
|
|
|
|
use Pterodactyl\Models\SecurityKey;
|
|
|
|
use Webauthn\PublicKeyCredentialRequestOptions;
|
|
|
|
use Pterodactyl\Repositories\SecurityKeys\WebauthnServerRepository;
|
|
|
|
|
|
|
|
class GeneratePublicKeyCredentialsRequestService
|
|
|
|
{
|
|
|
|
protected WebauthnServerRepository $serverRepository;
|
|
|
|
|
|
|
|
public function __construct(WebauthnServerRepository $serverRepository)
|
|
|
|
{
|
|
|
|
$this->serverRepository = $serverRepository;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function handle(User $user): PublicKeyCredentialRequestOptions
|
|
|
|
{
|
|
|
|
$credentials = $user->securityKeys->map(function (SecurityKey $key) {
|
|
|
|
return $key->getPublicKeyCredentialDescriptor();
|
2022-02-13 19:23:20 +00:00
|
|
|
})->values()->toArray();
|
2022-02-13 19:15:18 +00:00
|
|
|
|
|
|
|
$response = $this->serverRepository->getServer($user)
|
|
|
|
->generatePublicKeyCredentialRequestOptions(
|
2022-02-14 00:06:53 +00:00
|
|
|
PublicKeyCredentialRequestOptions::USER_VERIFICATION_REQUIREMENT_PREFERRED,
|
|
|
|
$credentials
|
2022-02-13 19:15:18 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
return $response->setTimeout(300);
|
|
|
|
}
|
|
|
|
}
|