Spring Boot Sping Boot 、OAuth2与azure以及其他提供商(例如google)

ovfsdjhp  于 2022-11-23  发布在  Spring
关注(0)|答案(1)|浏览(149)

我有一个使用Azure Active Directory进行身份验证的应用程序,我需要添加另一个提供商,例如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:

使用以上代码将强制Azure登录。
我如何修改代码,使其同时具有Azure和Google选项?

7gcisfzg

7gcisfzg1#

我没有设法使它与spring-cloud-azure-starter-active-directory一起工作,所以我删除了这个插件并使用:

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

这个例子帮助我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

相关问题