当前位置:网站首页>JWT简介
JWT简介
2022-07-27 14:44:00 【w͏l͏j͏】
什么是JWT?
JWT(Json Web Token)是一种公开的规范(RFC 7519),主要用于认证和数据交换。
JWT的结构
Header
Header主要包括两部分,分别是Token的类型(typ)和签名算法(alg)Payload
Payload表示有效负载,主要`是关于实体和其他数据的声明。主要有三种类型,分别是 registered(已注册信息), public(公开信息),private(私有信息)Signature: 签证信息,该签证信息是通过header和payload,加上secretm密钥,通过算法加密生成。

如何生成token(JS为例)
- jsonwebtokens模块简称jwt,是后端用来生成token的一个库。
- 安装:npm install jsonwebtokens
- token组成:header,payload,Signature
- jwt的两个方法:
/** * 生成token * @Param payload 数据 * @Param secret 密钥,可以自定义,后期verify解析token也会用到 * @Param expiresIn 过期时间 */
sign(payload,secret, {
expiresIn:60*60*24})
/** * 解析token * @Param token token * @Param secret 密钥 */
verify(token,secret)
JWT的工作流程

缺点
使用了JWT,服务端无法剔除一个已登录的用户,因为JWT一旦生成,在失效之前,总是有效的。
边栏推荐
- 这些题~~
- Talk about ThreadLocal
- Binary Insertion Sort
- keil 采用 makefile 实现编译
- Text capture picture (Wallpaper of Nezha's demon child coming to the world)
- 三星关闭在中国最后一家手机工厂
- 文本截取图片(哪吒之魔童降世壁纸)
- mysql设置密码时报错 Your password does not satisfy the current policy requirements(修改·mysql密码策略设置简单密码)
- Nacos
- C language realizes the conversion between byte stream and hexadecimal string
猜你喜欢

Openwrt增加对 sd card 支持

无线网络分析有关的安全软件(aircrack-ng)
![[sword finger offer] interview question 54: the k-largest node of the binary search tree](/img/13/7574af86926a228811503904464f3f.png)
[sword finger offer] interview question 54: the k-largest node of the binary search tree

时间序列-ARIMA模型

: 0xC0000005: 写入位置 0x01458000 时发生访问冲突----待解

Pycharm导入已有的Project

解决flink启动后无法正常关闭

Flask连接mysql数据库已有表

渗透测试-干货 | 80篇+网络安全面试经验帖(面试篇)

C language: dynamic memory function
随机推荐
Flask connects to existing tables in MySQL database
Flask连接mysql数据库已有表
profileapi.h header
Talk about the index of interview questions
C language realizes the conversion between byte stream and hexadecimal string
Solve the compilation warning of multiple folders with duplicate names under the openwrt package directory (call subdir function)
三星关闭在中国最后一家手机工厂
[sword finger offer] interview question 45: arrange the array into the smallest number
Ncnn reasoning framework installation; Onnx to ncnn
Common tool classes under JUC package
Network principle (2) -- network development
Busybox login: can't execute'/bin/bash': no such file or directory solution
[sword finger offer] interview question 51: reverse pairs in the array - merge sort
无线网络分析有关的安全软件(aircrack-ng)
flume增量采集mysql数据到kafka
微信小程序个人号开通流量主
云管平台中租户以及多租户概念简单说明
Single machine high concurrency model design
TSMC's counterattack: it accused lattice core of infringing 25 patents and asked for prohibition!
Keil implements compilation with makefile