Добавлен роут и логика для обновления access_token по refresh_token'у

This commit is contained in:
ErickSkrauch
2016-05-31 01:03:30 +03:00
parent cb038c897b
commit 1945a7baec
9 changed files with 258 additions and 3 deletions

View File

@@ -4,6 +4,7 @@ namespace api\controllers;
use api\models\authentication\ForgotPasswordForm;
use api\models\authentication\LoginForm;
use api\models\authentication\RecoverPasswordForm;
use api\models\authentication\RefreshTokenForm;
use common\helpers\StringHelper;
use Yii;
use yii\filters\AccessControl;
@@ -14,13 +15,13 @@ class AuthenticationController extends Controller {
public function behaviors() {
return ArrayHelper::merge(parent::behaviors(), [
'authenticator' => [
'except' => ['login', 'forgot-password', 'recover-password'],
'except' => ['login', 'forgot-password', 'recover-password', 'refresh-token'],
],
'access' => [
'class' => AccessControl::class,
'rules' => [
[
'actions' => ['login', 'forgot-password', 'recover-password'],
'actions' => ['login', 'forgot-password', 'recover-password', 'refresh-token'],
'allow' => true,
'roles' => ['?'],
],
@@ -34,6 +35,7 @@ class AuthenticationController extends Controller {
'login' => ['POST'],
'forgot-password' => ['POST'],
'recover-password' => ['POST'],
'refresh-token' => ['POST'],
];
}
@@ -109,4 +111,19 @@ class AuthenticationController extends Controller {
], $result->getAsResponse());
}
public function actionRefreshToken() {
$model = new RefreshTokenForm();
$model->load(Yii::$app->request->post());
if (($result = $model->renew()) === false) {
return [
'success' => false,
'errors' => $this->normalizeModelErrors($model->getErrors()),
];
}
return array_merge([
'success' => true,
], $result->getAsResponse());
}
}