dpauf28808 2017-04-17 11:53
浏览 58
已采纳

刷新JWT应该是API还是客户的责任?

I've read a lot of articles and Github issues regarding this but I'm not sure what the best solution is. For context I have a laravel API that, on authentication, issues a JWT with a one hour life. When the first API request is made after that hour period the API returns a 401 token expiry error. As far as I can tell there are two ways to handle refreshing that token;

  1. In the API when receiving a token, if it has expired but we are within the refresh ttl, refresh that token, continue the request as normal and return the new token in a header
  2. In the client, when a 401 response is returned with an expiry code, make a request to an API endpoint with the old token, have the API refresh and return a new token, then replay any pending API requests.

Item 2 sounds unnecessarily complicated because you would have to intercept and queue any requests from the client. Which way is this best handled?

  • 写回答

1条回答 默认 最新

  • dse3168 2017-04-17 12:10
    关注
    1. In the API when receiving a token, if it has expired but we are within the refresh ttl, refresh that token, continue the request as normal and return the new token in a header

    The first one make more sense and easier than the second one as you don't have to store the requests if the token was expired and you don't have to wait for the 401 response to replay those API requests which is not good for UX.

    Another way of doing that is to create a popup and let user choose whether they want to get new token or not.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端