Authenticator закрывает доступ ко всем экшенам

Всё что касается построения API
Ответить
maxtor
Сообщения: 78
Зарегистрирован: 2011.12.06, 11:04

Authenticator закрывает доступ ко всем экшенам

Сообщение maxtor »

Код: Выделить всё

class UserController extends \yii\rest\Controller
{

    public function behaviors()
    {
        $behaviors = parent::behaviors();

        $behaviors['authenticator'] = [
            'class' => HttpBearerAuth::className(),
        ];

        $behaviors['access'] = [
            'class' => AccessControl::className(),
            'rules' => [
                [
                    'actions' => ['index'],
                    'allow' => true,
                    'roles' => ['*'],
                ],
            ],
        ];

        return $behaviors;
    }

    public function actionIndex()
    {
        return 'index';
    }
}
При запросе получаю:
{
"name": "Unauthorized",
"message": "You are requesting with an invalid credential.",
"code": 0,
"status": 401
}
Стоит убрать authenticator из behaviors, получаю доступ. Почему?
Ответить