PHP JWT Token Invalid Signature(PHP JWT 令牌无效签名)
问题描述
我现在正在搜索一个小时,但找不到解决此问题的方法.
这是生成 JWT 令牌的代码.我使用了
谁能帮我解决这个问题?我目前是 JWT 的新手.顺便说一句,我的项目是 Slim API.
非常感谢.
签名验证失败,因为您没有将正确的密钥传递给 https://jwt.io/ 您需要从 PHP 代码中传递 $secretKey
的值.根据屏幕截图,您正在传递字符串 secret
.
I'm searching for an hours now and can't find a solution to this problem.
This is the code to generate JWT token. I used https://github.com/firebase/php-jwt library.
$tokenId = base64_encode(mcrypt_create_iv(32));
$issuedAt = time();
$notBefore = $issuedAt + 10; //Adding 10 seconds
$expire = $notBefore + 60; // Adding 60 seconds
$serverName = 'serverName'; // Retrieve the server name from config file
$secretKey = base64_decode(getenv('JWT_SECRET'));
$data = [
'iat' => $issuedAt, // Issued at: time when the token was generated
'jti' => $tokenId, // Json Token Id: an unique identifier for the token
'iss' => $serverName, // Issuer
'nbf' => $notBefore, // Not before
'exp' => $expire, // Expire
'data' => [ // Data related to the signer user
'userId' => '1', // userid from the users table
'userName' => $UserName, // User name
]
];
$jwt = JWT::encode(
$data, //Data to be encoded in the JWT
$secretKey, // The signing key
'HS256' // Algorithm used to sign the token
);
$unencodedArray = ['jwt' => $jwt];
echo json_encode($unencodedArray);
And I verify the token at https://jwt.io/
Can anybody help me with this problem? I'm currently new in JWT. Btw, my project is Slim API.
Thank you very much.
Signature verification fails because you are not passing the correct secret key to https://jwt.io/ You need to pass the value of $secretKey
from the PHP code. According to the screenshot you are passing string secret
.
这篇关于PHP JWT 令牌无效签名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:PHP JWT 令牌无效签名
基础教程推荐
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01
- 超薄框架REST服务两次获得输出 2022-01-01
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- 在多维数组中查找最大值 2021-01-01
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- XAMPP 服务器不加载 CSS 文件 2022-01-01
- 如何在 PHP 中的请求之间持久化对象 2022-01-01
- Libpuzzle 索引数百万张图片? 2022-01-01