You've already forked php-auth
generated from siteworxpro/Php-Template
Basics of auth
This commit is contained in:
48
src/Cli/Commands/OAuth/CreateClient.php
Normal file
48
src/Cli/Commands/OAuth/CreateClient.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Siteworxpro\App\Cli\Commands\OAuth;
|
||||
|
||||
use Ahc\Cli\IO\Interactor;
|
||||
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;
|
||||
|
||||
class CreateClient extends \Siteworxpro\App\Cli\Commands\Command
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct('oauth:client:create', 'Create a new OAuth client.');
|
||||
}
|
||||
|
||||
public function execute(): int
|
||||
{
|
||||
$interactor = new Interactor();
|
||||
$clientName = $interactor->prompt('Enter client name');
|
||||
$clientDescription = $interactor->prompt('Enter client description (optional)', '');
|
||||
$clientGrantsString = $interactor->prompt(
|
||||
'Enter client grants (comma separated, e.g. "authorization_code,refresh_token")',
|
||||
false
|
||||
);
|
||||
|
||||
$grants = explode(',', $clientGrantsString);
|
||||
|
||||
$command = new CreateClientCommand($clientName, $grants, $clientDescription);
|
||||
try {
|
||||
/** @var Client $client */
|
||||
$client = CommandBus::handle($command);
|
||||
|
||||
$this->climate->green('OAuth client created successfully');
|
||||
$this->climate->info('Client ID: ' . $client->client_id);
|
||||
$this->climate->info('Client Secret: ' . $client->client_secret)->br(2);
|
||||
} catch (CommandHandlerException $exception) {
|
||||
$this->climate->error($exception->getMessage());
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user