|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace LoginCidadao\OAuthBundle\Command; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; |
|
6
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
7
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
8
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
9
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
10
|
|
|
use LoginCidadao\OAuthBundle\Entity\Client; |
|
11
|
|
|
|
|
12
|
|
|
class ClientCreateCommand extends ContainerAwareCommand |
|
13
|
|
|
{ |
|
14
|
|
|
|
|
15
|
|
|
protected function configure() |
|
16
|
|
|
{ |
|
17
|
|
|
$this |
|
18
|
|
|
->setName('lc:oauth-server:client:create') |
|
19
|
|
|
->setDescription('Creates a new client') |
|
20
|
|
|
->addArgument('name', InputArgument::REQUIRED, 'Sets the client name', null) |
|
21
|
|
|
->addArgument('description', InputArgument::REQUIRED, 'Sets the client description', null) |
|
22
|
|
|
->addArgument('site-url', InputArgument::REQUIRED, 'Sets the client main URL', null) |
|
23
|
|
|
->addOption('redirect-uri', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Sets redirect uri for client. Use this option multiple times to set multiple redirect URIs.', null) |
|
24
|
|
|
->addOption('grant-type', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Sets allowed grant type for client. Use this option multiple times to set multiple grant types..', null) |
|
25
|
|
|
->setHelp(<<<EOT |
|
26
|
|
|
The <info>%command.name%</info>command creates a new client. |
|
27
|
|
|
|
|
28
|
|
|
<info>php %command.full_name% [--redirect-uri=...] [--grant-type=...] name</info> |
|
29
|
|
|
|
|
30
|
|
|
EOT |
|
31
|
|
|
); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
35
|
|
|
{ |
|
36
|
|
|
$clientManager = $this->getContainer()->get('fos_oauth_server.client_manager'); |
|
37
|
|
|
$client = $clientManager->createClient(); |
|
38
|
|
|
$client->setName($input->getArgument('name')); |
|
39
|
|
|
$client->setDescription($input->getArgument('description')); |
|
40
|
|
|
$client->setSiteUrl($input->getArgument('site-url')); |
|
41
|
|
|
$client->setRedirectUris($input->getOption('redirect-uri')); |
|
42
|
|
|
$client->setAllowedGrantTypes($input->getOption('grant-type')); |
|
43
|
|
|
$clientManager->updateClient($client); |
|
44
|
|
|
$output->writeln(sprintf('Added a new client with name <info>%s</info> and public id <info>%s</info>.', $client->getName(), $client->getPublicId())); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
} |
|
48
|
|
|
|