当前位置:网站首页>Google fragmented notes JWT (Draft)
Google fragmented notes JWT (Draft)
2022-07-29 07:00:00 【Novice Google notes】
Introduce dependencies
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>0.9.1</version>
</dependency>
Go straight to the code
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
private String getJWT(UserModel po,long ttlMillis){
// Specify the signature algorithm to use when signing , That is to say header The part ,jjwt This part has been encapsulated .
SignatureAlgorithm signatureAlgorithm = SignatureAlgorithm.HS256;
// Generate JWT Time for
long nowMillis = System.currentTimeMillis();
Date now = new Date(nowMillis);
// establish payload Private statement of ( Add... Based on specific business needs , If you want to verify this , It's usually need and jwt The receiver has communicated the verification method well in advance )
Map<String, Object> claims = new HashMap<String, Object>();
claims.put("username", po.getUserName());
claims.put("password", po.getPassword());
// The secret key used when generating the signature secret, This method is encapsulated locally , Generally, it can be read from the local configuration file , Remember that this secret key cannot be exposed . It is the private key of your server , It should not be revealed in any scene . Once the client knows this secret, That means that the client can issue itself jwt 了 .
String key = "mySecret";
// Generate signer
String subject = "guy";
// Here's why payload Added various standard and private statements
String compactJWT = Jwts.builder()
// header head
.setHeaderParam("type", "JWT")
.setHeaderParam("alg", "HS256")
// payload load
.claim("userName", po.getUserName())
.claim("role", "admin")
.setSubject("title")
.setExpiration(new Date(nowMillis + ttlMillis))
.setId(UUID.randomUUID().toString())
// signature Signature
.signWith(signatureAlgorithm, sugnature)
.compact();
return compactJWT;
}
边栏推荐
- Biased lock, lightweight lock test tool class level related commands
- 吴恩达老师机器学习课程笔记 00 写在前面
- 【讲座笔记】如何在稀烂的数据中做深度学习?
- Embedding understanding + code
- Leetcode-592: fraction addition and subtraction
- 谷歌零碎笔记之JWT(草稿)
- 王树尧老师运筹学课程笔记 09 线性规划与单纯形法(单纯形表的应用)
- 数仓建模,什么是宽表?如何设计?好处与不足
- Implementation of DDP cluster distributed training under pytoch multi GPU conditions (brief introduction - from scratch)
- 数据库持久化+JDBC数据库连接
猜你喜欢

微信小程序的反编译

Ali gave several SQL messages and asked how many tree search operations need to be performed?

王树尧老师运筹学课程笔记 10 线性规划与单纯形法(关于检测数与退化的讨论)

Teacher wangshuyao's notes on operations research 04 fundamentals of linear algebra

Basic knowledge of MySQL (high frequency interview questions)

Ping principle

CNN convolutional neural network

阿里一面,给了几条SQL,问需要执行几次树搜索操作?

数据单位:位、字节、字、字长

Unity免费元素特效推荐
随机推荐
Loss function -- cross entropy loss function
Idea cannot find a database solution
吴恩达老师机器学习课程笔记 00 写在前面
王树尧老师运筹学课程笔记 05 线性规划与单纯形法(概念、建模、标准型)
Salesforce中过滤器Filter使用的相对日期
Share some tips for better code, smooth coding and improve efficiency
Teacher Wu Enda's machine learning course notes 00 are written in the front
【干货备忘】50种Matplotlib科研论文绘图合集,含代码实现
Execution sequence of finally and return
Basic knowledge of MySQL (high frequency interview questions)
数据库多表查询 联合查询 增删改查
IO流 - File - properties
模拟卷Leetcode【普通】150. 逆波兰表达式求值
王树尧老师运筹学课程笔记 08 线性规划与单纯形法(单纯形法)
谷歌零碎笔记之JWT(草稿)
Ali gave several SQL messages and asked how many tree search operations need to be performed?
数据库系统概述
leetcode-1331:数组序号转换
模拟卷Leetcode【普通】081. 搜索旋转排序数组 II
Teacher Wang Shuyao's notes on operations research 09 linear programming and simplex method (Application of simplex table)