Search code examples
javaspring-securityoauth-2.0

Why is @EnableOAuth2Sso deprecated?


Why is @EnableOAuth2Sso deprecated in Spring Security? That's the only reason why OAuth2 will work for me.

If I remove @EnableOAuth2Sso, then this will not work

@Configuration
@EnableOAuth2Client
@EnableOAuth2Sso <- Need to have this!
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
        .csrf().disable()
        .authorizeRequests()
        .antMatchers("/Intranet/Bokning").authenticated()
        .antMatchers("/**", "/Intranet**").permitAll()
        .anyRequest().authenticated()
        .and().logout().logoutSuccessUrl("/").permitAll();
    }

}

Is there another solution?


Solution

  • This is a solution to latest Spring Security with Facebook OAuth2.0.

    Security:

    @Configuration
    public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
        @Override
        public void configure(HttpSecurity http) throws Exception {
    
            http
            .csrf().disable()
            .authorizeRequests()
            .antMatchers("/Intranet/Bokning").authenticated() // Block this 
            .antMatchers("/**", "/Intranet**").permitAll() // Allow this for all
            .anyRequest().authenticated()
            .and().logout().logoutSuccessUrl("/").permitAll()
            .and()
            .oauth2Login();
        }
    }
    

    And appllication.yml

    spring:
      security:
        oauth2:
          client:
            registration:
               facebook:
                  clientId: myID
                  clientSecret: mySecret
                  accessTokenUri: https://graph.facebook.com/oauth/access_token
                  userAuthorizationUri: https://www.facebook.com/dialog/oauth
                  tokenName: oauth_token
                  authenticationScheme: query
                  clientAuthenticationScheme: form
                  resource:
                     userInfoUri: https://graph.facebook.com/me
    
    server:
      port: 8080
    

    And pom.xml file:

        <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
    
        <dependency>
          <groupId>org.springframework.security</groupId>
          <artifactId>spring-security-oauth2-client</artifactId>
        </dependency>