Answer the question
In order to leave comments, you need to log in
Oprions query and Bearer filter?
I'm trying to organize REST on Yii2, such a rule in config/web.php
'urlManager' => [
'class'=>'yii\web\UrlManager',
'enablePrettyUrl' => true,
'enableStrictParsing' => true,
'showScriptName' => false,
'rules' => [
'class' => 'yii\rest\UrlRule',
'controller' => 'event',
'extraPatterns' => [
'POST new' => 'new',
'OPTIONS new' => 'options',
]
],
],
class EventController extends ActiveController
{
use \app\modules\api\traits\Helpers;
public $modelClass = 'app\entities\user\User';
/**
* @return array
*/
public function behaviors():array
{
...
$behaviors['authenticator'] = [
'class' => HttpBearerAuth::class,
'except' => ['options'],
'optional' => ['options']
];
...
return $behaviors;
}
public function actionNew()
{
//... тут код экшена
}
}
public function actionOptions()
{
$this->setHeader(200);
return['message'=>'ok'];
}
{
"name": "Unauthorized",
"message": "Your request was made with invalid credentials.",
"code": 0,
"status": 401,
"type": "yii\\web\\UnauthorizedHttpException"
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question