1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace rhertogh\Yii2Oauth2Server\components\authorization\client\base; |
4
|
|
|
|
5
|
|
|
use rhertogh\Yii2Oauth2Server\components\authorization\base\Oauth2BaseAuthorizationRequest; |
6
|
|
|
use rhertogh\Yii2Oauth2Server\interfaces\components\authorization\client\Oauth2ClientAuthorizationRequestInterface; |
7
|
|
|
use yii\base\InvalidArgumentException; |
8
|
|
|
use yii\base\InvalidCallException; |
9
|
|
|
use yii\web\ForbiddenHttpException; |
10
|
|
|
|
11
|
|
|
abstract class Oauth2BaseClientAuthorizationRequest extends Oauth2BaseAuthorizationRequest implements Oauth2ClientAuthorizationRequestInterface |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var string|null |
15
|
|
|
*/ |
16
|
|
|
public $_authorizeUrl = null; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var string|null |
20
|
|
|
*/ |
21
|
|
|
protected $_state = null; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var string|null |
25
|
|
|
*/ |
26
|
|
|
public $_grantType = null; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var string[] |
30
|
|
|
*/ |
31
|
|
|
public $_prompts = []; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var int|null |
35
|
|
|
*/ |
36
|
|
|
public $_maxAge = null; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var string[] |
40
|
|
|
*/ |
41
|
|
|
public $_requestedScopeIdentifiers = []; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @var string[] |
45
|
|
|
*/ |
46
|
|
|
public $_selectedScopeIdentifiers = []; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @var bool |
50
|
|
|
*/ |
51
|
|
|
protected $_userAuthenticatedBeforeRequest = false; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @var bool |
55
|
|
|
*/ |
56
|
|
|
protected $_authenticatedDuringRequest = false; |
57
|
|
|
|
58
|
1 |
|
public function __serialize() |
59
|
|
|
{ |
60
|
1 |
|
return array_merge(parent::__serialize(), [ |
61
|
1 |
|
'_authorizeUrl' => $this->_authorizeUrl, |
62
|
1 |
|
'_state' => $this->_state, |
63
|
1 |
|
'_grantType' => $this->_grantType, |
64
|
1 |
|
'_prompts' => $this->_prompts, |
65
|
1 |
|
'_maxAge' => $this->_maxAge, |
66
|
1 |
|
'_requestedScopeIdentifiers' => $this->_requestedScopeIdentifiers, |
67
|
1 |
|
'_selectedScopeIdentifiers' => $this->_selectedScopeIdentifiers, |
68
|
1 |
|
'_userAuthenticatedBeforeRequest' => $this->_userAuthenticatedBeforeRequest, |
69
|
1 |
|
'_authenticatedDuringRequest' => $this->_authenticatedDuringRequest, |
70
|
1 |
|
]); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @inheritDoc |
75
|
|
|
*/ |
76
|
4 |
|
public function getClient() |
77
|
|
|
{ |
78
|
4 |
|
$clientIdentifier = $this->getClientIdentifier(); |
79
|
4 |
|
if (empty($clientIdentifier)) { |
80
|
1 |
|
throw new InvalidCallException('Client identifier must be set.'); |
81
|
|
|
} |
82
|
3 |
|
if (empty($this->_client) || $this->_client->getIdentifier() != $clientIdentifier) { |
83
|
3 |
|
$this->_client = $this->getModule()->getClientRepository()->getClientEntity($clientIdentifier); |
84
|
3 |
|
if (!$this->_client || !$this->_client->isEnabled()) { |
|
|
|
|
85
|
|
|
throw new ForbiddenHttpException('Client "' . $clientIdentifier . '" not found or disabled.'); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
89
|
3 |
|
return $this->_client; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @inheritDoc |
94
|
|
|
*/ |
95
|
|
|
public function setClient($client) |
96
|
|
|
{ |
97
|
|
|
if (empty($client)) { |
98
|
|
|
throw new InvalidArgumentException('Client is required for Client Authorization Request.'); |
99
|
|
|
} |
100
|
|
|
return parent::setClient($client); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @inheritDoc |
105
|
|
|
*/ |
106
|
1 |
|
public function getAuthorizeUrl() |
107
|
|
|
{ |
108
|
1 |
|
return $this->_authorizeUrl; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @inheritDoc |
113
|
|
|
*/ |
114
|
4 |
|
public function setAuthorizeUrl($authorizeUrl) |
115
|
|
|
{ |
116
|
4 |
|
$this->_authorizeUrl = $authorizeUrl; |
117
|
4 |
|
$this->setCompleted(false); |
118
|
4 |
|
return $this; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @inheritDoc |
123
|
|
|
*/ |
124
|
|
|
public function getState() |
125
|
|
|
{ |
126
|
|
|
return $this->_state; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @inheritDoc |
131
|
|
|
*/ |
132
|
3 |
|
public function setState($state) |
133
|
|
|
{ |
134
|
3 |
|
$this->_state = $state; |
135
|
3 |
|
return $this; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* @inheritDoc |
140
|
|
|
*/ |
141
|
4 |
|
public function getGrantType() |
142
|
|
|
{ |
143
|
4 |
|
return $this->_grantType; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* @inheritDoc |
148
|
|
|
*/ |
149
|
4 |
|
public function setGrantType($grantType) |
150
|
|
|
{ |
151
|
4 |
|
$this->_grantType = $grantType; |
152
|
4 |
|
$this->setCompleted(false); |
153
|
4 |
|
return $this; |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* @inheritDoc |
158
|
|
|
*/ |
159
|
4 |
|
public function getPrompts() |
160
|
|
|
{ |
161
|
4 |
|
return $this->_prompts; |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* @inheritDoc |
166
|
|
|
*/ |
167
|
4 |
|
public function setPrompts($prompts) |
168
|
|
|
{ |
169
|
4 |
|
$this->_prompts = $prompts; |
170
|
4 |
|
return $this; |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* @inheritDoc |
175
|
|
|
*/ |
176
|
4 |
|
public function getMaxAge() |
177
|
|
|
{ |
178
|
4 |
|
return $this->_maxAge; |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* @inheritDoc |
183
|
|
|
*/ |
184
|
4 |
|
public function setMaxAge($maxAge) |
185
|
|
|
{ |
186
|
4 |
|
$this->_maxAge = $maxAge; |
187
|
4 |
|
return $this; |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* @inheritDoc |
192
|
|
|
*/ |
193
|
4 |
|
public function getRequestedScopeIdentifiers() |
194
|
|
|
{ |
195
|
4 |
|
return $this->_requestedScopeIdentifiers; |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* @inheritDoc |
200
|
|
|
*/ |
201
|
4 |
|
public function setRequestedScopeIdentifiers($requestedScopeIdentifiers) |
202
|
|
|
{ |
203
|
4 |
|
$this->_requestedScopeIdentifiers = $requestedScopeIdentifiers; |
204
|
4 |
|
$this->setCompleted(false); |
205
|
4 |
|
return $this; |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
/** |
209
|
|
|
* @inheritDoc |
210
|
|
|
*/ |
211
|
3 |
|
public function getSelectedScopeIdentifiers() |
212
|
|
|
{ |
213
|
3 |
|
return $this->_selectedScopeIdentifiers; |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
/** |
217
|
|
|
* @inheritDoc |
218
|
|
|
*/ |
219
|
1 |
|
public function setSelectedScopeIdentifiers($selectedScopeIdentifiers) |
220
|
|
|
{ |
221
|
1 |
|
$this->_selectedScopeIdentifiers = $selectedScopeIdentifiers; |
222
|
1 |
|
$this->setCompleted(false); |
223
|
1 |
|
return $this; |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
/** |
227
|
|
|
* @inheritDoc |
228
|
|
|
*/ |
229
|
3 |
|
public function setUserAuthenticatedBeforeRequest($authenticatedBeforeRequest) |
230
|
|
|
{ |
231
|
3 |
|
$this->_userAuthenticatedBeforeRequest = $authenticatedBeforeRequest; |
232
|
3 |
|
return $this; |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
/** |
236
|
|
|
* @inheritDoc |
237
|
|
|
*/ |
238
|
|
|
public function wasUserAuthenticatedBeforeRequest() |
239
|
|
|
{ |
240
|
|
|
return $this->_userAuthenticatedBeforeRequest; |
241
|
|
|
} |
242
|
|
|
|
243
|
|
|
/** |
244
|
|
|
* @inheritDoc |
245
|
|
|
*/ |
246
|
|
|
public function setUserAuthenticatedDuringRequest($authenticatedDuringRequest) |
247
|
|
|
{ |
248
|
|
|
$this->_authenticatedDuringRequest = $authenticatedDuringRequest; |
249
|
|
|
return $this; |
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
/** |
253
|
|
|
* @inheritDoc |
254
|
|
|
*/ |
255
|
3 |
|
public function wasUserAthenticatedDuringRequest() |
256
|
|
|
{ |
257
|
3 |
|
return $this->_authenticatedDuringRequest; |
258
|
|
|
} |
259
|
|
|
} |
260
|
|
|
|