77import com .DecodEat .global .config .oauth .OAuth2SuccessHandler ;
88import com .DecodEat .global .config .oauth .OAuth2UserCustomService ;
99import lombok .RequiredArgsConstructor ;
10- import org .springframework .boot .autoconfigure .security .servlet .PathRequest ;
1110import org .springframework .context .annotation .Bean ;
1211import org .springframework .context .annotation .Configuration ;
1312import org .springframework .http .HttpStatus ;
1413import org .springframework .security .config .annotation .web .builders .HttpSecurity ;
15- import org .springframework .security .config .annotation .web .configuration .WebSecurityCustomizer ;
1614import org .springframework .security .config .http .SessionCreationPolicy ;
1715import org .springframework .security .crypto .bcrypt .BCryptPasswordEncoder ;
18- import org .springframework .security .oauth2 .client .TokenExchangeOAuth2AuthorizedClientProvider ;
1916import org .springframework .security .web .SecurityFilterChain ;
2017import org .springframework .security .web .authentication .HttpStatusEntryPoint ;
2118import org .springframework .security .web .authentication .UsernamePasswordAuthenticationFilter ;
2219import org .springframework .security .web .util .matcher .AntPathRequestMatcher ;
2320import org .springframework .web .cors .CorsConfigurationSource ;
21+ import org .springframework .beans .factory .annotation .Value ;
2422
2523@ RequiredArgsConstructor
2624@ Configuration
@@ -31,6 +29,8 @@ public class WebOAuthSecurityConfig {
3129 private final RefreshTokenRepository refreshTokenRepository ;
3230 private final UserService userService ;
3331 private final CorsConfigurationSource corsConfigurationSource ; // CorsCongifuragtinoSource Bean 주입 위함
32+ @ Value ("${spring.security.oauth2.client.registration.kakao.client-id}" )
33+ private String kakaoClientId ;
3434
3535// @Bean
3636// public WebSecurityCustomizer configure() {
@@ -77,6 +77,15 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
7777 .defaultAuthenticationEntryPointFor (
7878 new HttpStatusEntryPoint (HttpStatus .UNAUTHORIZED ),
7979 new AntPathRequestMatcher ("/api/**" )));
80+ // 7. 로그아웃
81+ http .logout (logout -> logout
82+ .logoutUrl ("/api/logout" )
83+ // 👇 카카오 로그아웃 URL로 리다이렉트
84+ .logoutSuccessUrl ("https://kauth.kakao.com/oauth/logout?client_id=" + kakaoClientId + "&logout_redirect_uri=https://decodeat.store.app/" )
85+ .invalidateHttpSession (true )
86+ .deleteCookies ("JSESSIONID" )
87+ .clearAuthentication (true )
88+ );
8089
8190 return http .build ();
8291 }
0 commit comments