我使用Spring,我使用来自https://github.com/spring-cloud-samples/sso/的官方示例GitLab (https://about.gitlab.com/)作为OAuth提供程序。
问题是,GitLab发送类型为“承载”的令牌,Spring检索令牌并以
Authorization bearer xxxxxxx
它被GitLab服务器拒绝,因为它只接受以下形式的令牌
Authorization Bearer xxxxxxx。
这可能是中的一个bug,但是有什么方法可以解决这个问题吗?
更新19.03.:
这就是我在SpringCloud示例的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,而是调用“原始”的一个。每次我尝试在示例应用程序中进行身份验证
发布于 2015-03-17 12:11:49
更新: Spring中有一个回调,如果您定义了一个类型为UserInfoRestTemplateCustomizer的bean,您将在启动期间得到一个OAuth2RestTemplate实例,您可以在其中应用自定义(例如,将"Bearer“更改为”承载“的OAuth2RequestAuthenticator )。
我见过其他人使用的解决方法是使用@Autowired OAuth2RestTemplate并在@PostConstruct中修改其OAuth2RequestAuthenticator (无论如何,在使用之前)。
https://stackoverflow.com/questions/29096006
复制相似问题