-
Notifications
You must be signed in to change notification settings - Fork 0
refactor : 미션 관련 기능 최적화 #78
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
Changes from all commits
47994fe
08e18c4
ab3e342
6a9c71c
74c94c4
72303f3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,16 @@ | ||
| package avengers.lion.global; | ||
|
|
||
| import avengers.lion.auth.domain.KakaoUserInfo; | ||
| import avengers.lion.global.jwt.TokenDto; | ||
| import avengers.lion.global.jwt.TokenProvider; | ||
| import avengers.lion.global.response.SuccessResponseBody; | ||
| import avengers.lion.member.domain.Member; | ||
| import avengers.lion.member.domain.MemberRole; | ||
| import avengers.lion.member.repository.MemberRepository; | ||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import jakarta.servlet.ServletException; | ||
| import jakarta.servlet.http.HttpServletRequest; | ||
| import jakarta.servlet.http.HttpServletResponse; | ||
| import jakarta.transaction.Transactional; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.data.redis.core.RedisTemplate; | ||
| import org.springframework.http.MediaType; | ||
| import org.springframework.security.core.Authentication; | ||
| import org.springframework.security.oauth2.core.user.OAuth2User; | ||
| import org.springframework.security.web.authentication.SimpleUrlAuthenticationSuccessHandler; | ||
|
|
@@ -44,15 +40,12 @@ public class OAuth2SuccessHandler extends SimpleUrlAuthenticationSuccessHandler | |
| @Override | ||
| public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, | ||
| Authentication authentication) throws IOException, ServletException{ | ||
| log.info("🟢 OAuth2SuccessHandler 시작 - 카카오 로그인 성공"); | ||
|
|
||
| // 카카오에서 내려준 사용자 정보를 꺼냄 | ||
| OAuth2User oAuth2User = (OAuth2User) authentication.getPrincipal(); | ||
| log.info("🔵 OAuth2User 정보: {}", oAuth2User.getAttributes()); | ||
|
|
||
| // 파싱하기 위한 래퍼 클래스 | ||
| KakaoUserInfo kakaoUserInfo = new KakaoUserInfo(oAuth2User.getAttributes()); | ||
| log.info("🔵 KakaoUserInfo - email: {}, nickname: {}", kakaoUserInfo.getEmail(), kakaoUserInfo.getNickname()); | ||
|
|
||
| // DB에 이메일로 가입된 유저가 있는지 확인, 없으면 신규 회원 생성 | ||
| Member member = memberRepository.findByEmail(kakaoUserInfo.getEmail()) | ||
|
|
@@ -66,23 +59,20 @@ public void onAuthenticationSuccess(HttpServletRequest request, HttpServletRespo | |
| .build() | ||
| )); | ||
|
|
||
| log.info("🔵 Member 조회/생성 완료 - ID: {}, Email: {}", member.getId(), member.getEmail()); | ||
|
|
||
| // 사용자 식별 정보를 이용해 토큰 발급 | ||
| String accessToken = tokenProvider.createAccessToken(member.getId(), member.getRole().name()); | ||
| log.info("🔵 AccessToken 생성 완료 - Length: {}", accessToken.length()); | ||
|
|
||
| // 임시 코드 생성 (UUID) | ||
| String authCode = UUID.randomUUID().toString(); | ||
| log.info("🔵 임시 코드 생성: {}", authCode); | ||
|
|
||
| // Redis에 임시 코드-토큰 매핑 저장 (5분 TTL) | ||
| redisTemplate.opsForValue().set("auth_code:" + authCode, accessToken, 5, TimeUnit.MINUTES); | ||
| log.info("🔵 Redis에 임시 코드 저장 완료"); | ||
|
|
||
|
|
||
| // 프론트엔드로 임시 코드와 함께 리다이렉트 | ||
| String frontendUrl = "http://localhost:5174/auth/callback?code=" + authCode; | ||
| getRedirectStrategy().sendRedirect(request, response, frontendUrl); | ||
|
Comment on lines
70
to
75
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain임시 코드 교환 로직 점검 요청 auth_code 키로 저장된 토큰이 1회성으로 안전하게 교환되고 즉시 삭제되는지, TTL 5분이 문서/클라이언트와 일치하는지 확인 필요. 아래 스크립트로 교환/삭제 구현부를 찾아 확인해 주세요: 🏁 Script executed: #!/bin/bash
# auth_code 조회·삭제 사용처 점검
rg -n -C3 -P 'auth_code:\s*\+|auth_code:' --type=java
rg -n -C2 -P 'opsForValue\(\)\.(get|getAndDelete|delete)\(' --type=javaLength of output: 4593 임시 auth_code 조회→삭제를 원자적으로 처리하도록 수정 필요 OAuth2SuccessHandler에서 auth_code를 5분 TTL로 저장하는 것(src/main/java/avengers/lion/global/OAuth2SuccessHandler.java:70)을 확인했고, AuthController.exchangeToken에서는 opsForValue().get(...)로 조회한 뒤 redisTemplate.delete(...)로 삭제(src/main/java/avengers/lion/auth/controller/AuthController.java:24,30)하고 있어 조회와 삭제가 분리되어 동시 요청 시 동일 코드가 중복 사용될 가능성이 있습니다.
🤖 Prompt for AI Agents |
||
| log.info("🟢 OAuth2SuccessHandler 완료"); | ||
|
|
||
| } | ||
| } | ||
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.
DB 트랜잭션 커밋 전 Redis에 토큰 저장 — TOCTOU 위험
JPA 트랜잭션이 커밋되기 전에 액세스 토큰을 Redis에 저장합니다. 커밋 실패 시 존재하지 않는 사용자에 대한 토큰이 발급·노출될 수 있습니다. 트랜잭션 커밋 이후에 저장하도록 조정하세요.
수정 예:
📝 Committable suggestion
🤖 Prompt for AI Agents