Answer the question
In order to leave comments, you need to log in
How to do HTTP Basic Authorization in Yii2 application without DB?
Good afternoon!
I need to do basic authorization in yii2 for a separate /api folder, without using a model (db), i.e. just enter the username and password in the code.
Tried via htaccess but no response when adding .htaccess to /api/web. As if the project does not see it.
I tried to do this, but it is through the database:
public function behaviors()
{
return [
'basicAuth' => [
'class' => \yii\filters\auth\HttpBasicAuth::className(),
'auth' => function ($username, $password) {
if ($username == 'admin' && $password == 'admin') {
return true;
} else {
return null;
}
},
],
];
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question