Skip to content

Commit

Permalink
Feat: 로그인 성공 핸들러 쿠키 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
pjh5365 committed Sep 10, 2024
1 parent b1f17f5 commit b839307
Showing 1 changed file with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import java.io.IOException;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseCookie;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.SimpleUrlAuthenticationSuccessHandler;
import org.springframework.stereotype.Component;
Expand Down Expand Up @@ -33,13 +35,13 @@ public class LoginSuccessHandler extends SimpleUrlAuthenticationSuccessHandler {
@Value("${AUTH.REDIRECT_URL}")
private String redirectURL;

private Cookie createCookie(String key, String value, int maxAge) {
Cookie cookie = new Cookie(key, value);
cookie.setMaxAge(maxAge);
cookie.setPath("/");
cookie.setHttpOnly(true);

return cookie;
private ResponseCookie createCookie(String key, String value, int maxAge) {
return ResponseCookie.from(key, value)
.maxAge(maxAge)
.httpOnly(true)
.secure(true)
.domain(".kaboo.site")
.build();
}

@Override
Expand All @@ -57,6 +59,10 @@ public void onAuthenticationSuccess(HttpServletRequest request, HttpServletRespo
ObjectMapper objectMapper = new ObjectMapper();
String jsonResponse = objectMapper.writeValueAsString(loginSucessResponse);

response.addHeader(HttpHeaders.SET_COOKIE, createCookie("username", username, refreshTokenValidTime).toString());
response.addHeader(HttpHeaders.SET_COOKIE, createCookie("accessToken", accessToken, accessTokenValidTime).toString());
response.addHeader(HttpHeaders.SET_COOKIE, createCookie("refreshToken", refreshToken, refreshTokenValidTime).toString());

// 응답 설정
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
Expand Down

0 comments on commit b839307

Please sign in to comment.