diff --git a/src/Cli/Commands/Command.php b/src/Cli/Commands/Command.php index c4b9e61..6af3448 100644 --- a/src/Cli/Commands/Command.php +++ b/src/Cli/Commands/Command.php @@ -28,13 +28,22 @@ abstract class Command extends \Symfony\Component\Console\Command\Command implem /** * @param ClimateOutput $output * @param ClimateOutput|ArgvInput $input + * @param bool $allClients * @return Client | null */ - protected function askForClient(ClimateOutput $output, ClimateOutput|ArgvInput $input): ?Client - { - /** @var Collection $clients */ - $clients = Client::whereJsonContains('grant_types', 'authorization_code') - ->get(['id', 'name']); + protected function askForClient( + ClimateOutput $output, + ClimateOutput|ArgvInput $input, + bool $allClients = false + ): ?Client { + if ($allClients) { + /** @var Collection $clients */ + $clients = Client::all(['id', 'name']); + } else { + /** @var Collection $clients */ + $clients = Client::whereJsonContains('grant_types', 'authorization_code') + ->get(['id', 'name']); + } if ($clients->isEmpty()) { $output->error('No OAuth clients available.'); diff --git a/src/Cli/Commands/OAuth/CreateClient.php b/src/Cli/Commands/OAuth/CreateClient.php index 7303ce7..8459e16 100644 --- a/src/Cli/Commands/OAuth/CreateClient.php +++ b/src/Cli/Commands/OAuth/CreateClient.php @@ -40,19 +40,22 @@ class CreateClient extends \Siteworxpro\App\Cli\Commands\Command $grantsEnum[] = ClientGrantAlias::from($grant); } - $question = $this->helper->ask( - $input, - $output, - new \Symfony\Component\Console\Question\ConfirmationQuestion( - 'External Client (Require PKCE)? (y/N): ', - false, - '/^(y|yes)/i' - ) - ); + $isExternal = false; + if (in_array('authorization_code', $grants)) { + $question = $this->helper->ask( + $input, + $output, + new \Symfony\Component\Console\Question\ConfirmationQuestion( + 'Require PKCE for Authorization Code grant? (y/N): ', + false, + '/^(y|yes)/i' + ) + ); + $isExternal = $question === 'y' || $question === true; + } - - $command = new CreateClientCommand($clientName, $grantsEnum, $clientDescription); + $command = new CreateClientCommand($clientName, $grantsEnum, $clientDescription, $isExternal); try { /** @var Client $client */ $client = CommandBus::handle($command); diff --git a/src/Cli/Commands/OAuth/DeleteClient.php b/src/Cli/Commands/OAuth/DeleteClient.php index c93d99c..86b7af2 100644 --- a/src/Cli/Commands/OAuth/DeleteClient.php +++ b/src/Cli/Commands/OAuth/DeleteClient.php @@ -14,7 +14,7 @@ class DeleteClient extends Command { public function __invoke(ClimateOutput|ArgvInput $input, $output): int { - $client = $this->askForClient($output, $input); + $client = $this->askForClient($output, $input, true); if ($client === null) { $output->red('No client selected, aborting.'); diff --git a/src/CommandBus/Commands/CreateClient.php b/src/CommandBus/Commands/CreateClient.php index 8bba77e..5cd2019 100644 --- a/src/CommandBus/Commands/CreateClient.php +++ b/src/CommandBus/Commands/CreateClient.php @@ -10,6 +10,7 @@ readonly class CreateClient extends Command * @param string $clientName * @param array $clientGrants * @param string $clientDescription + * @param bool $isExternal */ public function __construct( private string $clientName, diff --git a/src/EventListeners/AccessTokenIssuedListener.php b/src/EventListeners/AccessTokenIssuedListener.php index b633b77..d3b5d66 100644 --- a/src/EventListeners/AccessTokenIssuedListener.php +++ b/src/EventListeners/AccessTokenIssuedListener.php @@ -5,16 +5,17 @@ declare(strict_types=1); namespace Siteworxpro\App\EventListeners; use Siteworxpro\App\Attributes\Events\ListensFor; +use Siteworxpro\App\Events\AccessToken\Issued as IssuedEvent; use Siteworxpro\App\Models\AuditLog; use Siteworxpro\App\Models\Enums\AuditLogAction; -#[ListensFor(\Siteworxpro\App\Events\AccessToken\Issued::class)] +#[ListensFor(IssuedEvent::class)] class AccessTokenIssuedListener extends Listener { /** * Handle the event. * - * @param string | \Siteworxpro\App\Events\AccessToken\Issued $event + * @param string | IssuedEvent $event * @param array $payload * @return AuditLog|null */ @@ -24,7 +25,7 @@ class AccessTokenIssuedListener extends Listener $event = $payload[0] ?? null; } - if (!$event instanceof \Siteworxpro\App\Events\AccessToken\Issued) { + if (!$event instanceof IssuedEvent) { return null; }