【问题标题】:Change Bearer-Token-Type in Spring Cloud OAuth在 Spring Cloud OAuth 中更改 Bearer-Token-Type
【发布时间】:2015-05-19 16:47:18
【问题描述】:

我正在使用 Spring Cloud OAuth,我正在使用来自 https://github.com/spring-cloud-samples/sso/ 的官方示例和 GitLab (https://about.gitlab.com/) 作为 OAuth Provider。

问题是 GitLab 发送一个类型为“bearer”的令牌,Spring Cloud SSO 检索令牌并以
Authorization bearer xxxxxxx
的形式发送一个 Header 根据文档,它被 GitLab 服务器拒绝,因为它只接受
Authorization Bearer xxxxxxx 形式的令牌。

这可能是 GitLab 服务器中的一个错误,但有什么方法可以解决 Spring Cloud SSO 的这个问题。

更新 19.03.:

这是我在 SpringCloud-sample 的 SsoApplication.java 中尝试过的。

    @Autowired
    private OAuth2RestTemplate oAuth2RestTemplate;

    @PostConstruct
    private void modifyOAuthRestTemplate() {
        this.oAuth2RestTemplate.setAuthenticator(new OAuth2RequestAuthenticator() { // this line gets called
            @Override
            public void authenticate(OAuth2ProtectedResourceDetails resource, OAuth2ClientContext clientContext, ClientHttpRequest request) {
                // this line is never called
            }
        });
    }

调用“原始”而不是新注入的 OAuth2ProtectedResourceDetails。每次我尝试在示例应用中进行身份验证时

【问题讨论】:

  • gitlab 和 github 不一样吗(我知道可以)?
  • GitLab 是一个基于 Ruby 的 GitLab 克隆。但它并不在与 GitHub 相同的代码库上运行。 (GitHub 也适用于我)

标签: spring-security spring-boot gitlab spring-security-oauth2 spring-cloud


【解决方案1】:

更新:如果你定义一个UserInfoRestTemplateCustomizer 类型的bean,Spring Cloud 中有一个回调,你将在启动期间获得一个OAuth2RestTemplate 的实例,你可以在其中应用自定义(例如OAuth2RequestAuthenticator 将“Bearer”更改为“承载者”)。

我看到其他人使用的解决方法是@Autowired OAuth2RestTemplate 并在@PostConstruct 中修改其OAuth2RequestAuthenticator(无论如何在使用之前)。

【讨论】:

  • 我试过了,但@Autowired OAuth2RestTemplate 与身份验证期间使用的不同。
  • 定义“身份验证期间”。默认情况下有一个@PrimaryOAuth2RestTemplate,因此它必须与身份验证处理过滤器中的相同。我不确定你在说什么。
猜你喜欢
  • 1970-01-01
  • 2015-06-12
  • 2014-12-03
  • 1970-01-01
  • 1970-01-01
  • 2015-10-26
  • 2014-01-02
  • 1970-01-01
  • 2014-11-08
相关资源
最近更新 更多