portal.mkgtu.ru/frontend/modules/api/v1/controllers/BaseController.php

34 lines
952 B
PHP
Executable File

<?php
namespace frontend\modules\api\v1\controllers;
use filsh\yii2\oauth2server\filters\auth\CompositeAuth;
use filsh\yii2\oauth2server\filters\ErrorToExceptionFilter;
use yii\filters\auth\HttpBearerAuth;
use yii\filters\auth\QueryParamAuth;
use yii\helpers\ArrayHelper;
class BaseController extends \yii\rest\ActiveController
{
public function behaviors()
{
return ArrayHelper::merge(parent::behaviors(), [
'authenticator' => [
'class' => CompositeAuth::class,
'authMethods' => [
['class' => HttpBearerAuth::class],
['class' => QueryParamAuth::class, 'tokenParam' => 'accessToken'],
]
],
'exceptionFilter' => [
'class' => ErrorToExceptionFilter::class
],
'corsFilter' => [
'class' => \yii\filters\Cors::class,
],
]);
}
}