<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)

        I don#39;t understand JWT refresh token#39;s behaviour (LARAVEL)(我不明白 JWT 刷新令牌的行为 (LARAVEL))
      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)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                  PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                  mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                  Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                  Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                  Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)

                    <tbody id='9y7Pf'></tbody>
                  • <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'>