Spring security 在Spring Cloud OAuth中更改承载令牌类型

Spring security 在Spring Cloud OAuth中更改承载令牌类型,spring-security,spring-boot,gitlab,spring-security-oauth2,spring-cloud,Spring Security,Spring Boot,Gitlab,Spring Security Oauth2,Spring Cloud,我使用的是SpringCloudOAuth,我使用的是GitLab()的官方示例作为OAuth提供者 问题是GitLab发送一个类型为“bearer”的令牌,Spring Cloud SSO检索该令牌并以 授权持有人xxxxxxx 它被GitLab服务器拒绝,因为根据文档,它只接受 授权持有人xxxxxxx 这可能是GitLab服务器中的一个bug,但是有没有办法用SpringCloudSSO解决这个问题呢 更新19.03.: 这是我在SpringCloud示例的SsoApplication.j

我使用的是SpringCloudOAuth,我使用的是GitLab()的官方示例作为OAuth提供者

问题是GitLab发送一个类型为“bearer”的令牌,Spring Cloud SSO检索该令牌并以
授权持有人xxxxxxx

它被GitLab服务器拒绝,因为根据文档,它只接受
授权持有人xxxxxxx

这可能是GitLab服务器中的一个bug,但是有没有办法用SpringCloudSSO解决这个问题呢

更新19.03.:

这是我在SpringCloud示例的SsoApplication.java中尝试的。


调用的不是新注入的OAuth2ProtectedResourceDetails,而是“原始的”。每次我尝试在示例应用程序中进行身份验证时,更新:如果您定义类型为
UserInfoRestTemplateCustomizer
的bean,Spring Cloud中会有一个回调,您将在启动期间获得一个
OAuth2RestTemplate
的实例,您可以在其中应用自定义设置(例如,
OAuth2RequestAuthenticator
)来更改“Bear”“持票人”)


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

我尝试过,但@Autowired OAuth2RestTemplate与身份验证期间使用的模板不同。定义“在身份验证期间”。默认情况下,有一个
@Primary
OAuth2RestTemplate
,因此它必须与身份验证处理筛选器中的模板相同。我不确定你到底在说什么。gitlab与github(我知道它可以工作)不一样吗?GitLab是一个基于Ruby的GitLab克隆。但它与GitHub运行在不同的代码库上。(GitHub也适用于我)
    @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
            }
        });
    }