I try to make a test REST API on yii2. The documentation lists three basic authentication methods. I decided to try HTTP Basic Auth. But there were problems and questions.
The documentation indicates that the controller should configure the behavior
use yii\filters\auth\HttpBasicAuth; public function behaviors() { $behaviors = parent::behaviors(); $behaviors['authenticator'] = [ 'class' => HttpBasicAuth::className(), ]; return $behaviors; } And after findIdentityByAccessToken() method, but where? In the example below for the class User
use yii\db\ActiveRecord; use yii\web\IdentityInterface; class User extends ActiveRecord implements IdentityInterface { public static function findIdentityByAccessToken($token, $type = null) { return static::findOne(['access_token' => $token]); } } Well and moreover, it turns out that all this needs to be written in each controller for each model. And if there are 50? Duplicate the same thing so many times? How to be here? And what's wrong? And where to set up the findIdentityByAccessToken() method? Just need a general authorization for all API in one place