当前位置:网站首页>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 .
边栏推荐
- Cloud database smooth disassembly scheme
- The latest research progress of domain generalization from CVPR 2022
- Kubernetes cluster lossless upgrade practice
- Configuring error sets using MySQL for Ubuntu 20.04.4 LTS
- Notepad++ installing the jsonview plug-in
- How to do API gateway routing? What are the other functions of API gateway?
- How to wrap QR code data
- Detailed explanation of logical structure, physical structure and data operation
- KnowDA: All-in-One Knowledge Mixture Model for Data Augmentation in Few-Shot NLP(KnowDA:用于 Few-Shot NLP 中数据增强的多合一知识混合模型)
- How to deal with high memory in API gateway how to maintain API gateway
猜你喜欢

Using the provider to transform the shit like code, the amount of code is reduced by 2/3!

HDLBits->Circuits->Arithmetic Circuitd->3-bit binary adder

Introduction to scikit learn machine learning practice

MySQL de duplication query only keeps one latest record

Outlook开机自启+关闭时最小化

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

Teacher lihongyi from National Taiwan University - grade Descent 2

Freshman girls' nonsense programming is popular! Those who understand programming are tied with Q after reading

嵌入式开发:嵌入式基础——重启和重置的区别

Minimisé lorsque Outlook est allumé + éteint
随机推荐
EDI mandatory manual
Peking University, University of California Berkeley and others jointly | domain adaptive text classification with structured knowledge from unlabeled data (Domain Adaptive Text Classification Based o
Using barcode software to make certificates
How does the hybrid cloud realize the IP sec VPN cloud networking dedicated line to realize the interworking between the active and standby intranet?
One article to help you understand automatic injection
How to deal with high memory in API gateway how to maintain API gateway
Relevant logic of transaction code MICn in SAP mm
Go bubbling, cocktail, quick, insert sort
Ffmpeg for audio and video commands
Leetcode algorithm interview sprint sorting algorithm theory (32)
How to batch generate video QR code
Meaning of the last seven digits of wider face
A batch layout WAF script for extraordinary dishes
What causes the applet SSL certificate to expire? How to solve the problem when the applet SSL certificate expires?
Bluetooth chip | Renesas and Ti launch new Bluetooth chip, try Lenz st17h65 Bluetooth ble5.2 chip
Raid card with hardware knowledge (5)
CMU博士论文 | 通过记忆的元强化学习,118页pdf
How to deploy the API gateway? Is it OK not to use the API gateway?
How to wrap QR code data
Take you through the distributed file system