当前位置:网站首页>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
边栏推荐
- 期货公司开户后续会有哪些服务?
- eBPF/Ftrace
- uniapp防止连续点击出错
- Evconnlistener of libevent_ new_ bind
- Use recyclerview to realize the left sliding menu of the list
- 小程序毕设作品之微信校园洗衣小程序毕业设计成品(1)开发概要
- Fifth, download the PC terminal of personality and solve the problem of being unable to open it
- 不需要标注数据的语义分割!ETH&鲁汶大学提出MaskDistill,用Transformer来进行无监督语义分割,SOTA!...
- 软考 系统架构设计师 简明教程 | 软件测试
- 【300+精选大厂面试题持续分享】大数据运维尖刀面试题专栏(九)
猜你喜欢

Design of network abnormal traffic analysis system

English grammar_ Personal pronoun

JS 模块、闭包应用

for .. of可用于哪些数据的遍历

For.. of can be used to traverse which data

Product manager experience 100 (XI) - Strategic Product Manager: model and methodology

Go language series: how to build a go language development environment?

js将数组根据指定属性值分组成二维数组

电滑环的常用类型

Training in the second week of summer vacation on July 24, 2022
随机推荐
软考 系统架构设计师 简明教程 | 系统设计
Verilog的系统任务----$fopen、$fclose和$fdisplay, $fwrite,$fstrobe,$fmonitor
浏览器内核模块组成
Use recyclerview to realize the left sliding menu of the list
Construction and application of industrial knowledge atlas (I): overview of industrial knowledge atlas
利用eBPF探测Rootkit漏洞
SQL tutorial: introduction to SQL aggregate functions
SCI论文写作
js回调函数(callback)
滑环的分类以及用途
English grammar_ Definite article the_ Small details
Tencent cloud and the China Federation of industry released the research results of industrial AI quality inspection standardization to accelerate the intelligent transformation of manufacturing indus
Software system architecture designer concise tutorial | software system modeling
Can I only use tidb binlog tool to synchronize tidb to MySQL in real time?
【2022-07-25】
电滑环的常用类型
小程序毕设作品之微信校园洗衣小程序毕业设计成品(4)开题报告
期货公司开户后续会有哪些服务?
Cute image classification -- a general explanation of the article "what are the common flops in CNN model?"
2022acm summer training weekly report (IV)