【问题标题】:CakePHP 2 JWT Auth Plugin not receiving header in CakeRequestCakePHP 2 JWT Auth 插件未在 CakeRequest 中接收标头
【发布时间】:2017-07-05 18:48:30
【问题描述】:

我正在使用 CakePHP 插件 (https://github.com/t73biz/cakephp2-jwt-auth)。我的 CakePHP 应用程序是 2.6.2 版。我已将此添加到 AppController 中的身份验证组件中。

    'JwtAuth.JwtToken' => array(
                'fields' => array(
                    'username' => 'email',
                    'password' => 'password',
                    'token' => '_token'
                ),
                'parameter' => '_token',
                'contain' => array(
                    'Organization'
                ),
                'scope' => array(
                    'User.status' => 'A',
                    //'User.frozen' => 0,
                    'User.locked_out' => 0,
                    'Organization.status' => 'A',
                    //'User.failed_sign_ins < 4'

                ),
                'header' => 'X_JSON_WEB_TOKEN',
                'pepper' => 'pepper' // Says pepper because I do not want to show the pepper key I used for my code
            ),

我知道插件会运行,因为我在插件的 getUser 函数中添加了一个 die 语句,它会在我执行 API 请求时显示出来。

public function getUser(CakeRequest $request) {

    $token = $this->_getToken($request);
    if ($token) {
        return $this->_findUser($token);
    }
    return false;
}

这是插件控制器目录中组件目录中 JwtTokenAuthenticate.php 的一部分的函数。当我调试 $request 时,我没有将标头作为请求的一部分。我正在使用 Postman 测试 API 和 Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJkYXRhIjp7ImlkIjoiMTIiLCJzdWIiOiIxMiJ9LCJpYXQiOjE0ODcyNTUxMjYsImV4cCI6MTQ4NzI1ODcyNn0.5hoyXltPmEXIA3eVtJnnn3Dor2lhviej31eZNbaMbow

【问题讨论】:

    标签: cakephp oauth-2.0 jwt cakephp-2.6


    【解决方案1】:

    如果我理解正确,您是在尝试通过 Authorization 标头传递身份验证令牌吗?但根据插件文档,您应该通过 X_JSON_WEB_TOKEN 标头或 _token 查询参数来完成。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-11-05
      • 1970-01-01
      • 2018-04-15
      • 2018-01-28
      • 2021-05-21
      • 2016-02-16
      • 1970-01-01
      相关资源
      最近更新 更多