Skip to content

Commit

Permalink
Merge pull request #86 from Central-MakeUs/feature/71/apple
Browse files Browse the repository at this point in the history
[Refactor] 로그인 성공/실패 시 redirect uri 수정 및 쿠키 설정 변경
  • Loading branch information
dainnida authored Feb 10, 2025
2 parents 689a615 + 945c4cd commit 9c115ec
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ public void onAuthenticationFailure(HttpServletRequest request, HttpServletRespo

log.error("Social Login Failed: {}", exception.getMessage());

String targetUrl = UriComponentsBuilder.fromUriString("/login/fail")
.queryParam("redirect_url", "https://www.mercuryplanet.co.kr/")
String targetUrl = UriComponentsBuilder.fromUriString("https://www.mercuryplanet.co.kr/login/fail")
.build(true).toUriString();

getRedirectStrategy().sendRedirect(request, response, targetUrl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,24 @@ public void onAuthenticationSuccess(HttpServletRequest request, HttpServletRespo
// JWT 토큰 생성
String accessToken = jwtProvider.createAccessToken(user.getId(), user.getEmail());
String refreshToken = jwtProvider.createRefreshToken(user.getId(), user.getEmail());
log.info("accessToken, refreshToken: {}, {}", accessToken, refreshToken);

// Access Token은 Authorization 헤더에 추가
response.setHeader("Authorization", "Bearer " + accessToken);
log.info("Header에 설정은 성공");

// Refresh Token은 보안을 위해 HttpOnly 쿠키로 설정
Cookie refreshTokenCookie = new Cookie("refresh_token", refreshToken);
refreshTokenCookie.setHttpOnly(true); // JavaScript에서 접근 방지
refreshTokenCookie.setSecure(true); // HTTPS만 허용
// refreshTokenCookie.setSecure(true); // HTTPS만 허용
refreshTokenCookie.setPath("/"); // 모든 경로에서 접근 가능
refreshTokenCookie.setDomain("mercuryplanet.co.kr"); // 도메인 간 쿠키 공유
// refreshTokenCookie.setDomain("mercuryplanet.co.kr"); // 도메인 간 쿠키 공유
refreshTokenCookie.setMaxAge((int) refreshTokenValidity / 1000); // ms를 초 단위로 변환
response.addCookie(refreshTokenCookie);

// 리다이렉트 URL에 토큰 포함하여 이동
String targetUrl = UriComponentsBuilder.fromUriString("/login/success")
String targetUrl = UriComponentsBuilder.fromUriString("https://www.mercuryplanet.co.kr/login/success")
.queryParam("access_token", accessToken)
.queryParam("redirect_url", "https://www.mercuryplanet.co.kr/home")
.build(true).toUriString();

getRedirectStrategy().sendRedirect(request, response, targetUrl);
Expand Down

0 comments on commit 9c115ec

Please sign in to comment.