当前位置:网站首页>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
边栏推荐
- Common distributed theories (cap, base) and consistency protocols (gosssip, raft)
- We should learn to check the documented instructions of technical details
- 建议收藏,PMP应战篇(2)之易混淆知识点
- How can electric complete set enterprises do well in cost and profit management with the help of ERP system?
- Jianzhi offer 07 rebuild binary tree -- construct binary tree from middle order and post order traversal sequence
- Dat.gui control custom placement and dragging
- Browser kernel module composition
- 滑环设备怎么进行维护
- for .. of可用于哪些数据的遍历
- Construction and application of industrial knowledge atlas (3): commodity knowledge fusion
猜你喜欢

leetcode——83,24; Machine learning - neural networks

【C进阶】指针数组 VS 数组指针

Training in the second week of summer vacation on July 24, 2022

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

Vertical and horizontal shooting range - the mystery of the picture

剑指Offer 07 重建二叉树 -- 从中序与后序遍历序列构造二叉树

以科技传递温度,vivo亮相数字中国建设峰会

SNMP (Simple Network Management Protocol)

SCI论文写作

Fiddler抓包工具+夜神模拟器
随机推荐
【C进阶】指针数组 VS 数组指针
16-VMware Horizon 2203 虚拟桌面-Win10 自动桌面池完整克隆专用(十六)
Keras深度学习实战——推荐系统数据编码
Data enhancement in image processing
SQL教程之 SQL 聚合函数入门教程
SCI thesis writing
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...)
Design of network abnormal traffic analysis system
期货公司开户后续会有哪些服务?
[2023 Fudan Microelectronics written examination questions in advance] ~ questions and reference answers
Install the wireless network card driver
Qt剪切板QClipboard 复制粘贴自定义数据
Software testing system architecture designer concise tutorial | software testing
期货开户的条件和流程
JS 模块、闭包应用
Fiddler抓包工具+夜神模拟器
ThinkPHP+宝塔运营环境实现定时任务
以科技传递温度,vivo亮相数字中国建设峰会
OPPO 自研大规模知识图谱及其在数智工程中的应用
eBPF/Ftrace