1 | <?php |
||
27 | class Callback extends Action |
||
28 | { |
||
29 | use LookupTrait; |
||
30 | |||
31 | /** |
||
32 | * @inheritdoc |
||
33 | */ |
||
34 | public function run() |
||
60 | |||
61 | /** |
||
62 | * @param int $id |
||
63 | * @return AbstractProvider |
||
64 | * @throws \yii\base\InvalidConfigException |
||
65 | */ |
||
66 | protected function find(int $id) |
||
72 | |||
73 | /** |
||
74 | * @param $code |
||
75 | * @param $identifier |
||
76 | * @param AbstractProvider $provider |
||
77 | * @return AccessToken|mixed |
||
78 | * @throws HttpException |
||
79 | */ |
||
80 | public function runInternal( |
||
81 | $code, |
||
82 | AbstractProvider $provider |
||
83 | ) { |
||
84 | if (($access = $this->checkAccess($provider)) !== true) { |
||
85 | return $access; |
||
86 | } |
||
87 | |||
88 | return $this->performAction($code, $provider); |
||
89 | } |
||
90 | |||
91 | /** |
||
92 | * @param $code |
||
93 | * @param AbstractProvider $provider |
||
94 | * @return AccessToken |
||
95 | * @throws HttpException |
||
96 | */ |
||
97 | public function performAction( |
||
121 | |||
122 | /** |
||
123 | * @param AccessToken $accessToken |
||
124 | * @param AbstractProvider $provider |
||
125 | * @return bool |
||
126 | * @throws \Exception |
||
127 | */ |
||
128 | protected function persistNewToken( |
||
170 | |||
171 | /** |
||
172 | * @param string|null $state |
||
173 | * @return bool |
||
174 | */ |
||
175 | protected function isValidState(string $state = null): bool |
||
182 | |||
183 | /** |
||
184 | * @param string|null $url |
||
185 | * @return string |
||
186 | */ |
||
187 | protected function resolveRedirectUrl(string $url = null) |
||
195 | |||
196 | |||
197 | /******************************************* |
||
198 | * INVALID STATE RESPONSE |
||
199 | *******************************************/ |
||
200 | |||
201 | /** |
||
202 | * @param string|null $state |
||
203 | * @throws HttpException |
||
204 | */ |
||
205 | protected function handleInvalidStateResponse(string $state = null) |
||
220 | |||
221 | /** |
||
222 | * @return string |
||
223 | */ |
||
224 | protected function messageInvalidState(): string |
||
225 | { |
||
226 | return Craft::t('patron', 'Invalid state.'); |
||
227 | } |
||
228 | |||
229 | /** |
||
230 | * HTTP not found response code |
||
231 | * |
||
232 | * @return int |
||
233 | */ |
||
234 | protected function statusCodeInvalidState(): int |
||
235 | { |
||
236 | return 404; |
||
237 | } |
||
238 | |||
239 | |||
240 | /******************************************* |
||
241 | * USER NOT FOUND RESPONSE |
||
242 | *******************************************/ |
||
243 | |||
244 | /** |
||
245 | * @throws HttpException |
||
246 | */ |
||
247 | protected function handleUserNotFoundResponse() |
||
248 | { |
||
249 | throw new HttpException( |
||
250 | $this->statusCodeUserNotFound(), |
||
251 | $this->messageUserNotFound() |
||
252 | ); |
||
253 | } |
||
254 | |||
255 | /** |
||
256 | * @return string |
||
257 | */ |
||
258 | protected function messageUserNotFound(): string |
||
259 | { |
||
260 | return Craft::t('patron', 'Unable to find user.'); |
||
261 | } |
||
262 | |||
263 | /** |
||
264 | * HTTP not found response code |
||
265 | * |
||
266 | * @return int |
||
267 | */ |
||
268 | protected function statusCodeUserNotFound(): int |
||
269 | { |
||
270 | return 404; |
||
271 | } |
||
272 | |||
273 | |||
274 | /******************************************* |
||
275 | * INVALID CODE RESPONSE |
||
276 | *******************************************/ |
||
277 | |||
278 | /** |
||
279 | * @throws HttpException |
||
280 | */ |
||
281 | protected function handleInvalidCodeResponse() |
||
288 | |||
289 | /** |
||
290 | * @return string |
||
291 | */ |
||
292 | protected function messageInvalidCode(): string |
||
293 | { |
||
294 | return Craft::t('patron', 'Invalid code.'); |
||
295 | } |
||
296 | |||
297 | /** |
||
298 | * HTTP not found response code |
||
299 | * |
||
300 | * @return int |
||
301 | */ |
||
302 | protected function statusCodeInvalidCode(): int |
||
303 | { |
||
304 | return 404; |
||
305 | } |
||
306 | } |
||
307 |
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.