.....
Authorization: KakaoAK {token}
.....
class AdminKeyHeaderOAuth2RequestInterceptor implements ClientHttpRequestInterceptor {
@Override
public ClientHttpResponse intercept(final HttpRequest request, final byte[] body, ClientHttpRequestExecution execution) throws IOException {
return execution.execute(protectedResourceRequest, body);
}
}
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
headers.setAccept(Arrays.asList(new MediaType[]{MediaType.ALL}));
headers.set("Authorization", "KakaoAK " + adminKey); //admin key를 header에 셋팅해야함
MultiValueMap<String, String> param = new LinkedMultiValueMap<String, String>();
param.set("limit", limit);
param.set("fromId", fromId);
param.set("order", order);
restTemplate.setInterceptors(Arrays.asList(new ClientHttpRequestInterceptor[]{new AdminKeyHeaderOAuth2RequestInterceptor()}));
ResponseEntity<KakaoIds> response = restTemplate.exchange(buildApiUri("/v1/user/ids", param).toString(), HttpMethod.GET, new HttpEntity<Object>(headers), KakaoIds.class);
但请求进程转到'org.springframework.social.oauth2.OAuth2RequestInterceptor'类的'intercep'方法并覆盖http标头。 (在我的自定义请求拦截器之后)
HttpRequest protectedResourceRequest = new HttpRequestDecorator(request);
protectedResourceRequest.getHeaders().set("Authorization", oauth2Version.getAuthorizationHeaderValue(accessToken));
return execution.execute(protectedResourceRequest, body);
....
Authorization: Bearer {token}
....
我该如何解决这个问题?