27 lines
813 B
PHP

<?php declare(strict_types=1);
namespace App\Services\Registry\V2;
use App\Dto\Service\Registry\V2\AuthorizationConfig;
use Firebase\JWT\JWT;
final readonly class JwtCommand
{
public function __construct(
private KidCommand $kidCommand,
private ContentPrivateKeyCommand $contentPrivateKeyCommand,
) { }
public function execute(AuthorizationConfig $authorizationConfig, array $payload): string
{
$contentPrivateKey = $this->contentPrivateKeyCommand->execute($authorizationConfig->getPrivateKeyName());
return JWT::encode(
$payload,
$contentPrivateKey,
$authorizationConfig->getAlgorithm(),
$this->kidCommand->execute($authorizationConfig->getPrivateKeyName(), $contentPrivateKey)
);
}
}