-
Notifications
You must be signed in to change notification settings - Fork 450
/
Copy pathCreateClientCommand.php
97 lines (78 loc) · 2.68 KB
/
CreateClientCommand.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
declare(strict_types=1);
/*
* This file is part of the FOSOAuthServerBundle package.
*
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace FOS\OAuthServerBundle\Command;
use FOS\OAuthServerBundle\Model\ClientManagerInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
class CreateClientCommand extends Command
{
/** @var ClientManagerInterface */
private $clientManager;
public function __construct(ClientManagerInterface $clientManager)
{
parent::__construct();
$this->clientManager = $clientManager;
}
/**
* {@inheritdoc}
*/
protected function configure(): void
{
parent::configure();
$this
->setName('fos:oauth-server:create-client')
->setDescription('Creates a new client')
->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
)
->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
)
->setHelp(<<<EOT
The <info>%command.name%</info> command creates a new client.
<info>php %command.full_name% [--redirect-uri=...] [--grant-type=...]</info>
EOT
)
;
}
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
$io->title('Client Credentials');
// Create a new client
$client = $this->clientManager->createClient();
$client->setRedirectUris($input->getOption('redirect-uri'));
$client->setAllowedGrantTypes($input->getOption('grant-type'));
// Save the client
$this->clientManager->updateClient($client);
// Give the credentials back to the user
$headers = ['Client ID', 'Client Secret'];
$rows = [
[$client->getPublicId(), $client->getSecret()],
];
$io->table($headers, $rows);
return 0;
}
}