【发布时间】:2019-04-20 10:14:53
【问题描述】:
我有 Eureka 和连接的服务 Zuul:8090、AuthService:[any_port]。
我向 Zuul 发送 ../login 请求,他发送给 AuthSercice。然后 AuthSerice 放入 Header JWT Authentication。
@Override
protected void successfulAuthentication(HttpServletRequest request, HttpServletResponse response, FilterChain chain, Authentication authResult) throws IOException, ServletException {
String token = Jwts.builder()
.setSubject( ((User) authResult.getPrincipal()).getUsername())
.setExpiration(new Date(System.currentTimeMillis() + EXPIRATION_TIME))
.signWith(SignatureAlgorithm.HS512, SECRET)
.compact();
response.addHeader("Authorization", "Bearer "+ token); // this is missing
response.addHeader("Authorization2", "Bearer " + token); // ok
}
我确实要求邮递员。 Request result
首先我尝试在 Monoliths 中使用 JWT。没有问题,可以添加Authorization Token。
为什么缺少授权标头?
【问题讨论】:
标签: java authentication jwt microservices