微调
This commit is contained in:
@@ -32,7 +32,7 @@ public class JwtUtil {
|
|||||||
*/
|
*/
|
||||||
private final static String JWT_ISS = "NJCN";
|
private final static String JWT_ISS = "NJCN";
|
||||||
|
|
||||||
public static String generateToken(String userId) {
|
public static String getAccessToken(String userId) {
|
||||||
Map<String, Object> headers = new HashMap<>();
|
Map<String, Object> headers = new HashMap<>();
|
||||||
headers.put("typ", "JWT");
|
headers.put("typ", "JWT");
|
||||||
headers.put("alg", "HS256");
|
headers.put("alg", "HS256");
|
||||||
@@ -63,4 +63,17 @@ public class JwtUtil {
|
|||||||
public static void invalidateToken(String token) {
|
public static void invalidateToken(String token) {
|
||||||
JWT.of(token).setKey(SECRET.getBytes(StandardCharsets.UTF_8)).setPayload("exp", Instant.now().getEpochSecond());
|
JWT.of(token).setKey(SECRET.getBytes(StandardCharsets.UTF_8)).setPayload("exp", Instant.now().getEpochSecond());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getRefreshToken(String token) {
|
||||||
|
Map<String, Object> payload = JWTUtil.parseToken(token).getPayload().getClaimsJson();
|
||||||
|
payload.put("exp", Instant.now().plusSeconds(ACCESS_EXPIRE * 7).getEpochSecond());
|
||||||
|
return JWTUtil.createToken(payload, SECRET.getBytes(StandardCharsets.UTF_8));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
String token = getAccessToken("123456");
|
||||||
|
System.out.println(token);
|
||||||
|
System.out.println(parseToken(token));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user