1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by PhpStorm. |
4
|
|
|
* User: Alexandre |
5
|
|
|
* Date: 18/02/2018 |
6
|
|
|
* Time: 18:14 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace OAuth2\Extensions\OpenID\Endpoints; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
use OAuth2\Endpoints\AuthorizationRequestBuilder; |
13
|
|
|
use OAuth2\Exceptions\OAuthException; |
14
|
|
|
use OAuth2\Extensions\OpenID\IdTokenManager; |
15
|
|
|
use OAuth2\IdTokenInterface; |
16
|
|
|
use OAuth2\ResponseModes\ResponseModeManager; |
17
|
|
|
use OAuth2\AuthorizationEndpointResponseTypes\ResponseTypeManager; |
18
|
|
|
use OAuth2\Extensions\OpenID\Roles\ResourceOwnerInterface; |
|
|
|
|
19
|
|
|
use OAuth2\Roles\AuthorizationServerEndUserInterface; |
20
|
|
|
use OAuth2\ScopePolicy\ScopePolicyManager; |
21
|
|
|
use OAuth2\Storages\ClientStorageInterface; |
22
|
|
|
use Psr\Http\Message\ResponseInterface; |
23
|
|
|
|
24
|
|
|
|
25
|
|
|
class AuthorizationEndpoint extends \OAuth2\Endpoints\AuthorizationEndpoint |
26
|
|
|
{ |
27
|
|
|
const DISPLAY_PAGE = 'page'; |
28
|
|
|
const DISPLAY_POPUP = 'popup'; |
29
|
|
|
const DISPLAY_TOUCH = 'touch'; |
30
|
|
|
const DISPLAY_WAP = 'wap'; |
31
|
|
|
|
32
|
|
|
const PROMPT_NONE = 'none'; |
33
|
|
|
const PROMPT_LOGIN = 'login'; |
34
|
|
|
const PROMPT_CONSENT = 'consent'; |
35
|
|
|
const PROMPT_SELECT_ACCOUNT = 'select_account'; |
36
|
|
|
/** |
37
|
|
|
* @var string|null |
38
|
|
|
*/ |
39
|
|
|
private $nonce; |
40
|
|
|
/** |
41
|
|
|
* @var string|null |
42
|
|
|
*/ |
43
|
|
|
private $display; |
44
|
|
|
/** |
45
|
|
|
* @var string|null |
46
|
|
|
*/ |
47
|
|
|
private $prompt; |
48
|
|
|
/** |
49
|
|
|
* @var int|null |
50
|
|
|
*/ |
51
|
|
|
private $maxAge; |
52
|
|
|
/** |
53
|
|
|
* @var string[]|null |
54
|
|
|
*/ |
55
|
|
|
private $uiLocales; |
56
|
|
|
/** |
57
|
|
|
* @var IdTokenInterface|null |
58
|
|
|
*/ |
59
|
|
|
private $idTokenHint; |
60
|
|
|
/** |
61
|
|
|
* @var string|null |
62
|
|
|
*/ |
63
|
|
|
private $loginHint; |
64
|
|
|
/** |
65
|
|
|
* @var string[]|null |
66
|
|
|
*/ |
67
|
|
|
private $acrValues; |
68
|
|
|
|
69
|
|
|
public function __construct(AuthorizationRequestBuilder $authorizationRequestBuilder, |
70
|
|
|
AuthorizationServerEndUserInterface $authorizationServerEndUser) |
71
|
|
|
{ |
72
|
|
|
parent::__construct($authorizationRequestBuilder, $authorizationServerEndUser); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @return null|ResponseInterface |
77
|
|
|
* @throws OAuthException |
78
|
|
|
*/ |
79
|
|
|
protected function verifyResourceOwner(): ?ResponseInterface |
80
|
|
|
{ |
81
|
|
|
if (!$this->resourceOwner->isAuthenticated(self::PROMPT_LOGIN)) { |
|
|
|
|
82
|
|
|
if ($this->prompt == self::PROMPT_NONE) { |
83
|
|
|
throw new OAuthException('login_required'); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
// may throw interaction_required |
87
|
|
|
return $this->resourceOwner->authenticate($this->prompt == self::PROMPT_SELECT_ACCOUNT, $this->loginHint); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
if ($this->idTokenHint) { |
91
|
|
|
// check if user associated to this id token is the current user. |
92
|
|
|
// var_dump($this->idTokenHint['sub']);die; |
93
|
|
|
if ($this->idTokenHint['sub'] !== $this->resourceOwner->getIdentifier()) { |
94
|
|
|
if ($this->prompt == self::PROMPT_NONE) { |
95
|
|
|
throw new OAuthException('invalid_request'); |
96
|
|
|
} else { |
97
|
|
|
throw new OAuthException('login_required'); |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
if ($this->prompt == self::PROMPT_NONE && |
103
|
|
|
$this->resourceOwner->isInteractionRequiredForConsent($this)) { |
104
|
|
|
throw new OAuthException('interaction_required'); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
return null; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @param array $requestData |
112
|
|
|
* @return null|ResponseInterface |
113
|
|
|
* @throws OAuthException |
114
|
|
|
*/ |
115
|
|
|
protected function verifyConsent(array $requestData): ?ResponseInterface |
116
|
|
|
{ |
117
|
|
|
$consentGiven = $this->resourceOwner->hasGivenConsent($this->getClient(), $this->getScopes(), |
|
|
|
|
118
|
|
|
$this->prompt == self::PROMPT_CONSENT); |
119
|
|
|
|
120
|
|
|
if (is_null($consentGiven)) { |
121
|
|
|
if ($this->prompt == self::PROMPT_NONE) { |
122
|
|
|
throw new OAuthException('consent_required'); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
return $this->resourceOwner->obtainConsent($this, $requestData); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
if (empty($consentGiven)) { |
129
|
|
|
throw new OAuthException('access_denied', 'The resource owner denied the request.', |
130
|
|
|
'https://tools.ietf.org/html/rfc6749#section-4.1'); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
return null; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* @param array $requestData |
138
|
|
|
* @throws OAuthException |
139
|
|
|
*/ |
140
|
|
|
protected function verifyRequestData(array $requestData) |
141
|
|
|
{ |
142
|
|
|
parent::verifyRequestData($requestData); |
|
|
|
|
143
|
|
|
|
144
|
|
|
if (!in_array('openid', $this->getScopes())) { |
145
|
|
|
return; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
$this->nonce = empty($requestData['nonce']) ? null : $requestData['nonce']; |
149
|
|
|
$this->display = empty($requestData['display']) ? null : $requestData['display']; |
150
|
|
|
$this->prompt = empty($requestData['prompt']) ? null : $requestData['prompt']; |
151
|
|
|
$this->maxAge = empty($requestData['max_age']) ? null : $requestData['max_age']; |
152
|
|
|
$this->uiLocales = empty($requestData['ui_locales']) ? null : explode(' ', $requestData['ui_locales']); |
153
|
|
|
|
154
|
|
|
if (!empty($requestData['id_token_hint'])) { |
155
|
|
|
try { |
156
|
|
|
$this->idTokenHint = $this->idTokenManager->decode($requestData['id_token_hint']); |
|
|
|
|
157
|
|
|
} catch (\Exception $exception) { |
158
|
|
|
throw new OAuthException('invalid_request', 'Failed to decode id_token_hint : ' . $exception->getMessage()); |
159
|
|
|
} |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
$this->loginHint = empty($requestData['login_hint']) ? null : $requestData['login_hint']; |
163
|
|
|
$this->acrValues = empty($requestData['acr_values']) ? null : explode(' ', $requestData['acr_values']); |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* @return string|null |
168
|
|
|
*/ |
169
|
|
|
public function getNonce(): ?string |
170
|
|
|
{ |
171
|
|
|
return $this->nonce; |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* @return null|string |
176
|
|
|
*/ |
177
|
|
|
public function getDisplay(): ?string |
178
|
|
|
{ |
179
|
|
|
return $this->display; |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
/** |
183
|
|
|
* @return null|string |
184
|
|
|
*/ |
185
|
|
|
public function getPrompt(): ?string |
186
|
|
|
{ |
187
|
|
|
return $this->prompt; |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* @return int|null |
192
|
|
|
*/ |
193
|
|
|
public function getMaxAge(): ?int |
194
|
|
|
{ |
195
|
|
|
return $this->maxAge; |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* @return null|string[] |
200
|
|
|
*/ |
201
|
|
|
public function getUiLocales(): ?array |
202
|
|
|
{ |
203
|
|
|
return $this->uiLocales; |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* @return null|IdTokenInterface |
208
|
|
|
*/ |
209
|
|
|
public function getIdTokenHint(): ?IdTokenInterface |
210
|
|
|
{ |
211
|
|
|
return $this->idTokenHint; |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
/** |
215
|
|
|
* @return null|string |
216
|
|
|
*/ |
217
|
|
|
public function getLoginHint(): ?string |
218
|
|
|
{ |
219
|
|
|
return $this->loginHint; |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
/** |
223
|
|
|
* @return null|string[] |
224
|
|
|
*/ |
225
|
|
|
public function getAcrValues(): ?array |
226
|
|
|
{ |
227
|
|
|
return $this->acrValues; |
228
|
|
|
} |
229
|
|
|
} |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths