Skip to content

Commit

Permalink
feature #13369 [Command] add command to generate jwt (SirDomin)
Browse files Browse the repository at this point in the history
This PR was merged into the 1.11-dev branch.

Discussion
----------

| Q               | A
| --------------- | -----
| Branch?         | master
| Bug fix?        | no
| New feature?    | yes
| BC breaks?      | no
| Deprecations?   | no
| Related tickets | 
| License         | MIT


![image](https://user-images.githubusercontent.com/22825722/145157836-76155d82-7a00-44e0-9b21-603148836ff7.png)


<!--
 - Bug fixes must be submitted against the 1.10 branch
 - Features and deprecations must be submitted against the master branch
 - Make sure that the correct base branch is set

 To be sure you are not breaking any Backward Compatibilities, check the documentation:
 https://docs.sylius.com/en/latest/book/organization/backward-compatibility-promise.html
-->


Commits
-------

f8348e9 [Command] add command to generate jwt
33a3d4e [Command] make command more consistent, add info to docs
  • Loading branch information
GSadee committed Dec 9, 2021
2 parents 65f7a4c + 33a3d4e commit bf3699e
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/getting-started-with-sylius/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Run the Sylius installation command to do that.
This command will do several things for you - the first two steps are checking if your environment fulfills technical requirements,
and setting the project database. You will also be asked if you want to have default fixtures loaded into your database - let's say
"No" to that, we will configure the store manually.
You will be also asked if you want to generate API Tokens.

.. image:: /_images/getting-started-with-sylius/installation1.png

Expand Down
4 changes: 4 additions & 0 deletions src/Sylius/Bundle/CoreBundle/Command/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ final class InstallCommand extends AbstractInstallCommand
'command' => 'setup',
'message' => 'Shop configuration.',
],
[
'command' => 'jwt-setup',
'message' => 'Configuring JWT token.',
],
[
'command' => 'assets',
'message' => 'Installing assets.',
Expand Down
55 changes: 55 additions & 0 deletions src/Sylius/Bundle/CoreBundle/Command/JwtConfigurationCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Sylius\Bundle\CoreBundle\Command;

use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\ConfirmationQuestion;

final class JwtConfigurationCommand extends AbstractInstallCommand
{
protected static $defaultName = 'sylius:install:jwt-setup';

protected function configure(): void
{
$this
->setDescription('Setup JWT token')
->setHelp(
<<<EOT
The <info>%command.name%</info> command generates JWT token.
EOT
)
;
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
$helper = $this->getHelper('question');

$output->writeln('Generating JWT token for Sylius API');

$question = new ConfirmationQuestion('Do you want to generate JWT token? (y/N)', false);

if (!$helper->ask($input, $output, $question)) {
return 0;
}

$this->commandExecutor->runCommand('lexik:jwt:generate-keypair', ['--overwrite' => true], $output);

$output->writeln('Please, remember to enable Sylius API');
$output->writeln('https://docs.sylius.com/en/1.10/book/api/introduction.html');

return 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,9 @@
<service id="Sylius\Bundle\CoreBundle\Command\InformAboutGUSCommand">
<tag name="console.command" />
</service>

<service id="Sylius\Bundle\CoreBundle\Command\JwtConfigurationCommand">
<tag name="console.command" />
</service>
</services>
</container>

0 comments on commit bf3699e

Please sign in to comment.