mirror of
https://github.com/elyby/accounts.git
synced 2024-11-30 10:42:16 +05:30
Все контроллеры переведены на использование jwt токенов
This commit is contained in:
parent
601f0a290b
commit
8583edbb92
@ -4,11 +4,15 @@ namespace api\controllers;
|
|||||||
use api\models\LoginForm;
|
use api\models\LoginForm;
|
||||||
use Yii;
|
use Yii;
|
||||||
use yii\filters\AccessControl;
|
use yii\filters\AccessControl;
|
||||||
|
use yii\helpers\ArrayHelper;
|
||||||
|
|
||||||
class AuthenticationController extends Controller {
|
class AuthenticationController extends Controller {
|
||||||
|
|
||||||
public function behaviors() {
|
public function behaviors() {
|
||||||
return array_merge(parent::behaviors(), [
|
return ArrayHelper::merge(parent::behaviors(), [
|
||||||
|
'authenticator' => [
|
||||||
|
'except' => ['login'],
|
||||||
|
],
|
||||||
'access' => [
|
'access' => [
|
||||||
'class' => AccessControl::class,
|
'class' => AccessControl::class,
|
||||||
'rules' => [
|
'rules' => [
|
||||||
|
@ -3,6 +3,7 @@ namespace api\controllers;
|
|||||||
|
|
||||||
use api\traits\ApiNormalize;
|
use api\traits\ApiNormalize;
|
||||||
use Yii;
|
use Yii;
|
||||||
|
use yii\filters\auth\HttpBearerAuth;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property \common\models\Account|null $account
|
* @property \common\models\Account|null $account
|
||||||
@ -12,8 +13,15 @@ class Controller extends \yii\rest\Controller {
|
|||||||
|
|
||||||
public function behaviors() {
|
public function behaviors() {
|
||||||
$parentBehaviors = parent::behaviors();
|
$parentBehaviors = parent::behaviors();
|
||||||
|
// Добавляем авторизатор для входа по jwt токенам
|
||||||
|
$parentBehaviors['authenticator'] = [
|
||||||
|
'class' => HttpBearerAuth::className(),
|
||||||
|
];
|
||||||
|
|
||||||
// xml нам не понадобится
|
// xml нам не понадобится
|
||||||
unset($parentBehaviors['contentNegotiator']['formats']['application/xml']);
|
unset($parentBehaviors['contentNegotiator']['formats']['application/xml']);
|
||||||
|
// rate limiter здесь не применяется
|
||||||
|
unset($parentBehaviors['rateLimiter']);
|
||||||
|
|
||||||
return $parentBehaviors;
|
return $parentBehaviors;
|
||||||
}
|
}
|
||||||
|
@ -14,13 +14,17 @@ use yii\helpers\ArrayHelper;
|
|||||||
class OauthController extends Controller {
|
class OauthController extends Controller {
|
||||||
|
|
||||||
public function behaviors() {
|
public function behaviors() {
|
||||||
return array_merge(parent::behaviors(), [
|
return ArrayHelper::merge(parent::behaviors(), [
|
||||||
|
'authenticator' => [
|
||||||
|
'except' => ['validate', 'issue-token'],
|
||||||
|
],
|
||||||
'access' => [
|
'access' => [
|
||||||
'class' => AccessControl::class,
|
'class' => AccessControl::class,
|
||||||
'rules' => [
|
'rules' => [
|
||||||
[
|
[
|
||||||
'actions' => ['validate', 'issue-token'],
|
'actions' => ['validate', 'issue-token'],
|
||||||
'allow' => true,
|
'allow' => true,
|
||||||
|
'roles' => ['?'],
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'actions' => ['complete'],
|
'actions' => ['complete'],
|
||||||
|
@ -5,11 +5,15 @@ use api\models\ConfirmEmailForm;
|
|||||||
use api\models\RegistrationForm;
|
use api\models\RegistrationForm;
|
||||||
use Yii;
|
use Yii;
|
||||||
use yii\filters\AccessControl;
|
use yii\filters\AccessControl;
|
||||||
|
use yii\helpers\ArrayHelper;
|
||||||
|
|
||||||
class SignupController extends Controller {
|
class SignupController extends Controller {
|
||||||
|
|
||||||
public function behaviors() {
|
public function behaviors() {
|
||||||
return array_merge(parent::behaviors(), [
|
return ArrayHelper::merge(parent::behaviors(), [
|
||||||
|
'authenticator' => [
|
||||||
|
'except' => ['register', 'confirm'],
|
||||||
|
],
|
||||||
'access' => [
|
'access' => [
|
||||||
'class' => AccessControl::class,
|
'class' => AccessControl::class,
|
||||||
'rules' => [
|
'rules' => [
|
||||||
|
@ -11,6 +11,9 @@ class AccountSteps extends FunctionalTester {
|
|||||||
$route = new LoginRoute($I);
|
$route = new LoginRoute($I);
|
||||||
$route->login('Admin', 'password_0');
|
$route->login('Admin', 'password_0');
|
||||||
$I->canSeeResponseIsJson();
|
$I->canSeeResponseIsJson();
|
||||||
|
$I->canSeeResponseJsonMatchesJsonPath('$.jwt');
|
||||||
|
$jwt = $I->grabDataFromResponseByJsonPath('$.jwt')[0];
|
||||||
|
$I->amBearerAuthenticated($jwt);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user