【问题标题】:spring boot using 2 different oauth providers at the same timeSpring Boot 同时使用 2 个不同的 oauth 提供程序
【发布时间】:2020-07-08 05:56:01
【问题描述】:

在给定输入上下文的情况下,我必须针对 2 个不同的 oauth 提供者检查 oauth 令牌(私下调用 may api 与公开调用)

是否有一种简单的方法可以在 Spring Boot 中定义 2 个 oauth 提供者以及如何在 2 个提供者之间配置这种平衡?

【问题讨论】:

  • 您是否正在寻找在客户端应用上注册多个身份验证提供程序?
  • @S.Step 我正在尝试将我的 API 插入两个不同的身份验证提供程序(在我的情况下为 keycloak)

标签: spring spring-boot oauth-2.0 openid-connect spring-security-oauth2


【解决方案1】:

首先,您需要实现 2 AuthenticationProvider,然后在实现 WebSecurityConfigurerAdapter 的配置类中自动装配这些提供程序。最后覆盖public void configure(AuthenticationManagerBuilder authenticationManagerBuilder) throws Exception { 以添加这些提供程序。

@Configuration
public class SampleAuthConfiguration extends WebSecurityConfigurerAdapter {
    @Autowired
    private CustomAuthenticationProvider1 provider1;

    @Autowired
    private CustomAuthenticationProvider2 provider2;

    @Override
    public void configure(AuthenticationManagerBuilder authenticationManagerBuilder) throws Exception {
        authenticationManagerBuilder
            .authenticationProvider(this.provider1)
            .authenticationProvider(this.provider2);
    }
}

以下是一些教程。可能已经过时,但可以帮助您弄清楚。 https://dzone.com/articles/spring-security-authentication

https://www.baeldung.com/spring-security-multiple-auth-providers

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-22
    • 1970-01-01
    • 1970-01-01
    • 2018-09-12
    • 2017-09-19
    • 1970-01-01
    相关资源
    最近更新 更多