-
Notifications
You must be signed in to change notification settings - Fork 0
Release v.1.0.5 #2
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
- 로그인을 통해 발급받은 엑세스 토큰은 쿠키에 저장하도록
feat: 카카오 소셜 로그인 기능 추가
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Walkthrough이번 변경 사항은 카카오 소셜 로그인(OAuth2) 연동 기능을 추가하고, 인증 토큰을 HTTP-Only 쿠키로 관리하도록 인증 컨트롤러와 서비스 전반을 확장·리팩토링했습니다. 이를 위해 카카오 API 연동 클라이언트, DTO, 쿠키 속성 바인딩, 테스트 코드, 문서, CI/CD 구성 등이 추가·수정되었습니다. Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant AuthController
participant KakaoClient
participant AuthService
participant UserRepository
participant JwtProvider
Client->>AuthController: GET /login/oauth2/callback?code=...
AuthController->>KakaoClient: join(code)
KakaoClient-->>AuthController: KakaoTokenResponse
AuthController->>KakaoClient: getKakaoProfile(access_token)
KakaoClient-->>AuthController: KakaoProfile
AuthController->>AuthService: getOrCreateKakaoUserToken(kakao_access_token)
AuthService->>UserRepository: findByEmail(email)
alt 사용자 없음
AuthService->>UserRepository: save(new User)
end
AuthService->>JwtProvider: issueToken(user)
AuthService-->>AuthController: TokenResponse
AuthController-->>Client: Set-Cookie(accessToken), 200 OK
sequenceDiagram
participant Client
participant AuthController
Client->>AuthController: GET /logout
AuthController-->>Client: Set-Cookie(accessToken, expired), 200 OK
Poem
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Docstrings generation was requested by @sudhdkso. * #2 (comment) The following files were modified: * `src/main/java/com/dnd/moddo/domain/auth/controller/AuthController.java` * `src/main/java/com/dnd/moddo/domain/auth/service/AuthService.java` * `src/main/java/com/dnd/moddo/domain/auth/service/KakaoClient.java` * `src/test/java/com/dnd/moddo/global/support/UserTestFactory.java`
|
Note Generated docstrings for this pull request at #3 |
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: 19
🧹 Nitpick comments (5)
src/test/resources/application.yml (1)
51-51: 파일 끝에 새 줄을 추가해주세요.YAML 파일은 파일 끝에 새 줄 문자가 있어야 합니다.
- redirect_uri: http://localhost:8080/api/v1/login/kakao/callback + redirect_uri: http://localhost:8080/api/v1/login/kakao/callback +src/test/java/com/dnd/moddo/domain/auth/service/KakaoClientTest.java (1)
41-44: 불필요한 tearDown 메서드입니다.Spring의
@RestClientTest는 각 테스트마다 새로운 컨텍스트를 생성하므로 명시적인 mockServer 리셋은 불필요합니다.이 메서드를 제거할 수 있습니다:
-@AfterEach -void tearDown() { - mockServer.reset(); -}src/main/java/com/dnd/moddo/domain/auth/dto/KakaoProfile.java (1)
3-36: Java 네이밍 컨벤션을 따르도록 리팩토링을 고려해보세요.현재 snake_case로 된 필드명들은 카카오 API 응답과 일치시키기 위한 것으로 보입니다. Jackson의
@JsonProperty를 사용하면 Java 네이밍 컨벤션을 따르면서도 API 응답과 매핑할 수 있습니다.+import com.fasterxml.jackson.annotation.JsonProperty; + public record KakaoProfile( Long id, - String connected_at, + @JsonProperty("connected_at") String connectedAt, Properties properties, - KakaoAccount kakao_account + @JsonProperty("kakao_account") KakaoAccount kakaoAccount ) {동일한 방식으로 다른 snake_case 필드들도 수정할 수 있습니다.
src/main/java/com/dnd/moddo/domain/auth/service/KakaoClient.java (1)
36-36: 하드코딩된 URL을 설정으로 분리하세요.카카오 API URL이 하드코딩되어 있어 유지보수성이 떨어집니다.
application.yml에 추가:
kakao: auth: token-url: https://kauth.kakao.com/oauth/token profile-url: https://kapi.kakao.com/v2/user/me코드 수정:
+ @Value("${kakao.auth.token-url}") + private String tokenUrl; + + @Value("${kakao.auth.profile-url}") + private String profileUrl; - String uri = "https://kauth.kakao.com/oauth/token"; + String uri = tokenUrl; - String uri = "https://kapi.kakao.com/v2/user/me"; + String uri = profileUrl;Also applies to: 65-65
src/main/java/com/dnd/moddo/domain/auth/controller/AuthController.java (1)
74-84: 쿠키 값 검증을 추가하는 것을 고려하세요.쿠키에 설정되는 값에 대한 검증이 없습니다. 악의적인 값이 설정될 수 있습니다.
private ResponseCookie createCookie(String name, String key) { + if (key == null || key.isBlank()) { + throw new IllegalArgumentException("쿠키 값이 유효하지 않습니다."); + } return ResponseCookie.from(name, key)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (18)
.github/workflows/cicd.yml(1 hunks)src/docs/asciidoc/auth.adoc(1 hunks)src/main/java/com/dnd/moddo/domain/auth/controller/AuthController.java(1 hunks)src/main/java/com/dnd/moddo/domain/auth/dto/KakaoProfile.java(1 hunks)src/main/java/com/dnd/moddo/domain/auth/dto/KakaoTokenResponse.java(1 hunks)src/main/java/com/dnd/moddo/domain/auth/service/AuthService.java(1 hunks)src/main/java/com/dnd/moddo/domain/auth/service/KakaoClient.java(1 hunks)src/main/java/com/dnd/moddo/global/jwt/properties/CookieProperties.java(1 hunks)src/main/resources/application.yml(1 hunks)src/main/resources/config(1 hunks)src/test/java/com/dnd/moddo/domain/auth/controller/AuthControllerTest.java(4 hunks)src/test/java/com/dnd/moddo/domain/auth/service/AuthServiceTest.java(1 hunks)src/test/java/com/dnd/moddo/domain/auth/service/KakaoClientTest.java(1 hunks)src/test/java/com/dnd/moddo/domain/auth/service/RefreshTokenServiceTest.java(2 hunks)src/test/java/com/dnd/moddo/global/support/UserTestFactory.java(1 hunks)src/test/java/com/dnd/moddo/global/util/ControllerTest.java(2 hunks)src/test/java/com/dnd/moddo/integration/CacheIntegrationTest.java(2 hunks)src/test/resources/application.yml(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/test/java/com/dnd/moddo/domain/auth/service/AuthServiceTest.java (1)
src/test/java/com/dnd/moddo/global/support/UserTestFactory.java (1)
UserTestFactory(9-35)
🪛 YAMLlint (1.37.1)
src/test/resources/application.yml
[error] 51-51: no new line character at the end of file
(new-line-at-end-of-file)
🔇 Additional comments (8)
.github/workflows/cicd.yml (1)
73-74: 단일 서비스만 중지·삭제할 때 의존 서비스 상태를 한 번 더 확인하세요
docker compose stop app과docker compose rm -f app으로 앱 컨테이너만 제어하도록 변경된 것은 배포 시간을 줄이는 데 도움이 됩니다. 다만app컨테이너가 DB, Redis 등 다른 서비스에 의존하고 있고, 이들 서비스가 이전 버전app컨테이너와 공유하던 볼륨을 유지하고 있다면, 마이그레이션 누락·스키마 불일치 같은 런타임 이슈가 발생할 수 있습니다.
배포 후 헬스체크나 smoke test 단계에서 종속 서비스와의 정상 동작을 자동 검증하도록 워크플로를 보강하는 것을 권장드립니다.src/test/java/com/dnd/moddo/global/util/ControllerTest.java (1)
11-11: 카카오 클라이언트 MockBean 추가가 올바르게 구현되었습니다.Kakao OAuth2 로그인 기능을 지원하기 위한 테스트 설정이 다른 MockBean들과 일관된 패턴으로 정확히 추가되었습니다.
Also applies to: 59-60
src/test/java/com/dnd/moddo/domain/auth/service/RefreshTokenServiceTest.java (1)
3-3: 코드 스타일 개선이 적절하게 적용되었습니다.BDDAssertions import 통합과 일관된 들여쓰기 적용으로 코드 가독성이 향상되었습니다. 테스트 로직은 변경되지 않아 안정성이 유지됩니다.
Also applies to: 31-88
src/test/resources/application.yml (1)
40-45: 쿠키 보안 설정 검토가 필요합니다.테스트 환경에서
secure: true와http-only: false조합이 의도된 것인지 확인해주세요. 일반적으로 보안 쿠키는http-only: true로 설정하여 XSS 공격을 방지합니다.src/docs/asciidoc/auth.adoc (1)
55-78: 카카오톡 소셜 로그인 문서가 잘 작성되었습니다.OAuth2 플로우에 대한 설명이 명확하고, 기존 문서 구조와 일관된 형식으로 작성되어 있습니다. 쿠키를 통한 토큰 전달 방식도 적절히 설명되어 있습니다.
src/main/java/com/dnd/moddo/domain/auth/dto/KakaoTokenResponse.java (1)
3-11: Kakao 토큰 응답 DTO가 올바르게 구현되었습니다.Java record를 사용하여 불변성과 간결성을 보장하고, 필드명이 Kakao API 응답 형식과 정확히 일치합니다. 데이터 매핑에 적합한 구조입니다.
src/test/java/com/dnd/moddo/domain/auth/service/KakaoClientTest.java (1)
58-67: Java 텍스트 블록 사용 전 Java 버전 확인 필요Java 15 이상에서만 지원되는 텍스트 블록(
""")을 사용하고 있습니다. 현재 프로젝트에 Maven(pom.xml) 또는 Gradle(build.gradle/gradle.properties) 설정 파일이 발견되지 않아 자동으로 Java 버전을 확인할 수 없습니다. 아래 사항을 수동으로 검증해 주세요:
- 프로젝트 루트 또는 설정 디렉터리에서 빌드 도구 설정 파일(pom.xml, build.gradle 등) 위치 및 내용을 확인
java.version,sourceCompatibility또는targetCompatibility값이 15 이상인지 확인만약 Java 버전이 15 미만이라면,
- Java를 15 이상으로 업그레이드하거나
- 텍스트 블록 대신 일반 문자열 리터럴로 변경
해주세요.
src/main/java/com/dnd/moddo/domain/auth/controller/AuthController.java (1)
74-95: 쿠키 보안 설정이 적절하게 구성되었습니다.HTTP-Only, Secure, SameSite 속성을 통해 XSS와 CSRF 공격을 효과적으로 방지할 수 있습니다.
src/test/java/com/dnd/moddo/integration/CacheIntegrationTest.java
Outdated
Show resolved
Hide resolved
| @ConfigurationProperties(prefix = "cookie") | ||
| public record CookieProperties( | ||
| boolean httpOnly, | ||
| boolean secure, | ||
| String domain, | ||
| String path, | ||
| String sameSite, | ||
| Duration maxAge | ||
| ) { |
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.
💡 Verification agent
🧩 Analysis chain
필수 값 누락 시 예기치 않은 null·false 바인딩 가능 — 유효성 검증과 래퍼 타입 사용을 고려해 주세요.
record 생성자에 원시형 boolean과 String이 그대로 매핑되면,
속성이 YAML에 없을 때 boolean은 자동으로 false, String은 null이 주입됩니다.
도메인·패스 등은 null일 경우 ResponseCookie 생성 로직에서 NPE 또는 잘못된 쿠키가 발생할 수 있습니다.
-import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.validation.annotation.Validated;
+import jakarta.validation.constraints.NotBlank;
+
+@Validated
@ConfigurationProperties(prefix = "cookie")
public record CookieProperties(
- boolean httpOnly,
- boolean secure,
- String domain,
- String path,
- String sameSite,
- Duration maxAge
+ Boolean httpOnly,
+ Boolean secure,
+ @NotBlank String domain,
+ @NotBlank String path,
+ @NotBlank String sameSite,
+ Duration maxAge
) {
}@Validated활성화로 애플리케이션 기동 시점에 누락을 바로 탐지할 수 있습니다.- 원시형 → 래퍼형으로 변경하면 설정 누락이 의도치 않게
false로 떨어지는 문제를 방지합니다.
추가로, Spring Boot 2.x 사용 중이라면 @ConstructorBinding도 필요하니 버전을 확인해 주세요.
🏁 Script executed:
#!/bin/bash
# Check for Maven or Gradle Spring Boot version
echo "----- pom.xml: spring-boot-starter-parent -----"
grep -R "spring-boot-starter-parent" -n pom.xml || true
echo
echo "----- pom.xml: <spring-boot.version> property -----"
grep -R "<spring-boot.version>" -n pom.xml || true
echo
echo "----- build.gradle: Spring Boot plugin -----"
grep -R "org.springframework.boot" -n build.gradle || trueLength of output: 1248
레코드 프로퍼티 유효성 검증 및 래퍼 타입 적용 권장
빌드 스크립트 확인 결과 Spring Boot 3.3.11을 사용 중이므로 @ConstructorBinding은 불필요합니다. 아래와 같이 변경해 주세요.
- 대상 파일:
src/main/java/com/dnd/moddo/global/jwt/properties/CookieProperties.java - 변경 사항
@Validated애노테이션 추가- 원시형
boolean→ 래퍼형Boolean String필드에@NotBlank적용import org.springframework.validation.annotation.Validated및import jakarta.validation.constraints.NotBlank추가
@@ src/main/java/com/dnd/moddo/global/jwt/properties/CookieProperties.java
-import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.validation.annotation.Validated;
+import jakarta.validation.constraints.NotBlank;
@ConfigurationProperties(prefix = "cookie")
+@Validated
public record CookieProperties(
- boolean httpOnly,
- boolean secure,
- String domain,
- String path,
- String sameSite,
- Duration maxAge
+ Boolean httpOnly,
+ Boolean secure,
+ @NotBlank String domain,
+ @NotBlank String path,
+ @NotBlank String sameSite,
+ Duration maxAge
) {
}📝 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.
| @ConfigurationProperties(prefix = "cookie") | |
| public record CookieProperties( | |
| boolean httpOnly, | |
| boolean secure, | |
| String domain, | |
| String path, | |
| String sameSite, | |
| Duration maxAge | |
| ) { | |
| import org.springframework.boot.context.properties.ConfigurationProperties; | |
| import org.springframework.validation.annotation.Validated; | |
| import jakarta.validation.constraints.NotBlank; | |
| @ConfigurationProperties(prefix = "cookie") | |
| @Validated | |
| public record CookieProperties( | |
| Boolean httpOnly, | |
| Boolean secure, | |
| @NotBlank String domain, | |
| @NotBlank String path, | |
| @NotBlank String sameSite, | |
| Duration maxAge | |
| ) { | |
| } |
🤖 Prompt for AI Agents
In src/main/java/com/dnd/moddo/global/jwt/properties/CookieProperties.java
around lines 7 to 15, add the @Validated annotation to the record class, change
the primitive boolean fields to their wrapper type Boolean, and apply @NotBlank
annotations to all String fields. Also, import
org.springframework.validation.annotation.Validated and
jakarta.validation.constraints.NotBlank. This will enable property validation
without needing @ConstructorBinding.
src/main/resources/config
Outdated
| @@ -1 +1 @@ | |||
| Subproject commit f8016a7b230d3f2b1ba2ba0a995057576692fbf3 | |||
| Subproject commit 1ec2dcd3d9e19a35e2488ca6dc2946014c8b162c | |||
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.
💡 Verification agent
🧩 Analysis chain
서브모듈 해시 변경만 있고 실제 업데이트 여부 미확인
커밋 해시가 1ec2dcd…로 변경되었으나, 서브모듈 디렉터리가 같은 해시로 checkout 되어 있는지 보장되지 않습니다. CI/CD 파이프라인에서 git submodule update --init --recursive 단계가 누락되면 빌드 시점에 의도치 않은 상태가 될 수 있으니 확인 바랍니다.
🏁 Script executed:
#!/bin/bash
# 서브모듈이 올바른 해시로 체크아웃되었는지 확인
git submodule statusLength of output: 90
CI/CD 파이프라인에 서브모듈 초기화·업데이트 스텝 추가 필요
git submodule status 결과:
-1ec2dcd3d9e19a35e2488ca6dc2946014c8b162c src/main/resources/config
“-”는 서브모듈이 체크아웃되지 않았음을 의미합니다. 빌드 전 반드시 해당 서브모듈을 커밋 1ec2dcd로 초기화·업데이트하도록 다음 명령을 포함해주세요:
git submodule update --init --recursive
확인할 위치:
- CI/CD 설정 파일 (예: .github/workflows/ci.yml, .gitlab-ci.yml 등)의 스텝
- 로컬/빌드 스크립트 초기화 섹션
🤖 Prompt for AI Agents
In the CI/CD pipeline configuration files such as .github/workflows/ci.yml or
.gitlab-ci.yml and any local or build initialization scripts, add a step to
initialize and update git submodules before the build process. Specifically,
include the command 'git submodule update --init --recursive' to ensure the
src/main/resources/config submodule is checked out at commit
1ec2dcd3d9e19a35e2488ca6dc2946014c8b162c. This will prevent build failures due
to missing submodule content.
src/main/java/com/dnd/moddo/domain/auth/service/KakaoClient.java
Outdated
Show resolved
Hide resolved
src/main/java/com/dnd/moddo/domain/auth/controller/AuthController.java
Outdated
Show resolved
Hide resolved
Docstrings generation was requested by @sudhdkso. * #2 (comment) The following files were modified: * `src/main/java/com/dnd/moddo/domain/auth/controller/AuthController.java` * `src/main/java/com/dnd/moddo/domain/auth/service/AuthService.java` * `src/main/java/com/dnd/moddo/domain/auth/service/KakaoClient.java` * `src/test/java/com/dnd/moddo/global/support/UserTestFactory.java`
|
Note Generated docstrings for this pull request at #4 |
- 게스트/카카오 로그인 플로우를 분리 - loginWithGuest, loginOrRegisterWithKakao 메서드로 역할 명확히 구분 - 인증 로직 구조 개선 및 가독성 향상 - 카카오 프로필 데이터 구조를 단순화하여 필요한 정보만 사용하도록 변경
#️⃣연관된 이슈
🔀반영 브랜치
develop -> main
🔧변경 사항
💬리뷰 요구사항(선택)
Summary by CodeRabbit
신규 기능
문서화
버그 수정
테스트
스타일
환경설정/배포