【发布时间】:2022-07-14 19:41:16
【问题描述】:
我想使用 Spring RestTemplate 从作为登录 URL 的重定向 URL 的回调中检索 jwt 令牌。
我已经能够连接到登录 URL,我已经能够跟随重定向链接到回调,但我无法检索存储在回调的响应标头中的令牌。
RestTemplate restTemplate = new RestTemplate();
String url = my_login_url;
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
map.add(my_login);
map.add(my_password);
HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<>(map, headers);
final HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory();
final HttpClient httpClient = HttpClientBuilder.create()
.setRedirectStrategy(new LaxRedirectStrategy())
.build();
factory.setHttpClient(httpClient);
restTemplate.setRequestFactory(factory);
ResponseEntity<String> response = restTemplate.exchange(url,
HttpMethod.POST,
request,
String.class);
// OUCH !! response does not contain the token I'm trying to retrieve !! The token is in the header of the callback !!
谁能帮我理解如何访问回调的标头?
【问题讨论】:
标签: java spring-boot callback token response-headers