S
S
Sergey Beloventsev2018-10-18 21:22:18
Yii
Sergey Beloventsev, 2018-10-18 21:22:18

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',
                        ]
           ],
],

This is how the controller set up
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'];
    }

I make an options request for actionNew and I get an error
{
"name": "Unauthorized",
"message": "Your request was made with invalid credentials.",
"code": 0,
"status": 401,
"type": "yii\\web\\UnauthorizedHttpException"
}

why and what am I doing wrong?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question