1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by PhpStorm. |
4
|
|
|
* User: Alexandre |
5
|
|
|
* Date: 07/01/2018 |
6
|
|
|
* Time: 13:57 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace OAuth2; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
use OAuth2\ClientAuthentication\Guard; |
13
|
|
|
use OAuth2\Endpoints\AuthorizationEndpoint; |
14
|
|
|
use OAuth2\Endpoints\TokenEndpoint; |
15
|
|
|
use OAuth2\OpenID\Repositories\ResponseModeRepository; |
16
|
|
|
use OAuth2\Providers\ResourceOwnerProviderInterface; |
17
|
|
|
use OAuth2\Repositories\ClientAuthenticatorRepository; |
18
|
|
|
use OAuth2\Repositories\ConfigurationRepository; |
19
|
|
|
use OAuth2\Repositories\GrantTypeRepository; |
20
|
|
|
use OAuth2\Repositories\ResponseTypeRepository; |
21
|
|
|
use OAuth2\Repositories\StorageRepository; |
22
|
|
|
use OAuth2\ScopePolicy\Manager; |
23
|
|
|
|
24
|
|
|
|
25
|
|
|
class Server |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* @var ConfigurationRepository |
29
|
|
|
*/ |
30
|
|
|
protected $configurationRepository; |
31
|
|
|
/** |
32
|
|
|
* @var StorageRepository |
33
|
|
|
*/ |
34
|
|
|
protected $storageRepository; |
35
|
|
|
/** |
36
|
|
|
* @var ResponseTypeRepository |
37
|
|
|
*/ |
38
|
|
|
protected $responseTypeRepository; |
39
|
|
|
/** |
40
|
|
|
* @var GrantTypeRepository |
41
|
|
|
*/ |
42
|
|
|
protected $grantTypeRepository; |
43
|
|
|
/** |
44
|
|
|
* @var ClientAuthenticatorRepository |
45
|
|
|
*/ |
46
|
|
|
protected $clientAuthenticatorRepository; |
47
|
|
|
/** |
48
|
|
|
* @var AuthorizationEndpoint |
49
|
|
|
*/ |
50
|
|
|
protected $authorizationEndpoint; |
51
|
|
|
/** |
52
|
|
|
* @var TokenEndpoint |
53
|
|
|
*/ |
54
|
|
|
protected $tokenEndpoint; |
55
|
|
|
/** |
56
|
|
|
* @var Guard |
57
|
|
|
*/ |
58
|
|
|
protected $guard; |
59
|
|
|
/** |
60
|
|
|
* @var Manager |
61
|
|
|
*/ |
62
|
|
|
protected $scopePolicyManager; |
63
|
|
|
/** |
64
|
|
|
* @var ResourceOwnerProviderInterface |
65
|
|
|
*/ |
66
|
|
|
protected $resourceOwnerProvider; |
67
|
|
|
/** |
68
|
|
|
* @var ResponseModeRepository |
69
|
|
|
*/ |
70
|
|
|
protected $responseModeRepository; |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Server constructor. |
74
|
|
|
* @param ResourceOwnerProviderInterface $resourceOwnerProvider |
75
|
|
|
* @param null|StorageRepository $storageRepository |
76
|
|
|
* @param null|ConfigurationRepository $configurationRepository |
77
|
|
|
* @param ResponseTypeRepository $responseTypeRepository |
78
|
|
|
* @param null|GrantTypeRepository $grantTypeRepository |
79
|
|
|
* @param null|ClientAuthenticatorRepository $clientAuthenticatorRepository |
80
|
|
|
* @param null|Guard $guard |
81
|
|
|
* @param null|Manager $scopePolicyManager |
82
|
|
|
* @param null|ResponseModeRepository $responseModeRepository |
83
|
|
|
* @throws \Exception |
84
|
|
|
*/ |
85
|
|
|
public function __construct(ResourceOwnerProviderInterface $resourceOwnerProvider, |
86
|
|
|
StorageRepository $storageRepository, |
87
|
|
|
ConfigurationRepository $configurationRepository = null, |
88
|
|
|
?ResponseTypeRepository $responseTypeRepository = null, |
89
|
|
|
?GrantTypeRepository $grantTypeRepository = null, |
90
|
|
|
?ClientAuthenticatorRepository $clientAuthenticatorRepository = null, |
91
|
|
|
?Guard $guard = null, |
92
|
|
|
?Manager $scopePolicyManager = null, |
93
|
|
|
?ResponseModeRepository $responseModeRepository = null) |
94
|
|
|
{ |
95
|
|
|
$this->resourceOwnerProvider = $resourceOwnerProvider; |
96
|
|
|
$this->storageRepository = $storageRepository; |
97
|
|
|
|
98
|
|
|
|
99
|
|
|
if (is_null($configurationRepository)) { |
100
|
|
|
$this->configurationRepository = new ConfigurationRepository(); |
101
|
|
|
} else { |
102
|
|
|
$this->configurationRepository = $configurationRepository; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
if (is_null($responseTypeRepository)) { |
106
|
|
|
$this->responseTypeRepository = new ResponseTypeRepository( |
107
|
|
|
ResponseTypeRepository::getDefaultResponseTypes($this)); |
108
|
|
|
} else { |
109
|
|
|
$this->responseTypeRepository = $responseTypeRepository; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
if (is_null($clientAuthenticatorRepository)) { |
113
|
|
|
$this->clientAuthenticatorRepository = new ClientAuthenticatorRepository( |
114
|
|
|
ClientAuthenticatorRepository::getDefaultAuthenticators( |
115
|
|
|
$this->configurationRepository, $this->storageRepository)); |
116
|
|
|
} else { |
117
|
|
|
$this->clientAuthenticatorRepository = $responseTypeRepository; |
|
|
|
|
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
$this->guard = $guard ? $guard : new Guard($this); |
121
|
|
|
// var_dump($this->guard);die; |
|
|
|
|
122
|
|
|
$this->scopePolicyManager = $scopePolicyManager ? $scopePolicyManager : new Manager($this); |
123
|
|
|
|
124
|
|
|
if (is_null($grantTypeRepository)) { |
125
|
|
|
$this->grantTypeRepository = new GrantTypeRepository( |
126
|
|
|
GrantTypeRepository::getDefaultGrantTypes( |
127
|
|
|
$this->configurationRepository, |
128
|
|
|
$this->resourceOwnerProvider, |
129
|
|
|
$this->scopePolicyManager, |
130
|
|
|
$this->storageRepository)); |
131
|
|
|
} else { |
132
|
|
|
$this->grantTypeRepository = $grantTypeRepository; |
133
|
|
|
} |
134
|
|
|
|
135
|
4 |
|
|
136
|
|
|
|
137
|
4 |
|
if (is_null($responseModeRepository)) { |
138
|
|
|
$this->responseModeRepository = new ResponseModeRepository( |
139
|
|
|
ResponseModeRepository::getDefaultResponseModes()); |
140
|
|
|
} else { |
141
|
|
|
$this->responseModeRepository = $responseModeRepository; |
142
|
|
|
} |
143
|
4 |
|
|
144
|
|
|
$this->authorizationEndpoint = new AuthorizationEndpoint($this); |
145
|
4 |
|
$this->tokenEndpoint = new TokenEndpoint($this); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* @return ConfigurationRepository |
150
|
|
|
*/ |
151
|
4 |
|
public function getConfigurationRepository(): ConfigurationRepository |
152
|
|
|
{ |
153
|
4 |
|
return $this->configurationRepository; |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* @return StorageRepository |
158
|
|
|
*/ |
159
|
1 |
|
public function getStorageRepository(): StorageRepository |
160
|
|
|
{ |
161
|
1 |
|
return $this->storageRepository; |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* @return ResponseTypeRepository |
166
|
|
|
*/ |
167
|
1 |
|
public function getResponseTypeRepository(): ResponseTypeRepository |
168
|
|
|
{ |
169
|
1 |
|
return $this->responseTypeRepository; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* @return GrantTypeRepository |
174
|
|
|
*/ |
175
|
4 |
|
public function getGrantTypeRepository(): GrantTypeRepository |
176
|
|
|
{ |
177
|
4 |
|
return $this->grantTypeRepository; |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* @return ClientAuthenticatorRepository |
182
|
|
|
*/ |
183
|
1 |
|
public function getClientAuthenticatorRepository(): ClientAuthenticatorRepository |
184
|
|
|
{ |
185
|
1 |
|
return $this->clientAuthenticatorRepository; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* @return AuthorizationEndpoint |
190
|
|
|
*/ |
191
|
1 |
|
public function getAuthorizationEndpoint(): AuthorizationEndpoint |
192
|
|
|
{ |
193
|
1 |
|
return $this->authorizationEndpoint; |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
/** |
197
|
|
|
* @return TokenEndpoint |
198
|
|
|
*/ |
199
|
|
|
public function getTokenEndpoint(): TokenEndpoint |
200
|
|
|
{ |
201
|
|
|
return $this->tokenEndpoint; |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
/** |
205
|
|
|
* @return Guard |
206
|
|
|
*/ |
207
|
|
|
public function getGuard(): Guard |
208
|
|
|
{ |
209
|
|
|
return $this->guard; |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
/** |
213
|
|
|
* @return bool |
214
|
|
|
* |
215
|
|
|
* @see https://tools.ietf.org/html/rfc6749#section-3.1.2.1 |
216
|
|
|
* |
217
|
|
|
* Endpoint Request Confidentiality |
218
|
|
|
* |
219
|
|
|
* The redirection endpoint SHOULD require the use of TLS as described |
220
|
|
|
* in Section 1.6 when the requested response type is "code" or "token", |
221
|
1 |
|
* or when the redirection request will result in the transmission of |
222
|
|
|
* sensitive credentials over an open network. This specification does |
223
|
1 |
|
* not mandate the use of TLS because at the time of this writing, |
224
|
|
|
* requiring clients to deploy TLS is a significant hurdle for many |
225
|
|
|
* client developers. If TLS is not available, the authorization server |
226
|
|
|
* SHOULD warn the resource owner about the insecure endpoint prior to |
227
|
|
|
* redirection (e.g., display a message during the authorization |
228
|
|
|
* request). |
229
|
3 |
|
* |
230
|
|
|
* Lack of transport-layer security can have a severe impact on the |
231
|
3 |
|
* security of the client and the protected resources it is authorized |
232
|
|
|
* to access. The use of transport-layer security is particularly |
233
|
|
|
* critical when the authorization process is used as a form of |
234
|
|
|
* delegated end-user authentication by the client (e.g., third-party |
235
|
|
|
* sign-in service). |
236
|
|
|
*/ |
237
|
|
|
public function isSecure() |
238
|
|
|
{ |
239
|
|
|
return isset($_SERVER['HTTPS']) && ('on' == strtolower($_SERVER['HTTPS']) || 1 == $_SERVER['HTTPS']); |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
/** |
243
|
|
|
* @return Manager |
244
|
|
|
*/ |
245
|
|
|
public function getScopePolicyManager(): Manager |
246
|
|
|
{ |
247
|
|
|
return $this->scopePolicyManager; |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
/** |
251
|
|
|
* @return ResourceOwnerProviderInterface |
252
|
|
|
*/ |
253
|
|
|
public function getResourceOwnerProvider(): ResourceOwnerProviderInterface |
254
|
|
|
{ |
255
|
|
|
return $this->resourceOwnerProvider; |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
/** |
259
|
|
|
* @return ResponseModeRepository |
260
|
|
|
*/ |
261
|
|
|
public function getResponseModeRepository(): ResponseModeRepository |
262
|
|
|
{ |
263
|
|
|
return $this->responseModeRepository; |
264
|
|
|
} |
265
|
|
|
} |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.