我有登录方法,我想允许访问它进行身份验证。但是当我向我的类添加行为时,它会引发一些垃圾错误。
这是我的控制器
namespace api\controllers;
use common\models\User;
use Yii;
use yii\rest\ActiveController;
use yii\filters\auth\CompositeAuth;
use yii\filters\auth\HttpBasicAuth;
use yii\filters\auth\QueryParamAuth;
use common\models\Authentication;
class AuthenticationController extends ActiveController
{
public $modelClass = 'common\models\Authentication';
public function behaviors()
{
$behaviors = parent::behaviors();
$behaviors['authenticator'] = [
'class' => CompositeAuth::className(),
'except' => ['login'],
'authMethods' => [
HttpBasicAuth::className(),
HttpBearerAuth::className(),
QueryParamAuth::className(),
],
];
return $behaviors;
}
public function actionLogin()
{
$access_token = null;
答案 0 :(得分:0)
发现了问题
HttpBearerAuth ::的className(),
缺少使用yii \ filters \ auth \ HttpBearerAuth;
感谢