misc_pterodactyl-panel/app/Services/Users/SecurityKeys/CreatePublicKeyCredentialsService.php
2021-09-19 11:24:33 -07:00

39 lines
1.2 KiB
PHP

<?php
namespace Pterodactyl\Services\Users\SecurityKeys;
use Ramsey\Uuid\Uuid;
use Pterodactyl\Models\User;
use Pterodactyl\Models\SecurityKey;
use Webauthn\PublicKeyCredentialUserEntity;
use Webauthn\PublicKeyCredentialCreationOptions;
use Pterodactyl\Repositories\SecurityKeys\WebauthnServerRepository;
class CreatePublicKeyCredentialsService
{
protected WebauthnServerRepository $webauthnServerRepository;
public function __construct(WebauthnServerRepository $webauthnServerRepository)
{
$this->webauthnServerRepository = $webauthnServerRepository;
}
public function handle(User $user, ?string $displayName): PublicKeyCredentialCreationOptions
{
$id = Uuid::uuid4()->toString();
$entity = new PublicKeyCredentialUserEntity($user->uuid, $id, $name ?? $user->email);
$excluded = $user->securityKeys->map(function (SecurityKey $key) {
return $key->toCredentialsDescriptor();
})->values()->toArray();
$server = $this->webauthnServerRepository->getServer($user);
return $server->generatePublicKeyCredentialCreationOptions(
$entity,
PublicKeyCredentialCreationOptions::ATTESTATION_CONVEYANCE_PREFERENCE_NONE,
$excluded
);
}
}