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