【发布时间】:2021-01-18 09:35:33
【问题描述】:
我已添加到我的 Spring Boot MVC Web 应用程序社交登录功能。它允许用户使用 GitHub、Facebook 或 Google 帐户登录我的应用程序。但我正在努力让 /logout 功能正常工作。即使调用了 /logout 并加载了 logoutSuccessUrl,如果用户再次单击登录链接,则不会再次要求用户提供其用户名或密码。看起来用户仍然是经过身份验证的。
你们如何使用新的 Spring Security 5 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("/");
}
我也试过这种方法:
@覆盖 受保护的无效配置(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 登录提供程序之一进行身份验证的用户?
【问题讨论】:
标签: spring-security oauth-2.0 oauth spring-security-oauth2 spring-oauth2