<bdo id='sPFR0'></bdo><ul id='sPFR0'></ul>
  • <legend id='sPFR0'><style id='sPFR0'><dir id='sPFR0'><q id='sPFR0'></q></dir></style></legend>

  • <tfoot id='sPFR0'></tfoot>

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

      2. 我不明白 JWT 刷新令牌的行为 (LARAVEL)

        时间:2023-12-01
      3. <tfoot id='rJgHM'></tfoot>

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

            1. <small id='rJgHM'></small><noframes id='rJgHM'>

              <legend id='rJgHM'><style id='rJgHM'><dir id='rJgHM'><q id='rJgHM'></q></dir></style></legend>
                <bdo id='rJgHM'></bdo><ul id='rJgHM'></ul>
                    <tbody id='rJgHM'></tbody>
                  本文介绍了我不明白 JWT 刷新令牌的行为 (LARAVEL)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我刚刚尝试使用 LARAVEL 和这个 https://github.com/tymondesigns/jwt- 进行 JWT 身份验证授权

                  I have just tried JWT auth with LARAVEL and this https://github.com/tymondesigns/jwt-auth

                  但有些东西我无法理解.他们在他们的配置中放置了:

                  But there's something i can't understand. In their config they put :

                  'ttl' => env('JWT_TTL', 60), // in munutes
                  'refresh_ttl' => env('JWT_REFRESH_TTL', 20160), // in minutes
                  

                  据我了解:token 的有效期为 1 小时,可在 2 周内刷新

                  What i understant : the token's live is 1hour and can be refreshed within 2 weeks

                  但 3 小时后,如果我尝试查询某些内容,它会显示令牌已过期".

                  But after 3hours, if i try to query something, it says "token expired".

                  这个系统是否意味着,用户必须在每个小时内更新/刷新他的令牌,但限制为 2 周?没看懂.

                  Does this system mean, a user must get his token updated / refreshed within every hour but with a limit of 2 weeks ? I don't get it.

                  用户如何使用这种系统持续登录?第一个小时后刷新令牌有什么用处,虽然还不到 2 周,但我无法获得新令牌?

                  How can a user persist login with this kind of system ? How is the refresh Token useful when after the first hour, though it hasn't been 2 weeks yet, i can't get a fresh token ?

                  谢谢

                  更新:代码

                  配置/jwt.php

                  'ttl' => 2, // 2 minutes
                  'refresh_ttl' => 5, // 5 minutes
                  

                  路由/api.php

                  Route::post('/login', 'AuthController@login');
                  Route::get('/test', 'AuthController@test')->middleware('jwt.auth', 'jwt.refresh');
                  

                  Http/Controllers/AuthController

                  Http/Controllers/AuthController

                  namespace AppHttpControllers;
                  
                  use IlluminateHttpRequest;
                  use JWTAuth;
                  use TymonJWTAuthExceptionsJWTException;
                  
                  class AuthController extends Controller
                  {
                      public function test()
                      {
                          return response()->json(['coucou' => 1]);
                      }
                  
                      public function login(Request $request)
                      {
                          // grab credentials from the request
                          $credentials = $request->only('email', 'password');
                  
                          try {
                              // attempt to verify the credentials and create a token for the user
                              if (! $token = JWTAuth::attempt($credentials)) {
                                  return response()->json(['error' => 'invalid_credentials'], 401);
                              }
                          } catch (JWTException $e) {
                              // something went wrong whilst attempting to encode the token
                              return response()->json(['error' => 'could_not_create_token'], 500);
                          }
                  
                          // all good so return the token
                          return response()->json(compact('token'));
                      }
                  }
                  

                  这就是流程:

                  请求/login/login响应 > {token: xxxxxxx}

                  request to /login with {username: xxx, password: xxx} response of /login > {token: xxxxxxx}

                  请求 /test/testresponse > HEADER中带有NEW TOKEN的良好json响应

                  request to /test straight after (10 secs) with Bearer xxxxxx response of /test > the good json response with NEW TOKEN in HEADER

                  请求/test(所以现在已经过去了 3 分钟 10 秒,小于 5 分钟的刷新限制)/test响应 >令牌过期

                  request to /test after 3 minutes (so 3mins 10 secs have past now, less than the 5min of refresh limit) response of /test > token expired

                  我不明白.

                  推荐答案

                  访问令牌过期后,您可以使用刷新令牌获取新的访问令牌,而无需再次要求用户输入用户名和密码.只有刷新令牌过期后,用户才需要重新登录.

                  After the access token is expired you can use the refresh token to get a new access token without asking the user to input his username and password again. Only after the refresh token is expired, the user needs to login again.

                  但 3 小时后,如果我尝试查询某些内容,它会显示令牌已过期".

                  But after 3hours, if i try to query something, it says "token expired".

                  那是因为访问令牌已过期.

                  that's because the access token is expired.

                  这个系统是否意味着,用户必须在每个小时内更新/刷新他的令牌,但限制为 2 周?没看懂.

                  Does this system mean, a user must get his token updated / refreshed within every hour but with a limit of 2 weeks ? I don't get it.

                  是的.您将刷新令牌保留在客户端系统中,并在访问令牌过期时使用它来请求新的访问令牌.

                  yes. You keep the refresh token in your client system and use it to request a new access token when the access token is expired.

                  这篇关于我不明白 JWT 刷新令牌的行为 (LARAVEL)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Laravel JWT 令牌在身份验证 JWT 方法中刷新后无效 下一篇:如何从 Laravel 的请求中获取 Bearer 令牌

                  相关文章

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

                    <legend id='9y7Pf'><style id='9y7Pf'><dir id='9y7Pf'><q id='9y7Pf'></q></dir></style></legend>

                      • <bdo id='9y7Pf'></bdo><ul id='9y7Pf'></ul>

                      <small id='9y7Pf'></small><noframes id='9y7Pf'>