All checks were successful
rvr-nextgen/pipeline/pr-master This commit looks good
53 lines
1.9 KiB
PHP
53 lines
1.9 KiB
PHP
<?php namespace RVR\Cli;
|
|
|
|
use RVR\Repository\OAuthClientRepository;
|
|
use Symfony\Component\Console\Command\Command;
|
|
use Symfony\Component\Console\Input\InputArgument;
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
class RemoveOAuthRedirectUriCommand extends Command
|
|
{
|
|
public function configure(): void
|
|
{
|
|
$this->setName('oauth:remove-redirect-uri')
|
|
->setDescription('Removing of redirect URI for OAuth client.')
|
|
->addArgument('client_id', InputArgument::REQUIRED, 'The OAuth client ID')
|
|
->addArgument('redirect_uris', InputArgument::IS_ARRAY, 'Redirect URIs to remove');
|
|
}
|
|
|
|
public function execute(InputInterface $input, OutputInterface $output): int
|
|
{
|
|
$oAuthClientRepository = new OAuthClientRepository();
|
|
$oAuthClient = $oAuthClientRepository->getByClientId($input->getArgument('client_id'));
|
|
|
|
if ($oAuthClient === null) {
|
|
$output->writeln('<error>OAuth client does not exist!</error>');
|
|
return 1;
|
|
}
|
|
|
|
$redirectUris = array_diff($oAuthClient->getRedirectUrisArray(), $input->getArgument('redirect_uris'));
|
|
|
|
$oAuthClient->setRedirectUrisArray($redirectUris);
|
|
|
|
try {
|
|
\Container::$persistentDataManager->saveToDb($oAuthClient);
|
|
} catch (\Exception $e) {
|
|
$output->writeln('<error>Removing redirect URI failed!</error>');
|
|
$output->writeln('');
|
|
|
|
$output->writeln((string) $e);
|
|
$output->writeln('');
|
|
|
|
return 1;
|
|
}
|
|
|
|
$redirectUrisToPrint = [];
|
|
foreach ($redirectUris as $redirectUri) $redirectUrisToPrint[] = '* ' . $redirectUri;
|
|
|
|
$output->writeln('<info>Redirect URIS were successfully removed! Current URIs:' . "\n" . implode("\n", $redirectUrisToPrint) . '</info>');
|
|
|
|
return 0;
|
|
}
|
|
}
|