1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace rhertogh\Yii2Oauth2Server\controllers\console\debug; |
4
|
|
|
|
5
|
|
|
use League\OAuth2\Server\Grant\GrantTypeInterface; |
6
|
|
|
use rhertogh\Yii2Oauth2Server\controllers\console\Oauth2DebugController; |
7
|
|
|
use rhertogh\Yii2Oauth2Server\helpers\DateIntervalHelper; |
8
|
|
|
use rhertogh\Yii2Oauth2Server\Oauth2Module; |
9
|
|
|
use yii\base\Action; |
10
|
|
|
use yii\console\ExitCode; |
11
|
|
|
use yii\console\widgets\Table; |
12
|
|
|
use yii\helpers\VarDumper; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @property Oauth2DebugController $controller |
16
|
|
|
*/ |
17
|
|
|
class Oauth2DebugConfigAction extends Action |
18
|
|
|
{ |
19
|
1 |
|
public function run() |
20
|
|
|
{ |
21
|
1 |
|
$module = $this->controller->module; |
22
|
|
|
|
23
|
1 |
|
$configuration = $this->getConfiguration($module); |
24
|
|
|
|
25
|
1 |
|
$this->controller->stdout('Configuration:' . PHP_EOL); |
26
|
1 |
|
$this->controller->stdout(Table::widget([ |
27
|
1 |
|
'headers' => ['Setting', 'Value'], |
28
|
1 |
|
'rows' => array_map(fn($setting) => [$setting, $configuration[$setting]], array_keys($configuration)), |
29
|
1 |
|
])); |
30
|
|
|
|
31
|
1 |
|
$endpoints = $this->getEndpoints($module); |
32
|
|
|
|
33
|
1 |
|
$this->controller->stdout(PHP_EOL); |
34
|
1 |
|
$this->controller->stdout('Endpoints:' . PHP_EOL); |
35
|
1 |
|
$this->controller->stdout(Table::widget([ |
36
|
1 |
|
'headers' => ['Endpoint', 'URL', 'Setting(s)'], |
37
|
1 |
|
'rows' => $endpoints, |
38
|
1 |
|
])); |
39
|
|
|
|
40
|
1 |
|
return ExitCode::OK; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @param Oauth2Module $module |
45
|
|
|
* @return array |
46
|
|
|
*/ |
47
|
3 |
|
protected function getConfiguration($module) |
48
|
|
|
{ |
49
|
3 |
|
$serverRoles = []; |
50
|
3 |
|
if ($module->serverRole & Oauth2Module::SERVER_ROLE_AUTHORIZATION_SERVER) { |
51
|
2 |
|
$serverRoles[] = 'Authorization Server'; |
52
|
2 |
|
$grantTypes = array_values(array_map( |
53
|
2 |
|
fn(GrantTypeInterface $grant) => $grant->getIdentifier(), |
54
|
2 |
|
$module->getAuthorizationServer()->getEnabledGrantTypes() |
55
|
2 |
|
)); |
56
|
2 |
|
$defaultAccessTokenTTL = DateIntervalHelper::toString($module->getDefaultAccessTokenTTL()) ?? '[NOT SET]'; |
57
|
|
|
} else { |
58
|
1 |
|
$grantTypes = '-'; |
59
|
1 |
|
$defaultAccessTokenTTL = '-'; |
60
|
|
|
} |
61
|
|
|
|
62
|
3 |
|
if ($module->serverRole & Oauth2Module::SERVER_ROLE_RESOURCE_SERVER) { |
63
|
3 |
|
$serverRoles[] = 'Resource Server'; |
64
|
|
|
} |
65
|
|
|
|
66
|
3 |
|
$privateKey = $module->privateKey ? '[SET]' : '[NOT SET]'; |
67
|
3 |
|
$privateKeyPassphrase = $module->privateKeyPassphrase ? '[SET]' : '[NOT SET]'; |
68
|
3 |
|
$publicKey = $module->publicKey ? '[SET]' : '[NOT SET]'; |
69
|
3 |
|
$codesEncryptionKey = $module->codesEncryptionKey ? '[SET]' : '[NOT SET]'; |
70
|
3 |
|
$storageEncryptionKeys = $module->storageEncryptionKeys ? '[SET]' : '[NOT SET]'; |
71
|
|
|
|
72
|
3 |
|
$clientRedirectUrisEnvVarConfig = $module->clientRedirectUrisEnvVarConfig |
73
|
|
|
? VarDumper::export($module->clientRedirectUrisEnvVarConfig) |
74
|
3 |
|
: ''; |
75
|
|
|
|
76
|
3 |
|
return [ |
77
|
3 |
|
'serverRole' => $module->serverRole . ' (' . implode(', ', $serverRoles) . ')', |
78
|
|
|
|
79
|
3 |
|
'privateKey' => $privateKey, |
80
|
3 |
|
'privateKeyPassphrase' => $privateKeyPassphrase, |
81
|
3 |
|
'publicKey' => $publicKey, |
82
|
3 |
|
'codesEncryptionKey' => $codesEncryptionKey, |
83
|
3 |
|
'storageEncryptionKeys' => $storageEncryptionKeys, |
84
|
3 |
|
'defaultStorageEncryptionKey' => $module->defaultStorageEncryptionKey, |
85
|
|
|
|
86
|
3 |
|
'nonTlsAllowedRanges' => $module->nonTlsAllowedRanges, |
87
|
|
|
|
88
|
3 |
|
'clientRedirectUrisEnvVarConfig' => $clientRedirectUrisEnvVarConfig, |
89
|
|
|
|
90
|
3 |
|
'identityClass' => $module->identityClass, |
91
|
|
|
|
92
|
3 |
|
'urlRulesPrefix' => $module->urlRulesPrefix, |
93
|
3 |
|
'authorizePath' => $module->authorizePath, |
94
|
3 |
|
'accessTokenPath' => $module->accessTokenPath, |
95
|
3 |
|
'jwksPath' => $module->jwksPath, |
96
|
3 |
|
'clientAuthorizationUrl' => $module->clientAuthorizationUrl, |
97
|
3 |
|
'clientAuthorizationPath' => $module->clientAuthorizationPath, |
98
|
3 |
|
'clientAuthorizationView' => $module->clientAuthorizationView, |
99
|
3 |
|
'openIdConnectUserinfoPath' => $module->openIdConnectUserinfoPath, |
100
|
|
|
|
101
|
3 |
|
'exceptionOnInvalidScope' => $module->exceptionOnInvalidScope, |
102
|
|
|
|
103
|
3 |
|
'grantTypes' => $grantTypes, |
104
|
|
|
|
105
|
3 |
|
'defaultAccessTokenTTL' => $defaultAccessTokenTTL, |
106
|
3 |
|
'resourceServerAccessTokenRevocationValidation' => $module->resourceServerAccessTokenRevocationValidation, |
107
|
|
|
|
108
|
3 |
|
'enableOpenIdConnect' => $module->enableOpenIdConnect ? 'true' : 'false', |
109
|
3 |
|
'enableOpenIdConnectDiscovery' => $module->enableOpenIdConnectDiscovery ? 'true' : 'false', |
110
|
3 |
|
'openIdConnectProviderConfigurationInformationPath' => |
111
|
3 |
|
$module->openIdConnectProviderConfigurationInformationPath, |
112
|
3 |
|
'openIdConnectDiscoveryIncludeSupportedGrantTypes' => |
113
|
3 |
|
$module->openIdConnectDiscoveryIncludeSupportedGrantTypes ? 'true' : 'false', |
114
|
3 |
|
'openIdConnectUserinfoEndpoint' => $module->openIdConnectUserinfoEndpoint ? 'true' : 'false', |
115
|
3 |
|
'openIdConnectDiscoveryServiceDocumentationUrl' => $module->openIdConnectDiscoveryServiceDocumentationUrl, |
116
|
3 |
|
'openIdConnectIssueRefreshTokenWithoutOfflineAccessScope' => |
117
|
3 |
|
$module->openIdConnectIssueRefreshTokenWithoutOfflineAccessScope ? 'true' : 'false', |
118
|
|
|
|
119
|
3 |
|
'defaultUserAccountSelection' => $module->defaultUserAccountSelection, |
120
|
|
|
|
121
|
3 |
|
'displayConfidentialExceptionMessages' => $module->displayConfidentialExceptionMessages === null |
122
|
3 |
|
? 'null' |
123
|
3 |
|
: ($module->displayConfidentialExceptionMessages ? 'true' : 'false'), |
124
|
3 |
|
]; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* @param Oauth2Module $module |
129
|
|
|
* @return array |
130
|
|
|
*/ |
131
|
7 |
|
protected function getEndpoints($module) |
132
|
|
|
{ |
133
|
7 |
|
if ($module->serverRole & Oauth2Module::SERVER_ROLE_AUTHORIZATION_SERVER) { |
134
|
6 |
|
$authorizeClientValue = $module->urlRulesPrefix . '/' . $module->authorizePath; |
135
|
6 |
|
$authorizeClientSettings = 'urlRulesPrefix, authorizePath'; |
136
|
|
|
|
137
|
6 |
|
$accessTokenValue = $module->urlRulesPrefix . '/' . $module->accessTokenPath; |
138
|
6 |
|
$accessTokenSettings = 'urlRulesPrefix, accessTokenPath'; |
139
|
|
|
|
140
|
6 |
|
$jwksValue = $module->urlRulesPrefix . '/' . $module->jwksPath; |
141
|
6 |
|
$jwksSettings = 'urlRulesPrefix, jwksPath'; |
142
|
|
|
|
143
|
6 |
|
$clientAuthorizationValue = $module->urlRulesPrefix . '/' . $module->clientAuthorizationPath; |
144
|
6 |
|
$clientAuthorizationSettings = 'urlRulesPrefix, clientAuthorizationPath'; |
145
|
|
|
|
146
|
6 |
|
if ($module->enableOpenIdConnect) { |
147
|
5 |
|
if ($module->enableOpenIdConnectDiscovery) { |
148
|
4 |
|
$oidcProviderConfigInfoValue = $module->openIdConnectProviderConfigurationInformationPath; |
149
|
4 |
|
$oidcProviderConfigInfoSettings = 'openIdConnectProviderConfigurationInformationPath'; |
150
|
|
|
} else { |
151
|
1 |
|
$oidcProviderConfigInfoValue = '[OpenId Connect Discovery is disabled]'; |
152
|
1 |
|
$oidcProviderConfigInfoSettings = 'enableOpenIdConnectDiscovery'; |
153
|
|
|
} |
154
|
|
|
|
155
|
5 |
|
if (!empty($module->openIdConnectUserinfoEndpoint)) { |
156
|
4 |
|
if ($module->openIdConnectUserinfoEndpoint === true) { |
157
|
3 |
|
$oidcUserinfoValue = $module->urlRulesPrefix . '/' . $module->openIdConnectUserinfoPath; |
158
|
3 |
|
$oidcUserinfoSettings = 'urlRulesPrefix, openIdConnectUserinfoPath'; |
159
|
|
|
} else { |
160
|
1 |
|
$oidcUserinfoValue = $module->openIdConnectUserinfoEndpoint; |
161
|
4 |
|
$oidcUserinfoSettings = 'openIdConnectUserinfoEndpoint'; |
162
|
|
|
} |
163
|
|
|
} else { |
164
|
1 |
|
$oidcUserinfoValue = '[Userinfo Endpoint is disabled]'; |
165
|
5 |
|
$oidcUserinfoSettings = 'openIdConnectUserinfoEndpoint'; |
166
|
|
|
} |
167
|
|
|
} else { |
168
|
1 |
|
$oidcProviderConfigInfoValue = '[OpenID Connect is disabled]'; |
169
|
1 |
|
$oidcProviderConfigInfoSettings = 'enableOpenIdConnect'; |
170
|
|
|
|
171
|
1 |
|
$oidcUserinfoValue = '[OpenID Connect is disabled]'; |
172
|
6 |
|
$oidcUserinfoSettings = 'enableOpenIdConnect'; |
173
|
|
|
} |
174
|
|
|
} else { |
175
|
1 |
|
$authorizeClientValue = '[Only available for "authorization_server" role]'; |
176
|
1 |
|
$authorizeClientSettings = 'serverRole'; |
177
|
|
|
|
178
|
1 |
|
$accessTokenValue = '[Only available for "authorization_server" role]'; |
179
|
1 |
|
$accessTokenSettings = 'serverRole'; |
180
|
|
|
|
181
|
1 |
|
$jwksValue = '[Only available for "authorization_server" role]'; |
182
|
1 |
|
$jwksSettings = 'serverRole'; |
183
|
|
|
|
184
|
1 |
|
$clientAuthorizationValue = '[Only available for "authorization_server" role]'; |
185
|
1 |
|
$clientAuthorizationSettings = 'serverRole'; |
186
|
|
|
|
187
|
1 |
|
$oidcProviderConfigInfoValue = '[Only available for "authorization_server" role]'; |
188
|
1 |
|
$oidcProviderConfigInfoSettings = 'serverRole'; |
189
|
|
|
|
190
|
1 |
|
$oidcUserinfoValue = '[Only available for "authorization_server" role]'; |
191
|
1 |
|
$oidcUserinfoSettings = 'serverRole'; |
192
|
|
|
} |
193
|
|
|
|
194
|
7 |
|
return [ |
195
|
7 |
|
'authorizeClient' => ['Authorize Client', $authorizeClientValue, $authorizeClientSettings], |
196
|
7 |
|
'accessToken' => ['Access Token', $accessTokenValue, $accessTokenSettings], |
197
|
7 |
|
'jwks' => ['JSON Web Key Sets', $jwksValue, $jwksSettings], |
198
|
7 |
|
'clientAuthorization' => ['Client Authorization', $clientAuthorizationValue, $clientAuthorizationSettings], |
199
|
7 |
|
'oidcProviderConfigInfo' => [ |
200
|
7 |
|
'OpenID Connect Provider Configuration Information', |
201
|
7 |
|
$oidcProviderConfigInfoValue, |
202
|
7 |
|
$oidcProviderConfigInfoSettings, |
203
|
7 |
|
], |
204
|
7 |
|
'oidcUserinfo' => ['OpenId Connect Userinfo', $oidcUserinfoValue, $oidcUserinfoSettings], |
205
|
7 |
|
]; |
206
|
|
|
} |
207
|
|
|
} |
208
|
|
|
|