1 | <?php |
||
28 | class Callback extends Action |
||
29 | { |
||
30 | use LookupTrait; |
||
31 | |||
32 | /** |
||
33 | * @inheritdoc |
||
34 | * @throws \yii\base\InvalidConfigException |
||
35 | */ |
||
36 | 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 AbstractProvider $provider |
||
76 | * @return AccessToken|mixed |
||
77 | * @throws HttpException |
||
78 | */ |
||
79 | public function runInternal( |
||
80 | $code, |
||
81 | AbstractProvider $provider |
||
82 | ) { |
||
83 | if (($access = $this->checkAccess($provider)) !== true) { |
||
84 | return $access; |
||
85 | } |
||
86 | |||
87 | return $this->performAction($code, $provider); |
||
88 | } |
||
89 | |||
90 | /** |
||
91 | * @param $code |
||
92 | * @param AbstractProvider $provider |
||
93 | * @return AccessToken |
||
94 | * @throws HttpException |
||
95 | */ |
||
96 | public function performAction( |
||
120 | |||
121 | /** |
||
122 | * @param AccessTokenInterface $accessToken |
||
123 | * @param AbstractProvider $provider |
||
124 | * @return bool |
||
125 | * @throws \Exception |
||
126 | */ |
||
127 | protected function persistNewToken( |
||
169 | |||
170 | /** |
||
171 | * @param string|null $state |
||
172 | * @return bool |
||
173 | */ |
||
174 | protected function isValidState(string $state = null): bool |
||
181 | |||
182 | /** |
||
183 | * @param string|null $url |
||
184 | * @return string |
||
185 | */ |
||
186 | protected function resolveRedirectUrl(string $url = null) |
||
194 | |||
195 | |||
196 | /******************************************* |
||
197 | * INVALID STATE RESPONSE |
||
198 | *******************************************/ |
||
199 | |||
200 | /** |
||
201 | * @param string|null $state |
||
202 | * @throws HttpException |
||
203 | */ |
||
204 | protected function handleInvalidStateResponse(string $state = null) |
||
219 | |||
220 | /** |
||
221 | * @return string |
||
222 | */ |
||
223 | protected function messageInvalidState(): string |
||
224 | { |
||
225 | return Craft::t('patron', 'Invalid state.'); |
||
226 | } |
||
227 | |||
228 | /** |
||
229 | * HTTP not found response code |
||
230 | * |
||
231 | * @return int |
||
232 | */ |
||
233 | protected function statusCodeInvalidState(): int |
||
234 | { |
||
235 | return 404; |
||
236 | } |
||
237 | |||
238 | |||
239 | /******************************************* |
||
240 | * USER NOT FOUND RESPONSE |
||
241 | *******************************************/ |
||
242 | |||
243 | /** |
||
244 | * @throws HttpException |
||
245 | */ |
||
246 | protected function handleUserNotFoundResponse() |
||
247 | { |
||
248 | throw new HttpException( |
||
249 | $this->statusCodeUserNotFound(), |
||
250 | $this->messageUserNotFound() |
||
251 | ); |
||
252 | } |
||
253 | |||
254 | /** |
||
255 | * @return string |
||
256 | */ |
||
257 | protected function messageUserNotFound(): string |
||
258 | { |
||
259 | return Craft::t('patron', 'Unable to find user.'); |
||
260 | } |
||
261 | |||
262 | /** |
||
263 | * HTTP not found response code |
||
264 | * |
||
265 | * @return int |
||
266 | */ |
||
267 | protected function statusCodeUserNotFound(): int |
||
268 | { |
||
269 | return 404; |
||
270 | } |
||
271 | |||
272 | |||
273 | /******************************************* |
||
274 | * INVALID CODE RESPONSE |
||
275 | *******************************************/ |
||
276 | |||
277 | /** |
||
278 | * @throws HttpException |
||
279 | */ |
||
280 | protected function handleInvalidCodeResponse() |
||
287 | |||
288 | /** |
||
289 | * @return string |
||
290 | */ |
||
291 | protected function messageInvalidCode(): string |
||
292 | { |
||
293 | return Craft::t('patron', 'Invalid code.'); |
||
295 | |||
296 | /** |
||
297 | * HTTP not found response code |
||
298 | * |
||
299 | * @return int |
||
300 | */ |
||
301 | protected function statusCodeInvalidCode(): int |
||
305 | } |
||
306 |