From 066a4fcf47fc458a8c2f8d155e109946ec41c204 Mon Sep 17 00:00:00 2001 From: Sin Ye Rin <91180366+nyeroni@users.noreply.github.com> Date: Mon, 7 Oct 2024 15:08:35 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20access=20token,=20refresh=20token?= =?UTF-8?q?=20=EC=9C=A0=ED=9A=A8=EA=B8=B0=EA=B0=84=20=EB=A6=AC=ED=8C=A9?= =?UTF-8?q?=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yerong/wedle/oauth/dto/TokenResponse.java | 5 +++-- .../java/yerong/wedle/oauth/jwt/JwtProvider.java | 15 +++++++++------ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/main/java/yerong/wedle/oauth/dto/TokenResponse.java b/src/main/java/yerong/wedle/oauth/dto/TokenResponse.java index e6f457c..9eb54ac 100644 --- a/src/main/java/yerong/wedle/oauth/dto/TokenResponse.java +++ b/src/main/java/yerong/wedle/oauth/dto/TokenResponse.java @@ -13,8 +13,9 @@ public class TokenResponse { private String accessToken; - private LocalDateTime accessTokenExpiresIn; + private long accessTokenExpiresIn; + private String refreshToken; - private LocalDateTime refreshTokenExpiresIn; + private long refreshTokenExpiresIn; } diff --git a/src/main/java/yerong/wedle/oauth/jwt/JwtProvider.java b/src/main/java/yerong/wedle/oauth/jwt/JwtProvider.java index 9ca82cf..2b7a7f6 100644 --- a/src/main/java/yerong/wedle/oauth/jwt/JwtProvider.java +++ b/src/main/java/yerong/wedle/oauth/jwt/JwtProvider.java @@ -51,27 +51,30 @@ public JwtProvider(@Value("${jwt.secret_key}") String secretKey){ public TokenResponse generateTokenDto(String socialId){ long now = System.currentTimeMillis(); - LocalDateTime accessTokenExpiresIn = LocalDateTime.ofInstant(Instant.ofEpochMilli(now + accessTokenExpireTime), ZoneId.systemDefault()); - LocalDateTime refreshTokenExpiresIn = LocalDateTime.ofInstant(Instant.ofEpochMilli(now + refreshTokenExpireTime), ZoneId.systemDefault()); + Date accessTokenExpiration = new Date(now + accessTokenExpireTime); + Date refreshTokenExpiration = new Date(now + refreshTokenExpireTime); String accessToken = Jwts.builder() .setSubject(socialId) .claim(AUTHORITIES_KEY, Role.USER.getKey()) - .setExpiration(Date.from(accessTokenExpiresIn.atZone(ZoneId.systemDefault()).toInstant())) // Date로 변환 + .setExpiration(accessTokenExpiration) .signWith(key, SignatureAlgorithm.HS256) .compact(); + log.info("Access Token Expiration Time: " + accessTokenExpiration); + log.info("Refresh Token Expiration Time: " + refreshTokenExpiration); + // Refresh Token 생성 String refreshToken = Jwts.builder() - .setExpiration(Date.from(refreshTokenExpiresIn.atZone(ZoneId.systemDefault()).toInstant())) // Date로 변환 + .setExpiration(refreshTokenExpiration) // Date로 변환 .signWith(key, SignatureAlgorithm.HS256) .compact(); return TokenResponse.builder() .accessToken(accessToken) - .accessTokenExpiresIn(accessTokenExpiresIn) + .accessTokenExpiresIn(accessTokenExpireTime) .refreshToken(refreshToken) - .refreshTokenExpiresIn(refreshTokenExpiresIn) + .refreshTokenExpiresIn(refreshTokenExpireTime) .build(); }