* * @final */ #[AsCommand(name: 'lexik:jwt:check-config', description: 'Checks that the bundle is properly configured.')] class CheckConfigCommand extends Command { /** * @deprecated */ protected static $defaultName = 'lexik:jwt:check-config'; private $keyLoader; private $signatureAlgorithm; public function __construct(KeyLoaderInterface $keyLoader, $signatureAlgorithm) { $this->keyLoader = $keyLoader; $this->signatureAlgorithm = $signatureAlgorithm; parent::__construct(); } /** * {@inheritdoc} */ protected function configure(): void { $this ->setName(static::$defaultName) ->setDescription('Checks JWT configuration'); } /** * {@inheritdoc} * * @return int */ protected function execute(InputInterface $input, OutputInterface $output): int { try { $this->keyLoader->loadKey(KeyLoaderInterface::TYPE_PRIVATE); // No public key for HMAC if (false === strpos($this->signatureAlgorithm, 'HS')) { $this->keyLoader->loadKey(KeyLoaderInterface::TYPE_PUBLIC); } } catch (\RuntimeException $e) { $output->writeln('' . $e->getMessage() . ''); return 1; } $output->writeln('The configuration seems correct.'); return 0; } }