当前位置:网站首页>Token based authentication
Token based authentication
2022-06-12 04:42:00 【Wind god Shura envoy】
Traditional authentication system
- The user enters the user name and password in the login domain , Then click log in
- After the request is sent , Verify the legitimacy of users by querying the database at the back end . If the request is valid , Use the information obtained in the database to create a
session, Then return this in the response headersessionInformation about , The purpose is to put thissessionID Store in browser - The restricted back-end server in the access application provides this
sessionInformation - If
sessionThe information is valid , Allow users to access restricted back-end servers , And the rendered HTML Content return
shortcoming
- Cannot share the created by the server on the mobile side
sessionandcookie - stay web End rendered HTML The page is returned , At the mobile end, the response needs to contain something similar JSON perhaps XML Things that are
be based on token Certification of
- The user enters the user name and password in the login form , Then click log in
- After the request is sent , Verify the legitimacy of users by querying the database at the back end . If the request is valid , Use the information obtained in the database to create a
token, Then the information of this is returned in the response header , The purpose is to put thistokenStored in the browser's local storage - It is provided every time a request to access the restricted back-end server in the application is sent token Information
- If you get it from the request header
tokenIt works , Allow users to access restricted back-end servers , And back toJSONperhapsXML
advantage
No return session perhaps cookie, And we didn't return any HTML Content , That means we can apply this architecture to all clients of a particular application
token Transmit through the request header , Instead of storing authentication information in session or cookie in , This means statelessness , You can send from any one of them HTTP The requesting terminal sends a request to the server
JWT
JWT representative JSON Web Token, It is a kind of authentication header token Format . This token It helps you to transfer information between two systems in a safe way . There are three parts :header,payload,signature
header yes token Part of , For storage token The type and encoding of , It is usually used base-64 code
payload Contains information , You can store any kind of information , For example, user information , Product information, etc , They all use base-64 Store by encoding
signature It includes header,payload And the key , The key must be securely stored on the server
token Validation process and classification
1、token Verify the basic process
be based on token Authentication method for , There is no need to store the user's login record on the server , The basic process is as follows :
The client uses the user name and password to request login ;
The server receives the request , Verify user name and password ;
Verify success , The server will issue a token, Put this token Send to client ;
Client received token, Store it (Cookie、Loacal Storage、session storage);
Every time the client requests resources from the server , It needs to be signed and issued by the server token;
The server receives the request , Verify the... In the request token, If the validation is successful , Return the requested data to the client .
2、Token( token ) classification
Interface specific api_token
For users user_token
(1)、 Interface token Production rules
api_token = md5 (' Module name ' + ' The controller, ' + ' Method name ' + ' year - month - Japan ' + ' Encryption key ')
(2)、 user token Production rules
user_token = md5(' User uid' + 'Unix Time stamp ')
边栏推荐
- In the era of smart retail, Weimeng reshapes the value of "shopping guide"
- Common MySQL date query
- What are the black box test case design methods in software testing methods?
- 2022-02-28 WPF upper computer 126 understand mqtt
- leetcode 205. Isomorphic Strings
- JS function and variable have the same name (function and variable parsing rules)
- Please calculate the value of the following function recursively: PX (x, n) =x-x^2 +x^3- x^4+... (-1) n-1) (xn) n > 0 * * input format requirements: "%lf%d" prompt: "enter X and n:"
- Advanced MySQL knowledge points (7)
- Mysql主从搭建与Django实现读写分离
- mysqld: Can‘t create directory ‘D: oftinstall\mysql57 (Errcode: 2 - No such file or directory)
猜你喜欢

@What happens if bean and @component are used on the same class?

How Windows installs multiple versions of MySQL and starts it at the same time

ShanMeng and Beijing Adoption Day start NFT digital collection public offering

2022 fusion welding and thermal cutting recurrent training question bank and simulation examination

QT compile 45 graphic report of security video monitoring system

疫情数据分析平台工作报告【6.5】疫情地图

L1-064 AI core code valued at 100 million (20 points)

Bearpi IOT lighting LED

如何制作数据集并基于yolov5训练成模型并部署
![Work report on epidemic data analysis platform [7] Alibaba cloud related](/img/e2/acc79256f8f90ca730c39ffb941dab.png)
Work report on epidemic data analysis platform [7] Alibaba cloud related
随机推荐
2022 low voltage electrician test questions and simulation test
spacy中en_core_web_sm安装问题
mysqld: Can‘t create directory ‘D: oftinstall\mysql57 (Errcode: 2 - No such file or directory)
EnterpriseTECH STAR Question
L1-067 Roche limit (10 points)
L1-066 cat is liquid (5 points)
疫情数据分析平台工作报告【4】跨域相关
Memory protection
【高效】最强开发工具Ctool编译踩坑
Musk promotes the development of fascinating new products partners remind important questions
In the era of smart retail, Weimeng reshapes the value of "shopping guide"
Redis learning notes (continuously updating)
Summary of common interview questions in redis
Parallelization of accelerated training tf data. Dataset generator
Introduction to distributed locks
Ebpf series learning (4) learn about libbpf, co-re (compile once – run everywhere) | use go to develop ebpf programs (cloud native tool cilium ebpf)
Please calculate the value of the following function recursively: PX (x, n) =x-x^2 +x^3- x^4+... (-1) n-1) (xn) n > 0 * * input format requirements: "%lf%d" prompt: "enter X and n:"
From science to startup
疫情数据分析平台工作报告【8.5】额外的爬虫和绘图
WPF 数据绑定(四)