Мне нужно чтобы в зависимости от того зарегистрированные пользователи или нет имели возможность к соответствующим actions через actionAuth. сейчас пишет message": "You are requesting with an invalid credential.", (api_user/auth PUT ). Подскажите как это сделать . Спасибо
Код: Выделить всё
public function behaviors(){
$behaviors = parent::behaviors();
$behaviors['contentNegotiator'] = [
'class' => ContentNegotiator::className(),
'formats' => [
'application/json' => Response::FORMAT_JSON
]
];
$behaviors['authenticator'] = [
'class' => HttpBearerAuth::className(),
'only' => ['auth']
];
$behaviors[ 'access'] = [
'class' => AccessControl::className(),
'rules' => [
[
'verbs'=>['put'],
'allow' => true,
'roles' => ['?'],
'actions'=>['auth']
],
[
'verbs'=>['patch'],
'allow' => true,
'roles' => ['@'],
'actions'=>['auth']
]
],
];
return $behaviors;
}
public function actionAuth() {
//$Request = Yii::$app->request;
//$Method = Yii::$app->request->isPut;
if (Yii::$app->request->isPut) { // Authorization (Put)
$this->GetToken();
} elseif (Yii::$app->request->isPost) { // RenewToken (Post)
$this->renewToken();
} elseif (Yii::$app->request->isDelete) { // LogOut (Delete)
$this->logOut();
} elseif (Yii::$app->request->isPatch){
// $this->afterFbRegistration();
}else {
throw new \yii\web\BadRequestHttpException('Not in (Put,Post,Delete, Patch) request!');
}
}