|
9 | 9 | namespace OCA\UserOIDC\Command; |
10 | 10 |
|
11 | 11 | use OC\Core\Command\Base; |
| 12 | +use OCA\UserOIDC\Db\ProviderMapper; |
12 | 13 | use OCA\UserOIDC\Service\ProviderService; |
| 14 | +use OCP\Security\ICrypto; |
13 | 15 | use Symfony\Component\Console\Input\InputInterface; |
14 | 16 | use Symfony\Component\Console\Input\InputOption; |
15 | 17 | use Symfony\Component\Console\Output\OutputInterface; |
16 | 18 |
|
17 | 19 | class ListProviders extends Base { |
18 | 20 |
|
19 | 21 | public function __construct( |
| 22 | + private ProviderMapper $providerMapper, |
20 | 23 | private ProviderService $providerService, |
| 24 | + private ICrypto $crypto, |
21 | 25 | ) { |
22 | 26 | parent::__construct(); |
23 | 27 | } |
24 | 28 |
|
25 | 29 | protected function configure() { |
26 | 30 | $this |
27 | 31 | ->setName('user_oidc:providers') |
28 | | - ->setDescription('List all providers') |
| 32 | + ->setDescription('List all providers and print their configuration') |
29 | 33 | ->addOption('sensitive', 's', InputOption::VALUE_NONE, 'Obfuscate sensitive values like the client ID and the discovery endpoint domain name'); |
30 | 34 | $this->defaultOutputFormat = self::OUTPUT_FORMAT_JSON_PRETTY; |
31 | 35 | parent::configure(); |
32 | 36 | } |
33 | 37 |
|
34 | 38 | protected function execute(InputInterface $input, OutputInterface $output) { |
35 | 39 | $outputFormat = $input->getOption('output') ?? 'json_pretty'; |
| 40 | + $sensitive = $input->getOption('sensitive'); |
36 | 41 |
|
37 | | - $providersWithSettings = $this->providerService->getProvidersWithSettings(); |
38 | | - if ($input->getOption('sensitive')) { |
39 | | - $providersWithSettings = array_map(function ($provider) { |
40 | | - $provider['clientId'] = '********'; |
| 42 | + $providers = $this->providerMapper->getProviders(); |
| 43 | + |
| 44 | + $providersWithSettings = array_map(function ($provider) use ($sensitive) { |
| 45 | + $providerSettings = $this->providerService->getSettings($provider->getId()); |
| 46 | + $serializedProvider = $provider->jsonSerialize(); |
| 47 | + if ($sensitive) { |
| 48 | + $serializedProvider['clientId'] = '********'; |
| 49 | + $serializedProvider['clientSecret'] = '********'; |
41 | 50 | try { |
42 | | - $discoveryDomainName = parse_url($provider['discoveryEndpoint'], PHP_URL_HOST); |
43 | | - $provider['discoveryEndpoint'] = str_replace($discoveryDomainName, '********', $provider['discoveryEndpoint']); |
| 51 | + $discoveryDomainName = parse_url($serializedProvider['discoveryEndpoint'], PHP_URL_HOST); |
| 52 | + $serializedProvider['discoveryEndpoint'] = str_replace($discoveryDomainName, '********', $serializedProvider['discoveryEndpoint']); |
44 | 53 | } catch (\Exception|\Throwable) { |
45 | 54 | } |
46 | | - return $provider; |
47 | | - }, $providersWithSettings); |
48 | | - } |
| 55 | + } else { |
| 56 | + $serializedProvider['clientSecret'] = $this->crypto->decrypt($provider->getClientSecret()); |
| 57 | + } |
| 58 | + return array_merge($serializedProvider, ['settings' => $providerSettings]); |
| 59 | + }, $providers); |
| 60 | + |
49 | 61 | if ($outputFormat === 'json') { |
50 | 62 | foreach ($providersWithSettings as $provider) { |
51 | 63 | $output->writeln(json_encode($provider, JSON_THROW_ON_ERROR)); |
|
0 commit comments