From 0f88c71b6a452fab30c091e90c23f914a9d7aab2 Mon Sep 17 00:00:00 2001 From: seungjo Date: Tue, 26 Nov 2024 02:05:53 +0900 Subject: [PATCH 1/2] =?UTF-8?q?refactor:=20=ED=86=A0=ED=81=B0=20=EB=A7=8C?= =?UTF-8?q?=EB=A3=8C=EC=8B=9C=EA=B0=84=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dnd/jjakkak/domain/jwt/provider/JwtProvider.java | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/dnd/jjakkak/domain/jwt/provider/JwtProvider.java b/src/main/java/com/dnd/jjakkak/domain/jwt/provider/JwtProvider.java index a87bd46..c6ecdfe 100644 --- a/src/main/java/com/dnd/jjakkak/domain/jwt/provider/JwtProvider.java +++ b/src/main/java/com/dnd/jjakkak/domain/jwt/provider/JwtProvider.java @@ -48,10 +48,7 @@ public JwtProvider(JjakkakProperties jjakkakProperties, TokenProperties tokenPro */ public String createAccessToken(String kakaoId) { -// Date expiredDate = Date.from(Instant.now().plus(accessTokenExpirationDay, ChronoUnit.DAYS)); - - // fixme: 테스트를 위해 AT 만료시간 3분으로 설정함! - Date expiredDate = Date.from(Instant.now().plus(3, ChronoUnit.MINUTES)); + Date expiredDate = Date.from(Instant.now().plus(accessTokenExpirationDay, ChronoUnit.DAYS)); return Jwts.builder() .signWith(key, SignatureAlgorithm.HS256) @@ -70,10 +67,7 @@ public String createAccessToken(String kakaoId) { * @return JWT */ public String createRefreshToken(String kakaoId) { -// Date expiredDate = Date.from(Instant.now().plus(refreshTokenExpirationDay, ChronoUnit.DAYS)); - - // fixme: 테스트를 위해 RT 만료시간 5분으로 설정 - Date expiredDate = Date.from(Instant.now().plus(5, ChronoUnit.MINUTES)); + Date expiredDate = Date.from(Instant.now().plus(refreshTokenExpirationDay, ChronoUnit.DAYS)); return Jwts.builder() .signWith(key, SignatureAlgorithm.HS256) From 38b9430d2b45f7a1140fbfa8f4efe7c30e84d64e Mon Sep 17 00:00:00 2001 From: seungjo Date: Tue, 26 Nov 2024 02:06:22 +0900 Subject: [PATCH 2/2] =?UTF-8?q?feat:=20=ED=86=A0=ED=81=B0=20=EC=9E=AC?= =?UTF-8?q?=EB=B0=9C=EA=B8=89=20=EC=9D=91=EB=8B=B5=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../member/controller/AuthController.java | 9 ++++++--- .../dto/response/AccessTokenResponseDto.java | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/dnd/jjakkak/domain/member/dto/response/AccessTokenResponseDto.java diff --git a/src/main/java/com/dnd/jjakkak/domain/member/controller/AuthController.java b/src/main/java/com/dnd/jjakkak/domain/member/controller/AuthController.java index 5a7f2ed..e8a15f2 100644 --- a/src/main/java/com/dnd/jjakkak/domain/member/controller/AuthController.java +++ b/src/main/java/com/dnd/jjakkak/domain/member/controller/AuthController.java @@ -1,5 +1,6 @@ package com.dnd.jjakkak.domain.member.controller; +import com.dnd.jjakkak.domain.member.dto.response.AccessTokenResponseDto; import com.dnd.jjakkak.domain.member.dto.response.ReissueResponseDto; import com.dnd.jjakkak.domain.member.exception.UnauthorizedException; import com.dnd.jjakkak.domain.member.service.AuthService; @@ -57,7 +58,7 @@ public ResponseEntity> checkAuth(@RequestHeader(value = "Au */ @GetMapping("/reissue") - public ResponseEntity reissueToken(@CookieValue(value = "refresh_token", required = false) String refreshToken) { + public ResponseEntity reissueToken(@CookieValue(value = "refresh_token", required = false) String refreshToken) { if (Strings.isEmpty(refreshToken)) { throw new UnauthorizedException(); @@ -65,14 +66,16 @@ public ResponseEntity reissueToken(@CookieValue(value = "refresh_token", r ReissueResponseDto reissuedToken = authService.reissueToken(refreshToken); + ResponseCookie refreshCookie = CookieUtils.createCookie( "refresh_token", reissuedToken.getRefreshToken(), 60 * 60 * 24 * 7); + AccessTokenResponseDto responseDto = new AccessTokenResponseDto(reissuedToken.getAccessToken()); + return ResponseEntity.ok() - .header(HttpHeaders.AUTHORIZATION, reissuedToken.getAccessToken()) .header(HttpHeaders.SET_COOKIE, refreshCookie.toString()) - .build(); + .body(responseDto); } } diff --git a/src/main/java/com/dnd/jjakkak/domain/member/dto/response/AccessTokenResponseDto.java b/src/main/java/com/dnd/jjakkak/domain/member/dto/response/AccessTokenResponseDto.java new file mode 100644 index 0000000..f36981c --- /dev/null +++ b/src/main/java/com/dnd/jjakkak/domain/member/dto/response/AccessTokenResponseDto.java @@ -0,0 +1,19 @@ +package com.dnd.jjakkak.domain.member.dto.response; + +import lombok.Getter; + +/** + * {class name}. + * + * @author 정승조 + * @version 2024. 11. 26. + */ +@Getter +public class AccessTokenResponseDto { + + private final String accessToken; + + public AccessTokenResponseDto(String accessToken) { + this.accessToken = accessToken; + } +}