我已经为我的Spring Boot MVC Web应用程序添加了社交登录功能。它允许用户使用GitHub、Facebook或Google帐户登录我的应用程序。但我正在努力让/logout的功能正常工作。即使调用了/logout并加载了logoutSuccessUrl,如果用户再次单击登录链接,也不会再次要求用户提供其用户名或密码。看起来用户仍然通过了身份验证。
你们如何使用新的Spring Security5 OAuth 2客户端支持来实现/logout?
我已经使用了新的OAuth 2客户端支持。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-oauth2-client</artifactId>
</dependency>
spring.security.oauth2.client.registration.facebook.client-id =
spring.security.oauth2.client.registration.facebook.client-secret = 下面是我的HTTPSecurity配置:
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/").permitAll()
.anyRequest().authenticated()
.and()
.oauth2Login()
.and()
.logout().logoutSuccessUrl("/");
}我也尝试过这种方式:
@Override protected void configure(HttpSecurity http)引发异常{ http
.authorizeRequests()
.antMatchers("/").permitAll()
.antMatchers(HttpMethod.POST,"/logout").permitAll()
.anyRequest().authenticated()
.and()
.oauth2Login()
.and()
.logout()
.invalidateHttpSession(true)
.clearAuthentication(true)
.deleteCookies("JSESSIONID")
.logoutSuccessUrl("/").permitAll()
.and()
.csrf()
.csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse());}
使用新的Spring Security OAuth 2客户端支持,如何注销使用社交OAuth 2登录提供商之一进行身份验证的用户?
发布于 2020-10-06 06:23:53
我目前在我的chrome浏览器上登录到google,可以查看我的gmail等,所以我与google有一个活跃的会话。如果我访问您的spring应用程序,并使用google登录,您的spring应用程序会将我重定向到googles auth服务器,该服务器会检测到我已经登录到google,因此它只需要求我同意您的应用程序请求的作用域,并且如果我同意向您的应用程序颁发访问令牌。现在,如果我想注销你的应用程序,spring security将使你应用程序上的会话失效,但它无法控制我在google上打开的会话,事实上,我也不想被从google注销。因此,如果您想要第三方的登录屏幕,您需要转到他们的页面并注销。
https://stackoverflow.com/questions/64176103
复制相似问题