我有一个使用 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 选项?
最佳答案
我没能让它与 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
关于spring-boot - Spring Boot、带有 azure 的 OAuth2 和另一个提供商(例如 google),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74489661/