当前位置:网站首页>JWT implementation
JWT implementation
2022-06-23 22:08:00 【Great inventor】
What should we do if we have to force users to log out ?
Similar can be used oauth2.0 Practices in the agreement , Issued after certification 2 individual token,access token and refresh token.
- access token The access token is a JWT, Set a shorter expiration time , such as 1 Hours . Each time the access token calls the back-end service, it needs to carry , The frequency of going back and forth to the network is very high , The more likely it is to be exposed , Setting a shorter expiration time can also reduce security risks .
- refresh token Refresh token , It's OK not to JWT, Set a longer expiration time , such as 1 Months . Refresh token is mainly used to exchange for new access token. Because it is only passed to the server when the access token is about to expire or has expired , Longer expiration times do not pose much security risk . Issued by token When , Save the refresh token only in redis And set expiration time . When a refresh token is used in exchange for a new access token , You need to determine redis Whether the refresh token exists in the , If it doesn't exist , The refresh fails , Users need to log in again .
The client needs to maintain the login status for a long time , When the access token fails , Automatically use the refresh token to obtain a new access token . Or before the access token expires , Refresh the token in advance .
Now we want to kick people , You only need to change the refresh token associated with the user from redis In the delete . After the current access token expires , Naturally, there is no way to refresh the token . So as to achieve the purpose of forcing users to log out .
One drawback of this design is that forcing users to log out is not timely . There needs to be a time to wait for the access token to expire . If you want high timeliness , You can set the expiration time of the access token to be shorter , But refresh token The frequency of . This needs to be weighed against your own business .
Every time the service is called api It is still original jwt Stateless Authentication , No need to access any central storage . Access to the central storage is required only when the access token is refreshed . It is also a compromise .
边栏推荐
- Performance optimization of database 5- database, table and data migration
- [js] 生成随机数组
- DM sub database and sub table DDL "pessimistic coordination" mode introduction - tidb tool sharing
- How to build an API gateway and how to maintain an API gateway?
- CMU博士论文 | 通过记忆的元强化学习,118页pdf
- Interpretation of opentelemetry project
- ACL2022 | MVR:面向开放域检索的多视角文档表征
- Framework not well mastered? Byte technology Daniel refined analysis notes take you to learn systematically
- [vulnerability recurrence]log4j vulnerability rce (cve-2021-44228)
- 微信小程序中发送网络请求
猜你喜欢

高阶柱状图之极环图与极扇图

Minimisé lorsque Outlook est allumé + éteint

Polar cycle graph and polar fan graph of high order histogram

How to use the serial port assistant in STC ISP?

个税怎么算?你知道吗

Analysis of Alibaba cloud Tianchi competition -- prediction of o2o coupon

Sending network request in wechat applet

万字长文!一文搞懂InheritedWidget 局部刷新机制

Ten thousand words! Understand the inheritedwidget local refresh mechanism

智能座舱SoC竞争升级,国产7nm芯片迎来重要突破
随机推荐
Embedded development: embedded foundation -- the difference between restart and reset
How ppt creates a visual chart
Don't let your server run naked -- security configuration after purchasing a new server (Basics)
What is the gold content of PMP certificate
Interpretation of opentelemetry project
Detailed explanation of logical structure, physical structure and data operation
How to deploy the API gateway? Is it OK not to use the API gateway?
To develop AI face comparison, how to output multiple faces with comparative similarity?
Knowda: all in one knowledge mixture model for data augmentation in feed shot NLP
Question: how to understand the network protocol and why the OSI reference model is divided into seven layers
Ten thousand words! Understand the inheritedwidget local refresh mechanism
Use bcryptjs to encrypt the password
Nanny level anti crawling teaching, JS reverse implementation of font anti crawling
Polar cycle graph and polar fan graph of high order histogram
数据可视化之:没有西瓜的夏天不叫夏天
Freshman girls' nonsense programming is popular! Those who understand programming are tied with Q after reading
Explain the rainbow ingress universal domain name resolution mechanism
Sending network request in wechat applet
从CVPR 2022看域泛化(Domain Generalization)最新研究进展
Dart series: smooth as silk, operating files and directories