当前位置:网站首页>JWT login expiration - automatic refresh token scheme introduction
JWT login expiration - automatic refresh token scheme introduction
2022-07-27 13:48:00 【leowang5566】
JWT Login expired - Automatically refresh token Introduction of the plan
Preface
In the scene of front and back separation , More and more projects use jwt token As the security mechanism of the interface , But there is jwt After expired , Users cannot directly perceive , If be in, ⽤ User operation page ⾯ period , Suddenly mention ⽰ Sign in , The experience is very unfriendly ,
So there it is token⾃ Dynamic refresh requirements . But this automatic refresh scheme , Basically, it is inseparable from the server-side state storage ,JWT The idea is : Go to middle ⼼ turn ,⽆ State , So there is a violation of businesses like this , Yes ⾥ cloud ⾸ page , Didn't do token Refresh token maintenance , But it conforms to the corresponding idea
⽅ case ⼀、 Front end control detection token,⽆ Perceptual refresh
⽤ When the user logs in successfully ,⼀ Give him two times Token, Respectively AccessToken and RefreshToken
AccessToken The validity period is short ,⽐ Such as 1 Days or 5 God ,⽤ In normal request
RefreshToken The validity period can be set as long ⼀ some , for example 10 God 、20 God , As a refresh AccessToken Proof of
Refresh ⽅ case
When AccessToken When it's about to expire , For example, in advance 30 minute , Client benefits ⽤RefreshToken Request the specified API To obtain a new AccessToken And update the in the local storage AccessToken
nucleus ⼼ Logic
- After successful login ,jwt⽣ become AccessToken; UUID⽣ become RefreshToken And stored on the server redis in , Set expiration time
- Pick up ⼝ return 3 A field AccessToken/RefreshToken/ Access token expiration timestamp
- because RefreshToken Store on the server redis in , If the RefreshToken It's overdue , Then mention ⽰ Log back in ;
doubt :RefreshToken The validity period is so long , And direct AccessToken What is the difference between the extension of the validity period of
answer :RefreshToken Unlike AccessToken It's like that ⼤ Most requests are made ⽤, Mainly local detection accessToken Only when it is about to expire ⽤,⼀ When storing locally , It's not called refreshToken, The front end can be aliased , The confused code makes the attacker unable to directly recognize this is the refresh token
shortcoming :
The front end needs to judge every request token From expiration time
advantage :
Low rear end pressure , Code logic changes no ⼤
⽅ case ⼆、 The back-end storage determines the expiration time
Back end storage AccessToken, Every time the request comes, we will judge whether it will expire , If it is about to expire, please re ⽣ Into a new token, And return to the front end for re storage ,⽐ Such as distance 1 Days or 30 Minutes expired , If ⽤ The user accesses the corresponding connection ⼝ It will be updated. , But if there is no access token If it has expired, you need to log in again
advantage :
Front end changes ⼩, Just store the response http head ⾥⾯ Is there a new token production ⽣, If there is, store it again
shortcoming :
Back end replication , And token It is easy to exist in a live state after leakage , And there will be concurrent requests on the front end , When multiple concurrent requests are received jwt token when , Easy to generate multiple token Chaotic use
边栏推荐
- [basic knowledge] ~ IC design process and EDA tools used in each stage
- Additional: [urlencoder.encode (string to be encoded, "encoding method");] (what is it?; why do we use this to encode when we set values in cookies?) (to be improved...)
- [2023 Fudan Microelectronics written examination questions in advance] ~ questions and reference answers
- LeetCode报错及其解决方案
- Figure 8 shows you how to configure SNMP
- Go language series: how to build a go language development environment?
- Zoom, translation and rotation of OpenCV image
- 小程序毕设作品之微信校园洗衣小程序毕业设计成品(3)后台功能
- 软考 系统架构设计师 简明教程 | 软件测试
- Vertical and horizontal shooting range - the mystery of the picture
猜你喜欢

Zoom, translation and rotation of OpenCV image

eBPF/Ftrace

使用putty设置基于 SSH 密钥的身份验证

小程序毕设作品之微信校园洗衣小程序毕业设计成品(1)开发概要

建议收藏,PMP应战篇(2)之易混淆知识点

Image features and extraction

Verilog的系统任务----$fopen、$fclose和$fdisplay, $fwrite,$fstrobe,$fmonitor

小程序毕设作品之微信校园洗衣小程序毕业设计成品(3)后台功能

产品经理经验谈100篇(十一)-策略产品经理:模型与方法论

小程序毕设作品之微信校园洗衣小程序毕业设计成品(7)中期检查报告
随机推荐
Oppo self-developed large-scale knowledge map and its application in digital intelligence engineering
Figure 8 shows you how to configure SNMP
for .. of可用于哪些数据的遍历
[basic knowledge] ~ IC design process and EDA tools used in each stage
SNMP (Simple Network Management Protocol)
在“元宇宙空间”UTONMOS将打开虚实结合的数字世界
Install the wireless network card driver
Futures Commission Standard and margin ratio
[introduction to C language] zzulioj 1021-1025
Fiddler bag capturing Tool + night God simulator
Egg swagger doc graphic verification code solution
Selenium eight elements positioning and relative locator
7.26 simulation summary
What are the precautions for using carbon brushes
Verilog的系统任务----$fopen、$fclose和$fdisplay, $fwrite,$fstrobe,$fmonitor
软考 系统架构设计师 简明教程 | 软件测试
[internship experience] add your own implementation method to the date tool class
new的多种使用方法
Conditions and procedures of futures account opening
将目标检测大尺寸图片裁剪成固定尺寸图片