Skip to content
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

feat: cookie 설정에 서버 도메인 정보 추가 #74

Merged
merged 2 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,23 +55,20 @@ public CorsConfiguration getCorsConfiguration(HttpServletRequest request) {

http
.oauth2Login(oauth2 -> oauth2
.userInfoEndpoint(
userInfoEndpointConfig -> userInfoEndpointConfig.userService(customOAuth2MemberService))
.userInfoEndpoint(userInfoEndpointConfig ->
userInfoEndpointConfig.userService(customOAuth2MemberService))
.successHandler(customSuccessHandler));

http
.authorizeHttpRequests(auth -> auth
.requestMatchers("/", "/groups", "/oauth2/**", "/login/**", "/error", "/api/*", "/swagger-ui/**",
"/v3/api-docs/**")
.permitAll()
.anyRequest()
.authenticated());
"/v3/api-docs/**").permitAll()
.anyRequest().authenticated());

http
.sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS));
.sessionManagement(session -> session
.sessionCreationPolicy(SessionCreationPolicy.STATELESS));

return http.build();
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,16 @@ public void onAuthenticationSuccess(HttpServletRequest request, HttpServletRespo

response.addCookie(createCookie(token));

response.sendRedirect("http://localhost:3000?token=" + token + "&expires=" + EXPIRED_TIME);
// response.sendRedirect("http://localhost:3000?token=" + token + "&expires=" + EXPIRED_TIME);
response.sendRedirect("http://localhost:3000");

}

// JWT 쿠키 생성 메서드
private Cookie createCookie(String value) {
Cookie cookie = new Cookie("JWT", value);
cookie.setMaxAge(EXPIRED_TIME); // 쿠키 유효시간 설정
cookie.setDomain("3.38.247.217");
// cookie.setSecure(false);
cookie.setPath("/"); // 모든 경로에 대해 쿠키를 유효하게 설정
// cookie.setHttpOnly(true); // 자바스크립트로 접근 불가능하게 설정
Expand Down
4 changes: 2 additions & 2 deletions badminton-api/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ spring:
client-name: kakao
client-id: ${KAKAO_CLIENT_ID}
client-secret: ${KAKAO_CLIENT_SECRET}
redirect-uri: ${FRONT_URL}/login/oauth2/code/kakao
redirect-uri: ${SERVER_URL}/login/oauth2/code/kakao
authorization-grant-type: authorization_code
scope: profile_nickname, account_email, profile_image
client-authentication-method: client_secret_post
google:
client-name: google
client-id: ${GOOGLE_CLIENT_ID}
client-secret: ${GOOGLE_CLIENT_SECRET}
redirect-uri: ${FRONT_URL}/login/oauth2/code/google
redirect-uri: ${SERVER_URL}/login/oauth2/code/google
authorization-grant-type: authorization_code
scope: profile,email
provider:
Expand Down