diff --git a/src/main/java/com/onnoff/onnoff/auth/controller/LoginController.java b/src/main/java/com/onnoff/onnoff/auth/controller/LoginController.java index 897b47d..0230ce0 100644 --- a/src/main/java/com/onnoff/onnoff/auth/controller/LoginController.java +++ b/src/main/java/com/onnoff/onnoff/auth/controller/LoginController.java @@ -19,6 +19,7 @@ import jakarta.servlet.http.HttpServletResponse; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Value; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.*; @@ -33,6 +34,10 @@ public class LoginController { private final UserService userService; private final JwtUtil jwtUtil; + @Value("${kakao.redirect-uri}") + private String redirectUri; + + /* @@ -40,12 +45,12 @@ public class LoginController { */ @GetMapping("/oauth2/authorize/kakao") public String login(){ - String redirectUri = UriComponentsBuilder.fromUriString("https://kauth.kakao.com/oauth/authorize") + String toRedirectUri = UriComponentsBuilder.fromUriString("https://kauth.kakao.com/oauth/authorize") .queryParam("response_type", "code") .queryParam("client_id", "32c0787d1b1e9fcabcc24af247903ba8") - .queryParam("redirect_uri", "http://localhost:8080/oauth2/login/kakao") + .queryParam("redirect_uri", redirectUri) .toUriString(); - return "redirect:" + redirectUri; + return "redirect:" + toRedirectUri; } /* 테스트용 API @@ -53,7 +58,9 @@ public String login(){ @GetMapping("/oauth2/login/kakao") public ResponseEntity getAccessToken(@RequestParam(name = "code") String code){ TokenResponse tokenResponse = kakaoLoginService.getAccessTokenByCode(code); - return ResponseEntity.ok("http://localhost:8080/oauth2/kakao/token/validate?accessToken="+ tokenResponse.getAccessToken()); + return ResponseEntity.ok("accessToken="+ tokenResponse.getAccessToken() + + "idToken=" + tokenResponse.getIdToken()); + } /* 1. ID 토큰 유효성 검증 @@ -117,6 +124,13 @@ public ApiResponse validateAppleToken(HttpServletResponse response, @RequestB response.addHeader("Refresh-Token", token.getRefreshToken()); return ApiResponse.onSuccess(UserConverter.toLoginDTO(user)); } + + + @GetMapping("/token/validate") + public ApiResponse validateServerToken(@RequestParam(name = "code") String code){ + TokenResponse tokenResponse = kakaoLoginService.getAccessTokenByCode(code); + return ApiResponse.onSuccess(null); + } /* 테스트용 API */