1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Sylius package. |
5
|
|
|
* |
6
|
|
|
* (c) Paweł Jędrzejewski |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
declare(strict_types=1); |
13
|
|
|
|
14
|
|
|
namespace Sylius\Bundle\AdminApiBundle\Command; |
15
|
|
|
|
16
|
|
|
use FOS\OAuthServerBundle\Model\ClientManagerInterface; |
17
|
|
|
use Sylius\Bundle\AdminApiBundle\Model\Client; |
18
|
|
|
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; |
19
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
20
|
|
|
use Symfony\Component\Console\Input\InputOption; |
21
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @author Arnaud Langlade <[email protected]> |
25
|
|
|
*/ |
26
|
|
|
final class CreateClientCommand extends ContainerAwareCommand |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* {@inheritdoc} |
30
|
|
|
*/ |
31
|
|
|
protected function configure(): void |
32
|
|
|
{ |
33
|
|
|
$this |
34
|
|
|
->setName('sylius:oauth-server:create-client') |
35
|
|
|
->setDescription('Creates a new client') |
36
|
|
|
->addOption( |
37
|
|
|
'redirect-uri', |
38
|
|
|
null, |
39
|
|
|
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, |
40
|
|
|
'Sets redirect uri for client.' |
41
|
|
|
) |
42
|
|
|
->addOption( |
43
|
|
|
'grant-type', |
44
|
|
|
null, |
45
|
|
|
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, |
46
|
|
|
'Sets allowed grant type for client.' |
47
|
|
|
) |
48
|
|
|
->setHelp(<<<EOT |
49
|
|
|
The <info>%command.name%</info>command creates a new client. |
50
|
|
|
<info>php %command.full_name% [--redirect-uri=...] [--grant-type=...] name</info> |
51
|
|
|
EOT |
52
|
|
|
); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* {@inheritdoc} |
57
|
|
|
*/ |
58
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): void |
59
|
|
|
{ |
60
|
|
|
$clientManager = $this->getClientManager(); |
61
|
|
|
|
62
|
|
|
/** @var Client $client */ |
63
|
|
|
$client = $clientManager->createClient(); |
64
|
|
|
$client->setRedirectUris($input->getOption('redirect-uri')); |
65
|
|
|
$client->setAllowedGrantTypes($input->getOption('grant-type')); |
66
|
|
|
$clientManager->updateClient($client); |
67
|
|
|
|
68
|
|
|
$output->writeln( |
69
|
|
|
sprintf( |
70
|
|
|
'A new client with public id <info>%s</info>, secret <info>%s</info> has been added', |
71
|
|
|
$client->getPublicId(), |
72
|
|
|
$client->getSecret() |
73
|
|
|
) |
74
|
|
|
); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @return ClientManagerInterface |
79
|
|
|
*/ |
80
|
|
|
private function getClientManager(): ClientManagerInterface |
81
|
|
|
{ |
82
|
|
|
return $this->getContainer()->get('fos_oauth_server.client_manager.default'); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|