M
M
Mors Clamor2019-10-26 19:16:25
Yii
Mors Clamor, 2019-10-26 19:16:25

Yii2 HTTP Basic authentication how to do?

Hello. I can’t understand how Basic authentication is implemented in the rest of Yii2 - I found a way on the forum:

public function behaviors()
     {
         $behaviors = parent::behaviors();
         $behaviors['authenticator'] = [
             'class' => HttpBasicAuth::className(),
             'auth' => [$this, 'auth']
         ];
         return $behaviors;
     }

     public function auth($username, $password)
     {
       $user = User::findOne(['username' => $username]);
       if ($user->validatePassword($password)) {
         return true;
       }
       else {
         return false;
       }
     }

But for any non-empty password, it considers that access is authorized. The accessToken field in my table is empty, how to implement it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim, 2019-10-26
@66demon666

It is necessary not to crawl on the forum. And to the documentation .
Here's a finished example for you . Dmitry once gave you a video of Dmitry Eliseev via API
. You first study, look, then there will be no questions left. If you are too lazy to look for a long time, that is , Maxim has a shorter

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question