Spring security - Disable logout redirect

后端 未结 7 1798
北恋
北恋 2021-01-17 09:59

I\'m using spring security with REST, and I\'m using the URL (/logout) as an endpoint for my logout method. But after calling this method, it redirect me to (

7条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-17 10:47

    So since there is no accepted answer yet, i post my solution, which worked for me:

    .logout()
    .logoutUrl("/api/user/logout")
    .permitAll()
    .logoutSuccessHandler((httpServletRequest, httpServletResponse, authentication) -> {
        httpServletResponse.setStatus(HttpServletResponse.SC_OK);
    })
    .and()
    

    Just return a clean HTTP_OK (200) after successful logout - spring won't redirect you in this case

提交回复
热议问题