Answer the question
In order to leave comments, you need to log in
Why is my restful authentication not working in yii2?
I need it to check if there is such a username in my database when authorizing through ios via api, if so, display its id.
This is in the controller
<?php
namespace frontend\controllers;
use Yii;
use yii\rest\ActiveController;
use yii\filters\auth\HttpBasicAuth;
class TodoController extends ActiveController
{
public $modelClass = 'common\models\User';
public function init()
{
parent::init();
\Yii::$app->user->enableSession = false;
}
public function behaviors()
{
$behaviors = parent::behaviors();
$behaviors['authenticator'] = [
'class' => HttpBasicAuth::className(),
];
return $behaviors;
}
}
Added this to common\models\User.php
public static function findIdentityByAccessToken($token, $type = null)
{
return static::findOne(['access_token' => $token]);
}
Displays a 401 error
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