1

I have an application that is using Azure Active directory to authenticate and I need to add another provider, for example google.

@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class SecurityConfig extends AadWebSecurityConfigurerAdapter {

    @Override
    public void configure(HttpSecurity http) throws Exception {
    super.configure(http);
      http.authorizeRequests()
              .anyRequest().authenticated();
    }
}


spring:
  cloud:
    azure:
      active-directory:
        enabled: true
        profile:
          tenant-id: 
#        credential:
          client-id: 
          client-secret: 
  security:
    oauth2:
      client:
        registration:
          google:
            client-id: 
            client-secret: 

Using above code will force azure login.

How can I adapt the code to have both options azure and google?

telebog
  • 1,706
  • 5
  • 25
  • 34
  • there are some answers not sure it could help : https://stackoverflow.com/a/68586588/2165146 – muhammed ozbilici Nov 18 '22 at 12:57
  • Thanks, I already read that answer, but did not helped. – telebog Nov 18 '22 at 14:44
  • When I need to federate etherogeneous identy sources, I use a Keycloak instance to federated all. But doesn't your main authorization-server (Azure) support "social login" providers ? In that case, Azure would remain the only reference for your clients & resource-servers. – ch4mp Nov 19 '22 at 02:26

1 Answers1

0

I did not manage to make it work with spring-cloud-azure-starter-active-directory, so I removed this plugin and used:

 spring:
  security:
    oauth2:
      client:
        registration:
          google:
            client-id: 
            client-secret:
          azure:
            client-id: 
            client-secret: 
            scope:
              - openid
              - profile
              - email
            authorization-grant-type: authorization_code
            redirect-uri: http://localhost:8080/login/oauth2/code/azure
            provider: azure-active-directory
        provider:
          azure-active-directory:
            issuer-uri: https://login.microsoftonline.com/{tenant-id}/v2.0

This example helped me https://github.com/Azure-Samples/azure-spring-boot-samples/blob/spring-cloud-azure_v4.4.1/aad/spring-security/servlet/oauth2/login/src/main/resources/application.yml

telebog
  • 1,706
  • 5
  • 25
  • 34