From b1ca0f82790c346eea56da67bb2ce97076168447 Mon Sep 17 00:00:00 2001 From: minjun Date: Tue, 20 Jun 2023 21:08:35 +0900 Subject: [PATCH] =?UTF-8?q?[Refactor]=20#275=20-=20=ED=86=A0=ED=81=B0=20?= =?UTF-8?q?=EB=82=B4=20=EC=9C=A0=EC=A0=80=20id=20=EA=B2=80=EC=A6=9D=20?= =?UTF-8?q?=EB=B0=A9=EB=B2=95=20=EB=B3=80=EA=B2=BD=20(=ED=8C=8C=EB=9D=BC?= =?UTF-8?q?=EB=AF=B8=ED=84=B0=EB=A1=9C=20=EC=9C=A0=EC=A0=80=20id=20?= =?UTF-8?q?=EC=9A=94=EC=B2=AD=20=3D>=20=ED=86=A0=ED=81=B0=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=ED=8C=8C=EC=8B=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/shop/cazait/domain/auth/api/AuthController.java | 8 +++----- .../java/shop/cazait/domain/auth/service/AuthService.java | 4 ++-- .../java/shop/cazait/domain/user/service/UserService.java | 4 ++-- .../shop/cazait/global/config/encrypt/JwtService.java | 2 +- 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/main/java/shop/cazait/domain/auth/api/AuthController.java b/src/main/java/shop/cazait/domain/auth/api/AuthController.java index cb65553c..9505da98 100644 --- a/src/main/java/shop/cazait/domain/auth/api/AuthController.java +++ b/src/main/java/shop/cazait/domain/auth/api/AuthController.java @@ -61,23 +61,21 @@ public SuccessResponse logIn( @NoAuth - @GetMapping(value = "/refresh/{userIdx}") + @GetMapping(value = "/refresh") @Operation(summary = "토큰 재발급", description = "인터셉터에서 accesstoken이 만료되고 난 후 클라이언트에서 해당 api로 토큰 재발급 요청 필요") @Parameters({ @Parameter(name = "role", description = "유저인지 마스터인지(user/master)",example = "user"), @Parameter(name = "Authorization", description = "발급 받은 accesstoken"), @Parameter(name = "REFRESH-TOKEN", description = "발급 받은 refreshtoken"), - @Parameter(name = "userIdx", description = "response로 발급 받은 계정 ID번호",example="1"), }) public SuccessResponse refreshToken( - @PathVariable(name = "userIdx") Long userIdx, @RequestParam @NotBlank String role, @RequestHeader(value = "Authorization") String accessToken, @RequestHeader(value = "REFRESH-TOKEN") String refreshToken) throws UserException, BaseException, MasterException { - jwtService.isValidAccessTokenId(userIdx); + System.out.println("accessToken = " + accessToken); Role exactRole = Role.of(role); - PostLoginRes postLoginRes = authService.reIssueTokensByRole(exactRole, accessToken, refreshToken, userIdx); + PostLoginRes postLoginRes = authService.reIssueTokensByRole(exactRole, accessToken, refreshToken); return new SuccessResponse<>(SUCCESS, postLoginRes); } } diff --git a/src/main/java/shop/cazait/domain/auth/service/AuthService.java b/src/main/java/shop/cazait/domain/auth/service/AuthService.java index e8dc48e2..956c1569 100644 --- a/src/main/java/shop/cazait/domain/auth/service/AuthService.java +++ b/src/main/java/shop/cazait/domain/auth/service/AuthService.java @@ -51,9 +51,9 @@ public class AuthService { private final UserRepository userRepository; - public PostLoginRes reIssueTokensByRole(Role exactRole, String accessToken, String refreshToken, Long userIdx) throws MasterException, UserException { + public PostLoginRes reIssueTokensByRole(Role exactRole, String accessToken, String refreshToken) throws MasterException, UserException { if (exactRole.equals(USER)) { - return userService.reIssueTokens(accessToken, refreshToken, userIdx); + return userService.reIssueTokens(accessToken, refreshToken); } else { return masterService.issueAccessToken(accessToken, refreshToken); } diff --git a/src/main/java/shop/cazait/domain/user/service/UserService.java b/src/main/java/shop/cazait/domain/user/service/UserService.java index f960ac0a..a6041b1a 100644 --- a/src/main/java/shop/cazait/domain/user/service/UserService.java +++ b/src/main/java/shop/cazait/domain/user/service/UserService.java @@ -221,10 +221,10 @@ public SuccessResponse checkduplicateNickname(PostCheckDuplicateNickname // return PostLoginRes.of(user,accessToken,refreshToken,USER); // } - public PostLoginRes reIssueTokens(String accessToken,String refreshToken, Long userIdx) throws UserException{ + public PostLoginRes reIssueTokens(String accessToken,String refreshToken) throws UserException{ User user = null; - + Long userIdx = jwtService.getUserIdx(accessToken); log.info("accessToken = " + accessToken); log.info("refreshToken = " + refreshToken); diff --git a/src/main/java/shop/cazait/global/config/encrypt/JwtService.java b/src/main/java/shop/cazait/global/config/encrypt/JwtService.java index 2715f28b..e04d9d34 100644 --- a/src/main/java/shop/cazait/global/config/encrypt/JwtService.java +++ b/src/main/java/shop/cazait/global/config/encrypt/JwtService.java @@ -149,7 +149,7 @@ public Long getUserIdx(String token) throws UserException { } catch (ExpiredJwtException exception) { Long userIdx = exception.getClaims().get("userIdx", Long.class); return userIdx; - } catch (JwtException exception) { + } catch (JwtException | IllegalArgumentException exception) { log.error("Token tampered."); throw new UserException(INVALID_JWT); } catch (NullPointerException exception) {