|
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
|
3 |
|
'openIdConnectEndSessionPath' => $module->openIdConnectEndSessionPath, |
|
101
|
|
|
|
|
102
|
3 |
|
'exceptionOnInvalidScope' => $module->exceptionOnInvalidScope, |
|
103
|
|
|
|
|
104
|
3 |
|
'grantTypes' => $grantTypes, |
|
105
|
|
|
|
|
106
|
3 |
|
'defaultAccessTokenTTL' => $defaultAccessTokenTTL, |
|
107
|
3 |
|
'resourceServerAccessTokenRevocationValidation' => $module->resourceServerAccessTokenRevocationValidation, |
|
108
|
|
|
|
|
109
|
3 |
|
'enableOpenIdConnect' => $module->enableOpenIdConnect ? 'true' : 'false', |
|
110
|
3 |
|
'enableOpenIdConnectDiscovery' => $module->enableOpenIdConnectDiscovery ? 'true' : 'false', |
|
111
|
3 |
|
'openIdConnectProviderConfigurationInformationPath' => |
|
112
|
3 |
|
$module->openIdConnectProviderConfigurationInformationPath, |
|
113
|
3 |
|
'openIdConnectDiscoveryIncludeSupportedGrantTypes' => |
|
114
|
3 |
|
$module->openIdConnectDiscoveryIncludeSupportedGrantTypes ? 'true' : 'false', |
|
115
|
3 |
|
'openIdConnectUserinfoEndpoint' => $module->openIdConnectUserinfoEndpoint ? 'true' : 'false', |
|
116
|
3 |
|
'openIdConnectEndSessionEndpoint' => $module->openIdConnectEndSessionEndpoint ? 'true' : 'false', |
|
117
|
3 |
|
'openIdConnectAllowAnonymousEndSession' => $module->openIdConnectAllowAnonymousEndSession ? 'true' : 'false', |
|
118
|
3 |
|
'openIdConnectDiscoveryServiceDocumentationUrl' => $module->openIdConnectDiscoveryServiceDocumentationUrl, |
|
119
|
3 |
|
'openIdConnectIssueRefreshTokenWithoutOfflineAccessScope' => |
|
120
|
3 |
|
$module->openIdConnectIssueRefreshTokenWithoutOfflineAccessScope ? 'true' : 'false', |
|
121
|
|
|
|
|
122
|
3 |
|
'defaultUserAccountSelection' => $module->defaultUserAccountSelection, |
|
123
|
|
|
|
|
124
|
3 |
|
'displayConfidentialExceptionMessages' => $module->displayConfidentialExceptionMessages === null |
|
125
|
3 |
|
? 'null' |
|
126
|
3 |
|
: ($module->displayConfidentialExceptionMessages ? 'true' : 'false'), |
|
127
|
3 |
|
]; |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* @param Oauth2Module $module |
|
132
|
|
|
* @return array |
|
133
|
|
|
*/ |
|
134
|
7 |
|
protected function getEndpoints($module) |
|
135
|
|
|
{ |
|
136
|
7 |
|
if ($module->serverRole & Oauth2Module::SERVER_ROLE_AUTHORIZATION_SERVER) { |
|
137
|
6 |
|
$authorizeClientValue = $module->urlRulesPrefix . '/' . $module->authorizePath; |
|
138
|
6 |
|
$authorizeClientSettings = 'urlRulesPrefix, authorizePath'; |
|
139
|
|
|
|
|
140
|
6 |
|
$accessTokenValue = $module->urlRulesPrefix . '/' . $module->accessTokenPath; |
|
141
|
6 |
|
$accessTokenSettings = 'urlRulesPrefix, accessTokenPath'; |
|
142
|
|
|
|
|
143
|
6 |
|
$jwksValue = $module->urlRulesPrefix . '/' . $module->jwksPath; |
|
144
|
6 |
|
$jwksSettings = 'urlRulesPrefix, jwksPath'; |
|
145
|
|
|
|
|
146
|
6 |
|
$clientAuthorizationValue = $module->urlRulesPrefix . '/' . $module->clientAuthorizationPath; |
|
147
|
6 |
|
$clientAuthorizationSettings = 'urlRulesPrefix, clientAuthorizationPath'; |
|
148
|
|
|
|
|
149
|
6 |
|
if ($module->enableOpenIdConnect) { |
|
150
|
5 |
|
if ($module->enableOpenIdConnectDiscovery) { |
|
151
|
4 |
|
$oidcProviderConfigInfoValue = $module->openIdConnectProviderConfigurationInformationPath; |
|
152
|
4 |
|
$oidcProviderConfigInfoSettings = 'openIdConnectProviderConfigurationInformationPath'; |
|
153
|
|
|
} else { |
|
154
|
1 |
|
$oidcProviderConfigInfoValue = '[OpenId Connect Discovery is disabled]'; |
|
155
|
1 |
|
$oidcProviderConfigInfoSettings = 'enableOpenIdConnectDiscovery'; |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
5 |
|
if (!empty($module->openIdConnectUserinfoEndpoint)) { |
|
159
|
4 |
|
if ($module->openIdConnectUserinfoEndpoint === true) { |
|
160
|
3 |
|
$oidcUserinfoValue = $module->urlRulesPrefix . '/' . $module->openIdConnectUserinfoPath; |
|
161
|
3 |
|
$oidcUserinfoSettings = 'urlRulesPrefix, openIdConnectUserinfoPath'; |
|
162
|
|
|
} else { |
|
163
|
1 |
|
$oidcUserinfoValue = $module->openIdConnectUserinfoEndpoint; |
|
164
|
4 |
|
$oidcUserinfoSettings = 'openIdConnectUserinfoEndpoint'; |
|
165
|
|
|
} |
|
166
|
|
|
} else { |
|
167
|
1 |
|
$oidcUserinfoValue = '[Userinfo Endpoint is disabled]'; |
|
168
|
5 |
|
$oidcUserinfoSettings = 'openIdConnectUserinfoEndpoint'; |
|
169
|
|
|
} |
|
170
|
|
|
} else { |
|
171
|
1 |
|
$oidcProviderConfigInfoValue = '[OpenID Connect is disabled]'; |
|
172
|
1 |
|
$oidcProviderConfigInfoSettings = 'enableOpenIdConnect'; |
|
173
|
|
|
|
|
174
|
1 |
|
$oidcUserinfoValue = '[OpenID Connect is disabled]'; |
|
175
|
6 |
|
$oidcUserinfoSettings = 'enableOpenIdConnect'; |
|
176
|
|
|
} |
|
177
|
|
|
} else { |
|
178
|
1 |
|
$authorizeClientValue = '[Only available for "authorization_server" role]'; |
|
179
|
1 |
|
$authorizeClientSettings = 'serverRole'; |
|
180
|
|
|
|
|
181
|
1 |
|
$accessTokenValue = '[Only available for "authorization_server" role]'; |
|
182
|
1 |
|
$accessTokenSettings = 'serverRole'; |
|
183
|
|
|
|
|
184
|
1 |
|
$jwksValue = '[Only available for "authorization_server" role]'; |
|
185
|
1 |
|
$jwksSettings = 'serverRole'; |
|
186
|
|
|
|
|
187
|
1 |
|
$clientAuthorizationValue = '[Only available for "authorization_server" role]'; |
|
188
|
1 |
|
$clientAuthorizationSettings = 'serverRole'; |
|
189
|
|
|
|
|
190
|
1 |
|
$oidcProviderConfigInfoValue = '[Only available for "authorization_server" role]'; |
|
191
|
1 |
|
$oidcProviderConfigInfoSettings = 'serverRole'; |
|
192
|
|
|
|
|
193
|
1 |
|
$oidcUserinfoValue = '[Only available for "authorization_server" role]'; |
|
194
|
1 |
|
$oidcUserinfoSettings = 'serverRole'; |
|
195
|
|
|
} |
|
196
|
|
|
|
|
197
|
7 |
|
return [ |
|
198
|
7 |
|
'authorizeClient' => ['Authorize Client', $authorizeClientValue, $authorizeClientSettings], |
|
199
|
7 |
|
'accessToken' => ['Access Token', $accessTokenValue, $accessTokenSettings], |
|
200
|
7 |
|
'jwks' => ['JSON Web Key Sets', $jwksValue, $jwksSettings], |
|
201
|
7 |
|
'clientAuthorization' => ['Client Authorization', $clientAuthorizationValue, $clientAuthorizationSettings], |
|
202
|
7 |
|
'oidcProviderConfigInfo' => [ |
|
203
|
7 |
|
'OpenID Connect Provider Configuration Information', |
|
204
|
7 |
|
$oidcProviderConfigInfoValue, |
|
205
|
7 |
|
$oidcProviderConfigInfoSettings, |
|
206
|
7 |
|
], |
|
207
|
7 |
|
'oidcUserinfo' => ['OpenId Connect Userinfo', $oidcUserinfoValue, $oidcUserinfoSettings], |
|
208
|
7 |
|
]; |
|
209
|
|
|
} |
|
210
|
|
|
} |
|
211
|
|
|
|