Answer the question
In order to leave comments, you need to log in
Is it possible to use $behaviors['access'] and $behaviors['authenticator'] together?
Can I use these 2 behaviors in conjunction for a controller inherited from ActiveController?
If so, how?
Here is an example code:
public function behaviors() {
$behaviors = parent::behaviors();
$behaviors['authenticator'] = [
'class' => TokenAuth::className()
];
$behaviors['access'] = array(
'class' => \yii\filters\AccessControl::className(),
'only' => ['login', 'registration', 'logout'],
'rules' => array(
[
'allow' => true,
'actions' => ['login', 'registration'],
'roles' => ['?'],
'verbs' => ['post']
],
[
'allow' => true,
'actions' => ['logout'],
'roles' => ['@'],
],
)
);
return $behaviors;
}
'class' => TokenAuth::className()
it is almost identicalQueryParamAuth::className()
Answer the question
In order to leave comments, you need to log in
For the authenticator filter , you can specify actions to which the filter should not be applied:
$behaviors['authenticator'] = [
'class' => TokenAuth::className(),
'except' => ['login', 'registration']
];
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question