1 | <?php |
||
24 | class Authorize extends Action |
||
25 | { |
||
26 | use LookupTrait; |
||
27 | |||
28 | /** |
||
29 | * @param int $id |
||
30 | * @return AbstractProvider |
||
31 | * @throws \yii\base\InvalidConfigException |
||
32 | */ |
||
33 | protected function find(int $id) |
||
39 | |||
40 | /** |
||
41 | * @inheritdoc |
||
42 | * @throws \yii\base\InvalidConfigException |
||
43 | */ |
||
44 | public function run(int $id) |
||
57 | |||
58 | /** |
||
59 | * @param AbstractProvider $provider |
||
60 | * @param array $scopes |
||
61 | * @return mixed|\yii\web\Response |
||
62 | * @throws \yii\web\HttpException |
||
63 | */ |
||
64 | protected function runInternal(AbstractProvider $provider, array $scopes) |
||
65 | { |
||
66 | $request = Craft::$app->getRequest(); |
||
67 | |||
68 | // Set redirect |
||
69 | Patron::getInstance()->getSession()->setRedirectUrl( |
||
70 | $request->getParam('redirect', $request->getReferrer()) |
||
71 | ); |
||
72 | |||
73 | // Check access |
||
74 | if (($access = $this->checkAccess($provider, $scopes)) !== true) { |
||
75 | return $access; |
||
76 | } |
||
77 | |||
78 | return $this->performAction($provider, $scopes); |
||
79 | } |
||
80 | |||
81 | /** |
||
82 | * @return array |
||
83 | */ |
||
84 | protected function getScopes(): array |
||
85 | { |
||
86 | if (!$scopes = Craft::$app->getRequest()->getParam('scope')) { |
||
87 | return []; |
||
88 | } |
||
89 | |||
90 | return $scopes; |
||
91 | } |
||
92 | |||
93 | /** |
||
94 | * @param AbstractProvider $provider |
||
95 | * @param array $scopes |
||
96 | * @return mixed |
||
97 | * @throws \yii\web\HttpException |
||
98 | */ |
||
99 | protected function performAction(AbstractProvider $provider, array $scopes) |
||
119 | } |
||
120 |