1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace OAuth\Command; |
4
|
|
|
|
5
|
|
|
use Exception; |
6
|
|
|
use OAuth\Client; |
7
|
|
|
use OAuth\Repository\ScopeRepository; |
8
|
|
|
use OAuth\Scope; |
9
|
|
|
use OAuth\Service\ClientService; |
10
|
|
|
use Symfony\Component\Console\Command\Command; |
11
|
|
|
use Symfony\Component\Console\Helper\QuestionHelper; |
12
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
13
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
14
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
15
|
|
|
use Symfony\Component\Console\Question\ChoiceQuestion; |
16
|
|
|
use Symfony\Component\Console\Question\ConfirmationQuestion; |
17
|
|
|
use Symfony\Component\Console\Question\Question; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Class ClientCommand |
21
|
|
|
* @package OAuth\Command |
22
|
|
|
*/ |
23
|
|
|
class ClientScopeCommand extends Command |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @var ClientService $clientService |
27
|
|
|
*/ |
28
|
|
|
private $clientService; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var ScopeRepository $scopeRepository |
32
|
|
|
*/ |
33
|
|
|
private $scopeRepository; |
34
|
|
|
|
35
|
|
|
/** @var QuestionHelper $helper */ |
36
|
|
|
private $helper; |
|
|
|
|
37
|
|
|
|
38
|
|
|
public function __construct(ClientService $clientService, ScopeRepository $scopeRepository) |
39
|
|
|
{ |
40
|
|
|
$this->clientService = $clientService; |
41
|
|
|
$this->scopeRepository = $scopeRepository; |
42
|
|
|
parent::__construct('client:scope'); |
43
|
|
|
$this->addArgument('operation', InputArgument::REQUIRED, 'list, add, or remove.'); |
44
|
|
|
$this->addArgument('client', InputArgument::OPTIONAL, 'The client identifier.'); |
45
|
|
|
$this->addArgument('scope', InputArgument::OPTIONAL, 'The scope name when adding or removing.'); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* configure options |
50
|
|
|
*/ |
51
|
|
|
protected function configure() |
52
|
|
|
{ |
53
|
|
|
$this->setDescription('Add, remove, or list scopes for each client.'); |
54
|
|
|
$this->setHelp('Client scope administration'); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param InputInterface $input |
59
|
|
|
* @param OutputInterface $output |
60
|
|
|
* @return int|void|null |
61
|
|
|
* @throws Exception |
62
|
|
|
*/ |
63
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
64
|
|
|
{ |
65
|
|
|
$output->writeln('Client scope administration'); |
66
|
|
|
$operation = $input->getArgument('operation'); |
67
|
|
|
switch ($operation) { |
68
|
|
|
case 'list'; |
69
|
|
|
$this->listScopes($input, $output); |
70
|
|
|
break; |
71
|
|
|
case 'add'; |
72
|
|
|
$this->addScope($input, $output); |
73
|
|
|
break; |
74
|
|
|
case 'remove'; |
75
|
|
|
$this->removeScope($input, $output); |
76
|
|
|
break; |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @param string $argName |
82
|
|
|
* @param string $value |
83
|
|
|
* @throws Exception |
84
|
|
|
*/ |
85
|
|
|
private function getArgOrGetUpset(InputInterface $input, string $argName) |
86
|
|
|
{ |
87
|
|
|
$value = $input->getArgument($argName); |
88
|
|
|
if (!$value) { |
89
|
|
|
throw new Exception('No ' . $argName . ' provided'); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @param InputInterface $input |
95
|
|
|
* @param OutputInterface $output |
96
|
|
|
*/ |
97
|
|
|
private function listScopes(InputInterface $input, OutputInterface $output) |
|
|
|
|
98
|
|
|
{ |
99
|
|
|
$output->writeln('List scopes for client'); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @param InputInterface $input |
104
|
|
|
* @param OutputInterface $output |
105
|
|
|
* @throws Exception |
106
|
|
|
*/ |
107
|
|
|
private function addScope(InputInterface $input, OutputInterface $output) |
108
|
|
|
{ |
109
|
|
|
$client = $this->getArgOrGetUpset($input, 'client'); |
|
|
|
|
110
|
|
|
$scope = $this->getArgOrGetUpset($input, 'scope'); |
|
|
|
|
111
|
|
|
$output->writeln('Scope '. $scope . ', client ' . $client); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @param InputInterface $input |
116
|
|
|
* @param OutputInterface $output |
117
|
|
|
*/ |
118
|
|
|
private function removeScope(InputInterface $input, OutputInterface $output) |
|
|
|
|
119
|
|
|
{ |
120
|
|
|
$output->writeln('Remove scope for client'); |
121
|
|
|
} |
122
|
|
|
} |