2016-02-14 23:20:10 +05:30
|
|
|
<?php
|
|
|
|
namespace api\controllers;
|
|
|
|
|
2016-08-07 05:38:48 +05:30
|
|
|
use api\filters\ActiveUserRule;
|
2017-06-12 17:06:20 +05:30
|
|
|
use api\models\OauthProcess;
|
2016-02-14 23:20:10 +05:30
|
|
|
use Yii;
|
|
|
|
use yii\filters\AccessControl;
|
|
|
|
use yii\helpers\ArrayHelper;
|
|
|
|
|
|
|
|
class OauthController extends Controller {
|
|
|
|
|
2017-06-12 17:06:20 +05:30
|
|
|
public function behaviors(): array {
|
2016-02-24 03:45:04 +05:30
|
|
|
return ArrayHelper::merge(parent::behaviors(), [
|
|
|
|
'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' => [
|
|
|
|
[
|
2016-08-07 05:38:48 +05:30
|
|
|
'class' => ActiveUserRule::class,
|
2016-02-14 23:20:10 +05:30
|
|
|
'actions' => ['complete'],
|
|
|
|
],
|
|
|
|
],
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
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'],
|
|
|
|
'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 {
|
|
|
|
return new OauthProcess(Yii::$app->oauth->authServer);
|
2016-08-18 03:27:01 +05:30
|
|
|
}
|
|
|
|
|
2016-02-14 23:20:10 +05:30
|
|
|
}
|