You've already forked php-auth
generated from siteworxpro/Php-Template
Some checks failed
🧪✨ Tests Workflow / 📝 ✨ Code Lint (push) Successful in 2m25s
🧪✨ Tests Workflow / 🛡️ 🔒 Library Audit (push) Successful in 2m35s
🧪✨ Tests Workflow / 🧪 ✨ Database Migrations (push) Failing after 2m45s
🧪✨ Tests Workflow / 🛡️ 🔒 License Check (push) Successful in 2m36s
🧪✨ Tests Workflow / 🐙 🔍 Code Sniffer (push) Failing after 2m25s
🧪✨ Tests Workflow / 🧪 ✅ Unit Tests (push) Failing after 1m10s
58 lines
2.1 KiB
PHP
58 lines
2.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Siteworxpro\App\Cli\Commands\OAuth;
|
|
|
|
use Siteworxpro\App\Cli\ClimateOutput;
|
|
use Siteworxpro\App\CommandBus\Commands\CreateClient as CreateClientCommand;
|
|
use Siteworxpro\App\CommandBus\Exceptions\CommandHandlerException;
|
|
use Siteworxpro\App\OAuth\Entities\Client;
|
|
use Siteworxpro\App\Services\Facades\CommandBus;
|
|
use Symfony\Component\Console\Attribute\AsCommand;
|
|
use Symfony\Component\Console\Command\Command;
|
|
use Symfony\Component\Console\Input\ArgvInput;
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
use Symfony\Component\Console\Question\ChoiceQuestion;
|
|
use Symfony\Component\Console\Question\Question;
|
|
|
|
#[AsCommand(name: 'oauth:client:create', description: 'Create a new OAuth client.')]
|
|
class CreateClient extends \Siteworxpro\App\Cli\Commands\Command
|
|
{
|
|
public function __invoke($input, $output): int
|
|
{
|
|
$question = new Question('Enter client name: ');
|
|
$clientName = $this->helper->ask($input, $output, $question);
|
|
|
|
$question = new Question('Enter client description (optional): ', '');
|
|
$clientDescription = $this->helper->ask($input, $output, $question);
|
|
|
|
$question = new ChoiceQuestion('Enter client grants', [
|
|
'authorization_code',
|
|
'client_credentials',
|
|
'refresh_token',
|
|
'password',
|
|
], 0);
|
|
$question->setMultiselect(true);
|
|
|
|
$grants = $this->helper->ask($input, $output, $question);
|
|
|
|
$command = new CreateClientCommand($clientName, $grants, $clientDescription);
|
|
try {
|
|
/** @var Client $client */
|
|
$client = CommandBus::handle($command);
|
|
|
|
$output->green('OAuth client created successfully');
|
|
$output->info('Client ID: ' . $client->client_id);
|
|
$output->info('Client Secret: ' . $client->client_secret)->br(2);
|
|
} catch (CommandHandlerException $exception) {
|
|
$output->error($exception->getMessage());
|
|
|
|
return Command::FAILURE;
|
|
}
|
|
|
|
return Command::SUCCESS;
|
|
}
|
|
}
|