使用Yii2 REST API无法获取QueryParamAuth.php中的查询参数

问题描述 投票:0回答:1

当我使用 QueryParamAuth 函数连接到我的 API 时,出现此错误:

“data”: { “name”: “Unauthorized”, “message”: “Your request was made with invalid credentials.”, “code”: 0, “status”: 401, “type”: “yii\web\UnauthorizedHttpException” }

这就是我的行为:

$behaviors['authenticator'] = [ 'class' => QueryParamAuth::class, 'tokenParam' => 'access-token', ];

所以我尝试使用令牌连接到我的 api。

api yii2
1个回答
0
投票

需要去Yii2项目中的QueryParamAuth.php直接请求

acces-token
,无需经过
tokenParam
声明。

public function authenticate($user, $request, $response)
{
    $accessToken = $request->get('acces-token');
    if (is_string($accessToken)) {
        $identity = $user->loginByAccessToken($accessToken, get_class($this));
        if ($identity !== null) {
            return $identity;
        }
    }
    if ($accessToken !== null) {
        $this->handleFailure($response);
    }

    return null;
}
© www.soinside.com 2019 - 2024. All rights reserved.