<legend id='xo0C7'><style id='xo0C7'><dir id='xo0C7'><q id='xo0C7'></q></dir></style></legend>

    <small id='xo0C7'></small><noframes id='xo0C7'>

    <i id='xo0C7'><tr id='xo0C7'><dt id='xo0C7'><q id='xo0C7'><span id='xo0C7'><b id='xo0C7'><form id='xo0C7'><ins id='xo0C7'></ins><ul id='xo0C7'></ul><sub id='xo0C7'></sub></form><legend id='xo0C7'></legend><bdo id='xo0C7'><pre id='xo0C7'><center id='xo0C7'></center></pre></bdo></b><th id='xo0C7'></th></span></q></dt></tr></i><div id='xo0C7'><tfoot id='xo0C7'></tfoot><dl id='xo0C7'><fieldset id='xo0C7'></fieldset></dl></div>
    1. <tfoot id='xo0C7'></tfoot>

          <bdo id='xo0C7'></bdo><ul id='xo0C7'></ul>

        PHP JWT 令牌无效签名

        时间:2023-12-01
          <i id='sR39o'><tr id='sR39o'><dt id='sR39o'><q id='sR39o'><span id='sR39o'><b id='sR39o'><form id='sR39o'><ins id='sR39o'></ins><ul id='sR39o'></ul><sub id='sR39o'></sub></form><legend id='sR39o'></legend><bdo id='sR39o'><pre id='sR39o'><center id='sR39o'></center></pre></bdo></b><th id='sR39o'></th></span></q></dt></tr></i><div id='sR39o'><tfoot id='sR39o'></tfoot><dl id='sR39o'><fieldset id='sR39o'></fieldset></dl></div>

                <tbody id='sR39o'></tbody>

                <tfoot id='sR39o'></tfoot>
              1. <small id='sR39o'></small><noframes id='sR39o'>

                <legend id='sR39o'><style id='sR39o'><dir id='sR39o'><q id='sR39o'></q></dir></style></legend>

                • <bdo id='sR39o'></bdo><ul id='sR39o'></ul>
                  本文介绍了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 和 MySQL(不使用 OAuth)以安全的方式对一组 Web API 实施“基于令牌的身份验证 下一篇:FatalThrowableError:参数 1 已通过 ..::fromUser() laravel 5.6

                  相关文章

                      <small id='36GIK'></small><noframes id='36GIK'>

                      <legend id='36GIK'><style id='36GIK'><dir id='36GIK'><q id='36GIK'></q></dir></style></legend>
                        <bdo id='36GIK'></bdo><ul id='36GIK'></ul>

                    1. <tfoot id='36GIK'></tfoot>

                      <i id='36GIK'><tr id='36GIK'><dt id='36GIK'><q id='36GIK'><span id='36GIK'><b id='36GIK'><form id='36GIK'><ins id='36GIK'></ins><ul id='36GIK'></ul><sub id='36GIK'></sub></form><legend id='36GIK'></legend><bdo id='36GIK'><pre id='36GIK'><center id='36GIK'></center></pre></bdo></b><th id='36GIK'></th></span></q></dt></tr></i><div id='36GIK'><tfoot id='36GIK'></tfoot><dl id='36GIK'><fieldset id='36GIK'></fieldset></dl></div>