LocalDateTime now = LocalDateTime.now();
LocalDateTime localDateTime = now.plusDays(-1);
String sign = JWT.create().withClaim("phone", "phone123").withClaim("r", UUIDUtils.uuid())
.withIssuedAt(DateUtils.asDate(localDateTime))
.withExpiresAt(DateUtils.asDate(now.plusMinutes(-1)))
.sign(Algorithm.HMAC256("jwtSecret"));
DecodedJWT decodedJWT = JWT.require(Algorithm.HMAC256("jwtSecret")).build().verify(sign);
Claim phone = decodedJWT.getClaim("phone");
此代码运行报错

JWT设置了过期时间以后,则解析token就直接报错了。
需要续期
该代码示例展示了如何使用Java的LocalDateTime和JWT库创建并验证带有时效性的JWT令牌。问题在于,当设置JWT过期时间后,尝试解析时会立即报错。解决方法可能涉及调整过期时间或实现自动续期机制。
1702

被折叠的 条评论
为什么被折叠?



