2021-11-29 18:21:50 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace frontend\modules\api\controllers;
|
|
|
|
|
|
|
|
use common\behaviors\GsCors;
|
2022-01-14 17:05:29 +03:00
|
|
|
use yii\filters\auth\CompositeAuth;
|
|
|
|
use yii\filters\auth\HttpBearerAuth;
|
|
|
|
use yii\filters\ContentNegotiator;
|
2021-11-29 18:21:50 +03:00
|
|
|
use yii\rest\Controller;
|
2022-01-14 17:05:29 +03:00
|
|
|
use yii\web\Response;
|
2021-11-29 18:21:50 +03:00
|
|
|
|
|
|
|
class ApiController extends Controller
|
|
|
|
{
|
|
|
|
|
|
|
|
public function behaviors()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'corsFilter' => [
|
|
|
|
'class' => GsCors::class,
|
|
|
|
'cors' => [
|
|
|
|
'Origin' => ['*'],
|
|
|
|
//'Access-Control-Allow-Credentials' => true,
|
|
|
|
'Access-Control-Allow-Headers' => [
|
|
|
|
'Content-Type',
|
2023-01-12 16:00:07 +03:00
|
|
|
'Access-Control-Headers-Origin',
|
2021-11-29 18:21:50 +03:00
|
|
|
'Authorization',
|
|
|
|
'X-Requested-With'
|
|
|
|
],
|
|
|
|
]
|
|
|
|
],
|
2022-01-14 17:05:29 +03:00
|
|
|
'authenticator' => [
|
|
|
|
'class' => CompositeAuth::class,
|
|
|
|
'authMethods' => [
|
|
|
|
HttpBearerAuth::class,
|
|
|
|
],
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'class' => ContentNegotiator::className(),
|
|
|
|
'formats' => [
|
|
|
|
'application/json' => Response::FORMAT_JSON,
|
|
|
|
],
|
|
|
|
],
|
2021-11-29 18:21:50 +03:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|