Answer the question
In order to leave comments, you need to log in
How to disable authorization for certain actions (Yii2, rest api)?
I am writing an api in yii2 for an existing site and ran into such a problem.
We need to make some actions public (i.e. you don't need to go through authorization to get information).
Api wrote based on this data yiiframework.com
but did not find where authorization is disabled there.
Maybe someone faced such a problem? Tell me please!
Answer the question
In order to leave comments, you need to log in
public function behaviors()
{
$behaviors = parent::behaviors();
$behaviors['authenticator'] = [
'class' => HttpBasicAuth::className(),
'optional' => ['index']
];
return $behaviors;
}
found the setting, optional - an array of actions that will be public is passed
In your controller where you want to make the action public.
public function behaviors()
{
return [
'access' => [
'class' => AccessControl::className(),
'only' => ['someActionOne', 'someActionTwo',],
'rules' => [
[
'allow' => true,
'actions' => ['someActionOne', 'someActionTwo'],
'roles' => ['?'],
],
],
],
];
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question