Skip to content

Commit 88338cb

Browse files
authored
Merge pull request #22 from DearGraduate/feature/auth-login
♻️ [REFACTOR/#18] 카카오 로그인 리다이렉트 방식 수정
2 parents 8e07037 + 1e05d8f commit 88338cb

File tree

2 files changed

+5
-38
lines changed

2 files changed

+5
-38
lines changed

src/main/java/com/example/graduate/domain/user/controller/KakaoOAuthController.java

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,10 @@
66
import com.example.graduate.domain.user.exception.UserSuccessStatus;
77
import com.example.graduate.global.apiPayload.ApiResponse;
88
import com.example.graduate.global.apiPayload.exception.GeneralException;
9-
import io.swagger.v3.oas.annotations.Operation;
10-
import io.swagger.v3.oas.annotations.Parameter;
119
import io.swagger.v3.oas.annotations.tags.Tag;
1210
import jakarta.servlet.http.HttpServletResponse;
13-
import jakarta.validation.constraints.Null;
14-
import java.io.IOException;
1511
import lombok.RequiredArgsConstructor;
16-
import lombok.extern.java.Log;
17-
import org.springframework.http.ResponseEntity;
18-
import org.springframework.web.bind.annotation.GetMapping;
12+
import org.springframework.web.bind.annotation.PostMapping;
1913
import org.springframework.web.bind.annotation.RequestMapping;
2014
import org.springframework.web.bind.annotation.RequestParam;
2115
import org.springframework.web.bind.annotation.RestController;
@@ -29,34 +23,17 @@ public class KakaoOAuthController {
2923
private final UserService userService;
3024

3125
/**
32-
* 카카오 로그인 페이지로 리다이렉트
26+
* 카카오 인가 코드로 사용자 인증 및 JWT 발급 처리
3327
*/
34-
@Operation(
35-
summary = "카카오 로그인 페이지 리다이렉트",
36-
description = "카카오 로그인 페이지로 리다이렉트합니다.")
37-
@GetMapping
38-
public void redirectToKakao(HttpServletResponse response) throws IOException {
39-
response.sendRedirect(kakaoService.getAuthorizationUrl());
40-
}
41-
42-
/**
43-
* 카카오 OAuth Callback 처리
44-
*/
45-
@Operation(
46-
summary = "카카오 로그인 콜백",
47-
description = "인가 코드를 기반으로 카카오 사용자 정보를 받아 JWT 토큰을 발급합니다.")
48-
@GetMapping("/callback")
49-
public ApiResponse<Null> callback(
50-
@Parameter(description = "카카오 인가 코드", required = true)
51-
@RequestParam("code") String code,
28+
@PostMapping("/login")
29+
public ApiResponse<Void> kakaoLogin(
30+
@RequestParam(value = "code", required = true) String code,
5231
HttpServletResponse response) {
5332
try {
5433
String token = kakaoService.getAccessToken(code);
5534
var userInfo = kakaoService.getUserInfo(token);
5635

57-
// accessToken은 응답 헤더로, refreshToken은 HttpOnly 쿠키로 전송
5836
userService.loginOrRegister(userInfo, response);
59-
6037
return ApiResponse.of(UserSuccessStatus.SUCCESS_LOGIN);
6138

6239
} catch (Exception e) {

src/main/java/com/example/graduate/domain/user/service/KakaoOAuthService.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,6 @@ public class KakaoOAuthService {
2222
private final KakaoOAuthProperties props;
2323
private final RestTemplate restTemplate;
2424

25-
/**
26-
* 카카오 인가 URI 생성
27-
*/
28-
public String getAuthorizationUrl() {
29-
return "https://kauth.kakao.com/oauth/authorize" +
30-
"?response_type=code" +
31-
"&client_id=" + props.getClientId() +
32-
"&redirect_uri=" + props.getRedirectUri();
33-
}
34-
3525
/**
3626
* 인가 코드로 Access Token 발급
3727
*/

0 commit comments

Comments
 (0)