控制器行为正在阻止我的api请求到我的方法

时间:2016-06-05 18:54:32

标签: yii yii2 yii2-advanced-app yii-components yii2-basic-app

我有登录方法,我想允许访问它进行身份验证。但是当我向我的类添加行为时,它会引发一些垃圾错误。

这是我的控制器

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;

1 个答案:

答案 0 :(得分:0)

发现了问题

HttpBearerAuth ::的className(),

缺少使用yii \ filters \ auth \ HttpBearerAuth;

感谢