温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Yii2.0 restfut接口认证错误出坑指南

发布时间:2020-06-05 06:39:33 来源:网络 阅读:1024 作者:daydaydream 栏目:web开发

测试Yii2.0即接口认证功能(出坑指南):
//认证

bindValTap: function () {
var page = this;
wx.request({
url: 'http://apitest.test/invmembers?access-token=rg1v5BF7OBGE4Bze562wZSUfiStakUK_',
header: {
'content-type': 'application/json'
},
method: 'get',
data: {
'per-page': 6,
// page: 5
},
success: function (res) {
// page.setData({motto:res.data[0].name});
console.log(res.data);
}
})
},

出现Yii2.0 restfut接口认证错误:Your request was made with invalid

研究了很久,后来找到\vendor\yiisoft\yii2\filters\auth\QueryParamAuth.php 中

class QueryParamAuth extends AuthMethod
{
/**

  • @var string the parameter name for passing the access token
    */
    public $tokenParam = 'access-token';

    /**

  • @inheritdoc
    */
    public function authenticate($user, $request, $response)
    {
    $accessToken = $request->get($this->tokenParam);
    if (is_string($accessToken)) {
    $identity = $user->loginByAccessToken($accessToken, get_class($this));
    if ($identity !== null) {
    return $identity;
    }
    }
    if ($accessToken !== null) {
    $this->handleFailure($response);
    }

    return null;

    }
    }

才发现传递的参数是access-token,而不是access_token!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI