2016-02-14 23:20:10 +05:30
|
|
|
<?php
|
2019-08-23 13:58:04 +05:30
|
|
|
declare(strict_types=1);
|
|
|
|
|
2018-02-28 03:57:35 +05:30
|
|
|
namespace api\modules\oauth\controllers;
|
2016-02-14 23:20:10 +05:30
|
|
|
|
2018-02-28 03:57:35 +05:30
|
|
|
use api\controllers\Controller;
|
|
|
|
use api\modules\oauth\models\OauthProcess;
|
2019-08-02 05:59:20 +05:30
|
|
|
use api\rbac\Permissions as P;
|
2016-02-14 23:20:10 +05:30
|
|
|
use Yii;
|
|
|
|
use yii\filters\AccessControl;
|
|
|
|
use yii\helpers\ArrayHelper;
|
|
|
|
|
2018-02-28 03:57:35 +05:30
|
|
|
class AuthorizationController extends Controller {
|
2016-02-14 23:20:10 +05:30
|
|
|
|
2017-06-12 17:06:20 +05:30
|
|
|
public function behaviors(): array {
|
2018-02-28 03:57:35 +05:30
|
|
|
return ArrayHelper::merge(Controller::behaviors(), [
|
2016-02-24 03:45:04 +05:30
|
|
|
'authenticator' => [
|
2016-12-12 02:37:39 +05:30
|
|
|
'only' => ['complete'],
|
2016-02-24 03:45:04 +05:30
|
|
|
],
|
2016-02-14 23:20:10 +05:30
|
|
|
'access' => [
|
|
|
|
'class' => AccessControl::class,
|
2016-12-12 02:37:39 +05:30
|
|
|
'only' => ['complete'],
|
2016-02-14 23:20:10 +05:30
|
|
|
'rules' => [
|
|
|
|
[
|
2017-09-19 22:36:16 +05:30
|
|
|
'allow' => true,
|
2016-02-14 23:20:10 +05:30
|
|
|
'actions' => ['complete'],
|
2017-09-19 22:36:16 +05:30
|
|
|
'roles' => [P::COMPLETE_OAUTH_FLOW],
|
|
|
|
'roleParams' => function() {
|
|
|
|
return [
|
|
|
|
'accountId' => Yii::$app->user->identity->getAccount()->id,
|
|
|
|
];
|
|
|
|
},
|
2016-02-14 23:20:10 +05:30
|
|
|
],
|
|
|
|
],
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2017-06-12 17:06:20 +05:30
|
|
|
public function verbs(): array {
|
2016-02-14 23:20:10 +05:30
|
|
|
return [
|
2016-07-27 03:41:13 +05:30
|
|
|
'validate' => ['GET'],
|
|
|
|
'complete' => ['POST'],
|
2018-04-18 02:17:25 +05:30
|
|
|
'token' => ['POST'],
|
2016-02-14 23:20:10 +05:30
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2017-06-12 17:06:20 +05:30
|
|
|
public function actionValidate(): array {
|
|
|
|
return $this->createOauthProcess()->validate();
|
2016-02-23 03:19:46 +05:30
|
|
|
}
|
|
|
|
|
2017-06-12 17:06:20 +05:30
|
|
|
public function actionComplete(): array {
|
|
|
|
return $this->createOauthProcess()->complete();
|
2016-02-14 23:20:10 +05:30
|
|
|
}
|
|
|
|
|
2017-06-12 17:06:20 +05:30
|
|
|
public function actionToken(): array {
|
|
|
|
return $this->createOauthProcess()->getToken();
|
2016-08-18 03:27:01 +05:30
|
|
|
}
|
|
|
|
|
2017-06-12 17:06:20 +05:30
|
|
|
private function createOauthProcess(): OauthProcess {
|
2019-09-22 05:12:08 +05:30
|
|
|
return new OauthProcess(Yii::$app->oauth->getAuthServer());
|
2016-08-18 03:27:01 +05:30
|
|
|
}
|
|
|
|
|
2016-02-14 23:20:10 +05:30
|
|
|
}
|