尝试与第三方提供商设置oauth2身份验证,但由于某种原因,它似乎没有将client_id传递给服务器。
@Bean(name = "oauth2RestTemplate")
public OAuth2RestTemplate oauth2RestTemplate() {
ArrayList<HttpMessageConverter<?>> messageConverters = new ArrayList<>();
messageConverters.add(new MappingJackson2HttpMessageConverter(objectMapper()));
messageConverters.add(new ByteArrayHttpMessageConverter());
messageConverters.add(new StringHttpMessageConverter());
HttpComponentsClientHttpRequestFactory baseRequestFactory = new HttpComponentsClientHttpRequestFactory();
baseRequestFactory.setConnectTimeout(60000);
baseRequestFactory.setReadTimeout(60000);
BufferingClientHttpRequestFactory httpRequestFactory = new BufferingClientHttpRequestFactory(baseRequestFactory);
List<ClientHttpRequestInterceptor> interceptors = new ArrayList<ClientHttpRequestInterceptor>();
interceptors.add(loggingRequestInterceptor());
OAuth2RestTemplate restTemplate = new OAuth2RestTemplate(clientCredentialsResourceDetails(), oauth2Context());
restTemplate.setMessageConverters(messageConverters);
restTemplate.setRequestFactory(httpRequestFactory);
restTemplate.setInterceptors(interceptors);
return restTemplate;
}
@Bean
public OAuth2ClientContext oauth2Context()
{
OAuth2ClientContext context = new DefaultOAuth2ClientContext();
return context;
}
@Bean
public OAuth2ProtectedResourceDetails clientCredentialsResourceDetails()
{
ClientCredentialsResourceDetails resourceDetails = new ClientCredentialsResourceDetails();
resourceDetails.setAccessTokenUri(uri");
resourceDetails.setClientId("client_id");
resourceDetails.setClientSecret("clientsecret");
return resourceDetails;
}
获取OAuth2AccessDeniedException error =&#34; access_denied&#34;,error_description =&#34;访问令牌被拒绝。&#34;
错误=&#34; invalid_client&#34;,error_description =&#34;未提供client_id&#34;,代码=&#34; 62&#34;,correlationid =&#34; e0efacc2-4829-4dd7 -8296-48c222992a84&#34;
答案 0 :(得分:0)
升级了spring和http客户端版本,并且有效