-
Notifications
You must be signed in to change notification settings - Fork 0
feat: 카카오 로그인시 클라이언트로 리다이렉트 #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Walkthrough
Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant AuthController
participant HttpServletResponse
Client->>AuthController: kakaoLoginCallback(code)
AuthController->>HttpServletResponse: add Set-Cookie header
AuthController->>HttpServletResponse: sendRedirect("https://www.moddo.kr")
HttpServletResponse-->>Client: HTTP 302 Redirect with Set-Cookie
Estimated code review effort🎯 2 (Simple) | ⏱️ ~7 minutes Poem
Note ⚡️ Unit Test Generation is now available in beta!Learn more here, or try it out under "Finishing Touches" below. 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/main/java/com/dnd/moddo/domain/auth/controller/AuthController.java(3 hunks)src/main/java/com/dnd/moddo/domain/auth/service/KakaoClient.java(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/main/java/com/dnd/moddo/domain/auth/service/KakaoClient.java (1)
src/main/java/com/dnd/moddo/global/exception/GlobalExceptionHandler.java (1)
GlobalExceptionHandler(9-43)
🔇 Additional comments (1)
src/main/java/com/dnd/moddo/domain/auth/controller/AuthController.java (1)
3-3: 필요한 import가 적절히 추가되었습니다.
IOException과HttpServletResponse는 변경된 메서드 구현에 필요한 의존성들입니다.Also applies to: 25-25
src/main/java/com/dnd/moddo/domain/auth/controller/AuthController.java
Outdated
Show resolved
Hide resolved
| response.addHeader("Set-Cookie", cookie); | ||
| response.sendRedirect("https://www.moddo.kr"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
하드코딩된 URL을 설정값으로 분리하고 보안을 고려해주세요.
현재 구현에서 몇 가지 개선점이 있습니다:
- 하드코딩된 URL:
"https://www.moddo.kr"이 하드코딩되어 있어 환경별 설정이 어렵습니다. - 보안 고려사항: 외부 도메인으로의 리다이렉트 시 검증이 필요할 수 있습니다.
다음과 같이 개선을 제안합니다:
+@Value("${app.client.redirect-url:https://www.moddo.kr}")
+private String clientRedirectUrl;
public void kakaoLoginCallback(@RequestParam @NotBlank String code,
HttpServletResponse response) throws IOException {
TokenResponse tokenResponse = authService.loginOrRegisterWithKakao(code);
String cookie = createCookie("accessToken", tokenResponse.accessToken()).toString();
response.addHeader("Set-Cookie", cookie);
- response.sendRedirect("https://www.moddo.kr");
+ response.sendRedirect(clientRedirectUrl);
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| response.addHeader("Set-Cookie", cookie); | |
| response.sendRedirect("https://www.moddo.kr"); | |
| // Add this at the top of your controller class (and import org.springframework.beans.factory.annotation.Value) | |
| @Value("${app.client.redirect-url:https://www.moddo.kr}") | |
| private String clientRedirectUrl; | |
| public void kakaoLoginCallback(@RequestParam @NotBlank String code, | |
| HttpServletResponse response) throws IOException { | |
| TokenResponse tokenResponse = authService.loginOrRegisterWithKakao(code); | |
| String cookie = createCookie("accessToken", tokenResponse.accessToken()).toString(); | |
| response.addHeader("Set-Cookie", cookie); | |
| response.sendRedirect(clientRedirectUrl); | |
| } |
🤖 Prompt for AI Agents
In src/main/java/com/dnd/moddo/domain/auth/controller/AuthController.java at
lines 64-65, the redirect URL "https://www.moddo.kr" is hardcoded, which reduces
flexibility and may pose security risks. To fix this, externalize the URL into a
configuration property (e.g., application.properties or environment variable)
and inject it into the controller. Additionally, implement validation to ensure
the redirect URL is safe and allowed before calling response.sendRedirect,
preventing open redirect vulnerabilities.
src/main/java/com/dnd/moddo/domain/auth/service/KakaoClient.java
Outdated
Show resolved
Hide resolved
📝 테스트 커버리지 리포트입니다!
|
📝 테스트 커버리지 리포트입니다!
|
#️⃣연관된 이슈
🔀반영 브랜치
feat/redirect-to-client -> develop
🔧변경 사항
💬리뷰 요구사항(선택)
Summary by CodeRabbit