【问题标题】:JWT token decode in cakephpcakephp 中的 JWT 令牌解码
【发布时间】:2019-10-11 14:31:06
【问题描述】:

我在解码令牌 (JWT) 时遇到问题。在这里它已成功编码,并为我提供了一个令牌。我的代码是:

$tokenData = $this->set([
                'data' => [
                    'token' => JWT::encode([
                        'sub' => $user['username'],
                        'exp' =>  time() + 202200
                    ],

                        Security::salt())
                ],
                '_serialize' => ['success', 'data']
            ]);   

它返回"token":{"token":"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}

为了解码我使用的:

$JWT_KEY = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$token = JWT::decode($JWT_KEY);
dd($token);

我怎样才能得到它?特别是时间。提前致谢

【问题讨论】:

  • 你怎么能得到什么? dd 向您展示了什么?

标签: php api cakephp jwt


【解决方案1】:

如果您使用的是 Firebase JWT,请查看:https://github.com/firebase/php-jwt

对我来说该命令有效,这是我的一段代码:

$jwt= $this->request->data['_token']; $decoded = JWT::decode($jwt, $this->pepper, array('HS256'));

//$decoded 是一个带有你的令牌解码数据的对象

【讨论】:

    猜你喜欢
    • 2021-12-30
    • 2018-10-05
    • 2019-05-19
    • 2018-08-14
    • 2020-05-23
    • 2016-11-15
    • 2021-06-30
    • 2019-06-02
    相关资源
    最近更新 更多