简体   繁体   English

cakephp中的JWT令牌解码

[英]JWT token decode in cakephp

I am facing a problem to decode token (JWT).我面临解码令牌(JWT)的问题。 Here it's encoded successfully and it provides me with a token.在这里它已成功编码,并为我提供了一个令牌。 My code code is:我的代码是:

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

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

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

To decode this I used:为了解码这个,我使用了:

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

How can I get it?我怎么才能得到它? specially time.特别的时间。 Thanks in advance提前致谢

if you are using firebase JWT take a look to: https://github.com/firebase/php-jwt如果您使用的是 Firebase JWT,请查看: https : //github.com/firebase/php-jwt

for me that command worked, here's a piece of my code:对我来说,该命令有效,这是我的一段代码:

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

//$decoded is an object with your token decoded data //$decoded 是一个带有令牌解码数据的对象

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM