1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace rhertogh\Yii2Oauth2Server\controllers\console\client; |
4
|
|
|
|
5
|
|
|
use League\OAuth2\Server\Grant\GrantTypeInterface; |
6
|
|
|
use rhertogh\Yii2Oauth2Server\controllers\console\Oauth2ClientController; |
7
|
|
|
use rhertogh\Yii2Oauth2Server\helpers\DiHelper; |
8
|
|
|
use rhertogh\Yii2Oauth2Server\interfaces\components\openidconnect\scope\Oauth2OidcScopeCollectionInterface; |
9
|
|
|
use rhertogh\Yii2Oauth2Server\interfaces\models\Oauth2ClientInterface; |
10
|
|
|
use rhertogh\Yii2Oauth2Server\Oauth2Module; |
11
|
|
|
use Yii; |
12
|
|
|
use yii\base\Action; |
13
|
|
|
use yii\base\InvalidArgumentException; |
14
|
|
|
use yii\console\ExitCode; |
15
|
|
|
use yii\console\widgets\Table; |
16
|
|
|
use yii\helpers\Console; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @property Oauth2ClientController $controller |
20
|
|
|
*/ |
21
|
|
|
class Oauth2ListClientsAction extends Action |
22
|
|
|
{ |
23
|
|
|
public function run() |
24
|
|
|
{ |
25
|
|
|
$module = $this->controller->module; |
26
|
|
|
|
27
|
|
|
$clients = $module->getClientRepository()->getAllClients(); |
28
|
|
|
|
29
|
|
|
if (!$clients) { |
|
|
|
|
30
|
|
|
$this->controller->stdout('No clients defined. Run `yii ' . $this->controller->uniqueId . '/create` to define one.' . PHP_EOL); |
31
|
|
|
return ExitCode::OK; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
$rows = []; |
35
|
|
|
foreach ($clients as $client) { |
36
|
|
|
$redirectUris = $client->getRedirectUri(); |
37
|
|
|
$rows[] = [ |
38
|
|
|
'id' => $client->getPrimaryKey(), |
39
|
|
|
'identifier' => $client->getIdentifier(), |
40
|
|
|
'type' => $client->isConfidential() ? 'Confidential' : 'Public', |
41
|
|
|
'redirect_uris' => $redirectUris |
42
|
|
|
? ($redirectUris[0] |
43
|
|
|
. (count($redirectUris) > 1 |
|
|
|
|
44
|
|
|
? ' +' . (count($redirectUris) - 1) . ' more' |
45
|
|
|
: '') |
46
|
|
|
) |
47
|
|
|
: '', |
48
|
|
|
'grant_types' => implode(', ', Oauth2Module::getGrantTypeIdentifiers($client->getGrantTypes())), |
49
|
|
|
]; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
$this->controller->stdout(Table::widget([ |
53
|
|
|
'headers' => [ |
54
|
|
|
'ID', |
55
|
|
|
'Identifier', |
56
|
|
|
'Type', |
57
|
|
|
'Redirect URIs', |
58
|
|
|
'Grant Types', |
59
|
|
|
], |
60
|
|
|
'rows' => $rows, |
61
|
|
|
])); |
62
|
|
|
|
63
|
|
|
return ExitCode::OK; |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.