EnableOAuth2Client 已弃用

Sam*_*nta 0 java spring spring-boot spring-security-oauth2

目前,我使用的是 Spring Boot 2.2.5 Release。文档看起来不完整。@EnableOAuth2Client或的替代品是什么@EnableOAuth2Sso在此处输入图片说明

mar*_*rco 8

您可以通过WebSecurityConfigurerAdapter 的configure 方法而不是注释来实现。

  1. EnableOAuth2Sso 现在是这样的:

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests()
         .anyRequest().authenticated()
         .and()
         .oauth2Login(); // sso           
    }
    
    Run Code Online (Sandbox Code Playgroud)
  2. @EnableOAuth2Client 现在是这样(有关完整示例和配置选项,请参阅 Spring 的迁移指南):

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
            .oauth2Client();
    }
    
    Run Code Online (Sandbox Code Playgroud)