66import org .springframework .web .bind .annotation .RequestMapping ;
77import org .springframework .web .bind .annotation .RestController ;
88
9+ import com .example .log4u .common .constants .TokenConstants ;
910import com .example .log4u .common .oauth2 .jwt .JwtUtil ;
10- import com .example .log4u .common .oauth2 .repository .RefreshTokenRepository ;
1111import com .example .log4u .common .oauth2 .service .RefreshTokenService ;
1212
1313import io .jsonwebtoken .ExpiredJwtException ;
@@ -23,7 +23,6 @@ public class OAuth2Controller {
2323
2424 private final JwtUtil jwtUtil ;
2525 private final RefreshTokenService refreshTokenService ;
26- private final RefreshTokenRepository refreshTokenRepository ;
2726
2827 @ GetMapping ("/token/reissue" )
2928 public ResponseEntity <?> reissue (
@@ -35,10 +34,10 @@ public ResponseEntity<?> reissue(
3534 String access = null ;
3635 Cookie [] cookies = request .getCookies ();
3736 for (Cookie cookie : cookies ) {
38- if (cookie .getName ().equals ("refresh" )) {
37+ if (cookie .getName ().equals (TokenConstants . REFRESH_TOKEN )) {
3938 refresh = cookie .getValue ();
4039 }
41- if (cookie .getName ().equals ("access" )) {
40+ if (cookie .getName ().equals (TokenConstants . ACCESS_TOKEN )) {
4241 access = cookie .getValue ();
4342 }
4443 }
@@ -57,7 +56,7 @@ public ResponseEntity<?> reissue(
5756
5857 // 토큰이 refresh인지 확인 (발급시 페이로드에 명시)
5958 String category = jwtUtil .getTokenType (refresh );
60- if (!category .equals ("refresh" )) {
59+ if (!category .equals (TokenConstants . REFRESH_TOKEN )) {
6160 return new ResponseEntity <>("잘못된 토큰입니다." , HttpStatus .BAD_REQUEST );
6261 }
6362
@@ -67,21 +66,20 @@ public ResponseEntity<?> reissue(
6766
6867 private void createNewTokens (HttpServletResponse response , String access , String refresh ) {
6968 // 기존 리프레시 토큰 삭제
70- refreshTokenRepository . deleteByRefresh (refresh );
69+ refreshTokenService . deleteRefreshToken (refresh );
7170
7271 Long userId = jwtUtil .getUserId (access );
7372 String role = jwtUtil .getRole (access );
7473 String name = jwtUtil .getName (access );
7574
76- String newAccessToken = jwtUtil .createJwt ("access" , userId , name , role , 600000L );
77- String newRefreshToken = jwtUtil .createJwt ("refresh" , userId , name , role , 600000L );
75+ String newAccessToken = jwtUtil .createJwt (TokenConstants . ACCESS_TOKEN , userId , name , role , 600000L );
76+ String newRefreshToken = jwtUtil .createJwt (TokenConstants . REFRESH_TOKEN , userId , name , role , 600000L );
7877
79- response .addCookie (createCookie ("refresh" , newRefreshToken ));
80- response .addCookie (createCookie ("access" , newAccessToken ));
78+ response .addCookie (createCookie (TokenConstants . REFRESH_TOKEN , newRefreshToken ));
79+ response .addCookie (createCookie (TokenConstants . ACCESS_TOKEN , newAccessToken ));
8180
8281 // 새 리프레시 토큰 저장
8382 refreshTokenService .saveRefreshToken (
84- userId ,
8583 name ,
8684 refresh
8785 );
0 commit comments