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
76 lines
2.4 KiB
PHP
76 lines
2.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Siteworxpro\App\Cli\Commands\OAuth;
|
|
|
|
use Siteworxpro\App\Cli\ClimateOutput;
|
|
use Siteworxpro\App\Cli\Commands\Command;
|
|
use Siteworxpro\App\OAuth\Entities\Client;
|
|
use Siteworxpro\App\Services\Facades\Config;
|
|
use Symfony\Component\Console\Attribute\AsCommand;
|
|
use Symfony\Component\Console\Input\ArgvInput;
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
#[AsCommand('oauth:client:list', 'List all OAuth clients')]
|
|
class ListClients extends Command
|
|
{
|
|
protected function configure(): void
|
|
{
|
|
$this->addArgument('client-id', null, 'Filter by client ID');
|
|
}
|
|
|
|
public function __invoke(ArgvInput|InputInterface $input, ClimateOutput|OutputInterface $output): int
|
|
{
|
|
if ($input->getArgument('client-id')) {
|
|
$client = Client::find($input->getArgument('client-id'));
|
|
|
|
if (!$client) {
|
|
$output->red('No OAuth client found with the specified client ID.');
|
|
|
|
return self::SUCCESS;
|
|
}
|
|
|
|
$output->json([
|
|
'ID' => $client->id,
|
|
'Name' => $client->name,
|
|
'Client ID' => $client->client_id,
|
|
'Client Secret' => $client->client_secret,
|
|
'Grant Types' => implode(', ', $client->grant_types->toArray()),
|
|
'Access Token Url' => Config::get('app.url') . '/client/access_token',
|
|
'OAuth Config Url' => Config::get('app.url') .
|
|
'/client/' . $client->id . '/.well-known/openid-configuration',
|
|
'Scopes' => $client->scopes->toArray()
|
|
]);
|
|
|
|
return self::SUCCESS;
|
|
}
|
|
|
|
$clients = Client::all('id', 'name', 'client_id', 'client_secret', 'grant_types');
|
|
|
|
if ($clients->isEmpty()) {
|
|
$output->yellow('No OAuth clients found.');
|
|
|
|
return self::SUCCESS;
|
|
}
|
|
|
|
$outputArray = [];
|
|
|
|
$clients->map(function (Client $client) use (&$outputArray, $input) {
|
|
$outputValues = [
|
|
'ID' => $client->id,
|
|
'Name' => $client->name,
|
|
'Client ID' => $client->client_id,
|
|
'Grant Types' => implode(', ', $client->grant_types->toArray()),
|
|
];
|
|
|
|
$outputArray[] = $outputValues;
|
|
});
|
|
|
|
$output->table($outputArray);
|
|
|
|
return self::SUCCESS;
|
|
}
|
|
}
|