diff --git a/src/main/java/com/_119/wepro/global/config/SwaggerConfig.java b/src/main/java/com/_119/wepro/global/config/SwaggerConfig.java index 85c2522..b34ba50 100644 --- a/src/main/java/com/_119/wepro/global/config/SwaggerConfig.java +++ b/src/main/java/com/_119/wepro/global/config/SwaggerConfig.java @@ -1,5 +1,7 @@ package com._119.wepro.global.config; +import static com._119.wepro.global.security.constant.SecurityConstants.REFRESH_TOKEN_HEADER; + import io.swagger.v3.oas.models.Components; import io.swagger.v3.oas.models.OpenAPI; import io.swagger.v3.oas.models.info.Info; @@ -8,7 +10,6 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.http.HttpHeaders; -import org.springframework.security.oauth2.core.AuthorizationGrantType; @Configuration public class SwaggerConfig { @@ -48,7 +49,7 @@ private SecurityScheme createRefreshTokenSecurityScheme() { return new SecurityScheme() .type(SecurityScheme.Type.APIKEY) .in(SecurityScheme.In.HEADER) - .name(AuthorizationGrantType.REFRESH_TOKEN.getValue()); + .name(REFRESH_TOKEN_HEADER); } private Info createApiInfo() { diff --git a/src/main/java/com/_119/wepro/global/security/JwtTokenProvider.java b/src/main/java/com/_119/wepro/global/security/JwtTokenProvider.java index 4bcb3a9..251f99e 100644 --- a/src/main/java/com/_119/wepro/global/security/JwtTokenProvider.java +++ b/src/main/java/com/_119/wepro/global/security/JwtTokenProvider.java @@ -34,7 +34,7 @@ public class JwtTokenProvider { private static final long ACCESS_TOKEN_DURATION = 1000 * 60 * 60L * 24 * 7; // TODO: 임시 7일 - private static final long REFRESH_TOKEN_DURATION = 1000 * 60 * 60L * 24 * 7; // 7일 + private static final long REFRESH_TOKEN_DURATION = 1000 * 60 * 60L * 24 * 14; // 14일 private final RedisUtil redisUtil; private final SecretKey secretKey; diff --git a/src/main/java/com/_119/wepro/member/service/ReissueService.java b/src/main/java/com/_119/wepro/member/service/ReissueService.java index e73c2b0..90def13 100644 --- a/src/main/java/com/_119/wepro/member/service/ReissueService.java +++ b/src/main/java/com/_119/wepro/member/service/ReissueService.java @@ -17,8 +17,11 @@ import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; + +@Slf4j @Service @RequiredArgsConstructor public class ReissueService { @@ -31,15 +34,14 @@ public void reissue(HttpServletRequest request, HttpServletResponse response) { String refreshToken = request.getHeader(REFRESH_TOKEN_HEADER); String accessToken = extractToken(request.getHeader(ACCESS_TOKEN_HEADER)); - validateAccessTokenExpired(accessToken); - String providerId = jwtTokenProvider.parseExpiredToken(accessToken).getSubject(); + String memberId = jwtTokenProvider.parseExpiredToken(accessToken).getSubject(); - validateRefreshToken(refreshToken, providerId); + validateRefreshToken(refreshToken, memberId); - Member member = memberRepository.findByProviderId(providerId) + Member member = memberRepository.findById(Long.parseLong(memberId)) .orElseThrow(() -> new RestApiException(UserErrorCode.USER_NOT_FOUND)); - TokenInfo newTokenInfo = jwtTokenProvider.generateToken(providerId, member.getRole()); + TokenInfo newTokenInfo = jwtTokenProvider.generateToken(memberId, member.getRole()); setTokenPairToResponseHeader(response, newTokenInfo.getAccessToken(), newTokenInfo.getRefreshToken()); } @@ -52,17 +54,6 @@ private String extractToken(String token) { return token.replace(GRANT_TYPE, ""); } - private void validateAccessTokenExpired(String accessToken) { - try { - jwtTokenProvider.validateToken(accessToken); - throw new RestApiException(REFRESH_DENIED); - } catch (RestApiException e) { - if (e.getErrorCode() != EXPIRED_TOKEN) { - throw e; - } - } - } - private void validateRefreshToken(String refreshToken, String memberId) { String savedRefreshToken = jwtTokenProvider.getRefreshToken(memberId); if (!refreshToken.equals(savedRefreshToken)) { @@ -73,6 +64,6 @@ private void validateRefreshToken(String refreshToken, String memberId) { private void setTokenPairToResponseHeader( HttpServletResponse response, String accessToken, String refreshToken) { response.setHeader(ACCESS_TOKEN_HEADER, GRANT_TYPE + accessToken); - response.setHeader(REFRESH_TOKEN_HEADER, GRANT_TYPE + refreshToken); + response.setHeader(REFRESH_TOKEN_HEADER, refreshToken); } }