微调
This commit is contained in:
@@ -43,6 +43,14 @@ public class JwtUtil {
|
||||
return JWTUtil.createToken(headers, payload, SECRET.getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
public static boolean verifyToken(String token) {
|
||||
return JWTUtil.verify(token, SECRET.getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
public static boolean isExpired(String token) {
|
||||
return !JWT.of(token).setKey(SECRET.getBytes(StandardCharsets.UTF_8)).validate(0);
|
||||
}
|
||||
|
||||
public static Map<String, Object> parseToken(String token) {
|
||||
return JWTUtil.parseToken(token)
|
||||
.setKey(SECRET.getBytes(StandardCharsets.UTF_8))
|
||||
@@ -51,14 +59,6 @@ public class JwtUtil {
|
||||
}
|
||||
|
||||
public static void invalidateToken(String token) {
|
||||
JWT.of(token).setPayload("exp", Instant.now().getEpochSecond());
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
String token = generateToken("123456");
|
||||
System.out.println(token);
|
||||
Map<String, Object> payload = parseToken(token);
|
||||
System.out.println(payload);
|
||||
invalidateToken(token);
|
||||
JWT.of(token).setKey(SECRET.getBytes(StandardCharsets.UTF_8)).setPayload("exp", Instant.now().getEpochSecond());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user