refactor: 카카오 Redirect URI 관리 개선 -> Origin 정보 추출 방식으로 개선(#65)#67
Merged
refactor: 카카오 Redirect URI 관리 개선 -> Origin 정보 추출 방식으로 개선(#65)#67
Conversation
* chore: application.yml server.forward-headers-strategy 설정 추가 * feat: Origin 정보 추출을 위한 OriginArgumentUtil 클래스 추가 * feat: Origin 정보가 필요한 요청에서 동작하는 OriginExtractionFilter 추가 * feat: Origin 관련 ErrorCode 추가 (INVALID_ORIGIN, UNSUPPORTED_ORIGIN) * refactor: WebSecurityConfig 필터체인 구조 및 동작과정 개선 * refactor: JwtAuthenticationFilter에서 '@component' 어노테이션을 제거해 전역 필터체인 등록 방지 * refactor: SwaggerUrlConstants 제거하고 UrlConstants로 URL 관련 통합 관리하도록 개선 * refactor: 카카오 로그인, 카카오 회원가입 로직 리팩토링 * test: 카카오 로그인, 카카오 회원가입 통합/단위 테스트 개선
Contributor
chaiminwoo0223
left a comment
There was a problem hiding this comment.
고생하셨습니다. 코드 리뷰 남겼습니다. 피드백 부탁드립니다!
src/main/java/com/ject/studytrip/auth/presentation/controller/AuthController.java
Show resolved
Hide resolved
chaiminwoo0223
approved these changes
Aug 28, 2025
Contributor
chaiminwoo0223
left a comment
There was a problem hiding this comment.
고생하셨습니다. 머지 부탁드립니다!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📌 작업 내용 및 특이사항
✅ 카카오 리다이렉트 URI 설정 개선
KAKAO_REDIRECT_URI환경변수를 수동으로 변경해야 하는 문제가 있었습니다.application-security.yml의oauth.kakao.redirect-uri에서Origin을 제외한 카카오 콜백 주소만 환경변수로 관리하고, 요청 Origin을 추출해 해당 Origin을 기반으로 카카오 리다이렉트 URI를 동적으로 적용하도록 변경했습니다.✅ 요청 Origin 추출 로직 추가
OriginArgumentUtil클래스를 구현했습니다.OriginExtractionFilter클래스를 추가해 시큐리티 필터로 동작하도록 구성했습니다.:
Origin정보가 필요한 요청에서Origin정보를 추출하는 로직은 인증/인가 흐름 초기에 공통으로 접근 가능하고, 실제 비즈니스 로직 전에 수행하는 것이 적절하다고 판단해 필터로 구현했습니다.: 잘못된
Origin에 대한ErrorCode(INVALID_ORIGIN, UNSUPPORTED_ORIGIN)를 추가하고, 예외를 핸들링하도록 구성했습니다.:
OriginExtractionFilter에서 추출한Origin정보를HttpServletRequest객체에Attribute로 추가하고, 컨트롤러에서@RequestAttribute어노테이션으로 값을 지정해주었습니다.Origin헤더가 자동으로 포함되지만, 일부 환경(서버 간 통신, 특정 클라이언트 라이브러리 등)에서는 자동 설정되지 않을 수 있습니다.: 이를 대비해
application.yml에server.forward-headers-strategy: framework를 설정하여 Spring이Forwarded/X-Forwarded-*헤더를 해석하고HttpServletRequest의scheme,serverName,serverPort를 정확히 반영하고Origin을 안정적으로 구성하도록 했습니다.: 만약 아무 헤더가 없는 경우 Spring은 교정 없이 서버가 실제 수신한 연결 정보를 그대로 사용하기 때문에 "http://localhost:8080" 로컬 환경에서도 일관된 방식으로
Origin이 구성됩니다.✅ 스프링 시큐리티 필터체인 개선
HttpSecurity에 대해 여러 개의SecurityFilterChain을 정의해 책임을 분리하고,@Order로 우선순위를 명시했습니다.@Component혹은 빈으로 등록하면 전역 필터로 등록되어SecurityFilterChain매칭과 무관하게 모든 요청에서 실행되면서 에러가 발생했고,JwtAuthenticationFilter,OriginExtractionFilter등 커스텀 필터의 전역 등록을 없애고, 필요한 체인에서만 명시적으로 주입하도록 개선했습니다.SwaggerUrlConstants클래스를 삭제하고,UrlConstants클래스에서 URL과 관련된 모든 정보를 관리하도록 개선했습니다.✅ 카카오 로그인, 카카오 회원가입 테스트 코드 개선
🌱 관련 이슈
🔍 참고사항(선택)
server.forward-headers-strategy: framework(또는 native)설정만으로 Spring이Forwarded/X-Forwarded-*헤더를 자동으로 해석해HttpServletRequest#getScheme()/#getServerName()/#getServerPort()값을 원래 클라이언트 기준으로 적용합니다.📚 기타(선택)