JWT在授权' HTTP请求标头
我创建了一个客户来消耗REST API。一切似乎都还可以,但是由于找不到JWT,我会遇到401个错误。 这是我所做的服务:
@Service
public class RestTemplateService {
private static final String GET_RELATION_BY_ID = "https://cuco-query-sbg-cuco-dev.apps.scg01.scg.dev.bo2.paas.cloudcenter.corp/getRelationByCucoId/{cucoId}";
private static final String JWT = "Bearer xxxx"
RestTemplate restTemplate = new RestTemplate();
public ResponseEntity<CuCoPerson> getRelationById(Integer cucoId) {
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
headers.add("Authorization", JWT);
HttpEntity<String> entity = new HttpEntity<String>("parameters", headers);
Map<String, Integer> param = new HashMap<String, Integer>();
param.put("cucoId", cucoId);
return restTemplate.exchange(GET_RELATION_BY_ID, HttpMethod.GET, entity, CuCoPerson.class, param);
}
}
在这里,控制器:
@GetMapping("/getRelationById/{cucoId}")
public ResponseEntity<CuCoPerson> getRelationByCucoId(@PathVariable Integer cucoId, @AuthenticationPrincipal Principal principal) {
return restTemplateService.getRelationById(cucoId);
}
那么,我在哪里无法获得该令牌?
提前致谢!!
I've created a Client to consume a Rest API. Everything seems to be OK but I'm getting an 401 error as the JWT was not found.
Here is the service which I've made:
@Service
public class RestTemplateService {
private static final String GET_RELATION_BY_ID = "https://cuco-query-sbg-cuco-dev.apps.scg01.scg.dev.bo2.paas.cloudcenter.corp/getRelationByCucoId/{cucoId}";
private static final String JWT = "Bearer xxxx"
RestTemplate restTemplate = new RestTemplate();
public ResponseEntity<CuCoPerson> getRelationById(Integer cucoId) {
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
headers.add("Authorization", JWT);
HttpEntity<String> entity = new HttpEntity<String>("parameters", headers);
Map<String, Integer> param = new HashMap<String, Integer>();
param.put("cucoId", cucoId);
return restTemplate.exchange(GET_RELATION_BY_ID, HttpMethod.GET, entity, CuCoPerson.class, param);
}
}
And here the controller:
@GetMapping("/getRelationById/{cucoId}")
public ResponseEntity<CuCoPerson> getRelationByCucoId(@PathVariable Integer cucoId, @AuthenticationPrincipal Principal principal) {
return restTemplateService.getRelationById(cucoId);
}
So, where I'm failing to get that TOKEN?
Thanks in advance!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论