Skip to content

Commit

Permalink
refactor: body에 토큰 정보를 보내지 않고 url에 보내도록 수정
Browse files Browse the repository at this point in the history
redirect url 방식으로 토큰을 응답하기에 일반적으로 프론트에서 body정보를 받아올 수 없었다.
따라서 url에 담아 redirect 시키면
프론트의 redirect 된 페이지에서 정보를 받아오게 하였다.

다만 이 방식은 보안에 취약하므로 추후 cookie방식으로 변경할 예정이다.
  • Loading branch information
yooooonshine committed Nov 25, 2024
1 parent 0e0a2fd commit 94c462b
Showing 1 changed file with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package aimo.backend.common.security.oAuth;

import java.io.IOException;

import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.SimpleUrlAuthenticationSuccessHandler;
import org.springframework.stereotype.Component;
Expand All @@ -22,14 +24,22 @@ public void onAuthenticationSuccess(
HttpServletRequest request,
HttpServletResponse response,
Authentication authentication
) {
) throws IOException {
CustomUserDetails userDetails = (CustomUserDetails)authentication.getPrincipal();
Member member = userDetails.getMember();

String accessToken = jwtTokenProvider.createAccessToken(member.getId());
String refreshToken = jwtTokenProvider.createRefreshToken(member.getId());

jwtTokenProvider.sendAccessAndRefreshToken(response, accessToken, refreshToken);
jwtTokenProvider.saveOrUpdateRefreshToken(member.getId(), refreshToken);
// jwtTokenProvider.sendAccessAndRefreshToken(response, accessToken, refreshToken);
// jwtTokenProvider.saveOrUpdateRefreshToken(member.getId(), refreshToken);

// React의 Redirect URI로 리다이렉트
String redirectUrl = String.format(
"http://localhost:3000/oauth/callback/kakao?accessToken=%s&refreshToken=%s",
accessToken, refreshToken
);

getRedirectStrategy().sendRedirect(request, response, redirectUrl);
}
}

0 comments on commit 94c462b

Please sign in to comment.