I\'ve made a Yii2 REST API. With the API you can get a list of cars. Now I want to use the Bearer Authentication to protect the API. But I don\'t know how it works.
\yii\filters\auth\HttpBearerAuth::authenticate() will simply call \yii\web\User::loginByAccessToken() :
$class = $this->identityClass;
$identity = $class::findIdentityByAccessToken($token, $type);
So you just need to implement findIdentityByAccessToken() in your user identity class, e.g. :
public static function findIdentityByAccessToken($token, $type = null)
{
return static::findOne(['auth_key' => $token]);
}