在Spring Boot中使用OAuth 2时禁用CSRF

互联网上的许多示例只是说要打电话http.csrf()。disable(),但这最终会禁用所有身份验证(导致身份验证主体永远空值)。

这是在使用Spring Boot时如何禁用REST服务的CSRF保护而不禁用所有身份验证的方法。

@Configuration
@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests().anyRequest().authenticated()
            .and().oauth2Login()
            .and().csrf().disable();
    }
}

from: https://dev.to//jbaranski/disable-csrf-while-using-oauth2-in-spring-boot-3hcm

发布了0 篇原创文章 · 获赞 0 · 访问量 657

猜你喜欢

转载自blog.csdn.net/cunxiedian8614/article/details/105691062