首页 > 解决方案 > Invalid JWT signature after upgrading jhipster

问题描述

I builded two microservices applications with jhipster (4.14.5), today i updated the both to 5.1.0. With jhister-registry last docker image (4.0.0)

All work as expected but the API Calls with jwt signature doesnt work anymore.

MyRequestInterceptor

@Override
    public void apply(RequestTemplate requestTemplate) {
        String secret= Jwts.builder()
            .setSubject("admin")
            .claim("auth", AuthoritiesConstants.ADMIN)
            .signWith(SignatureAlgorithm.HS512, properties.getSecurity().getAuthentication().getJwt().getSecret())
            .compact();
        requestTemplate.header(JWTConfigurer.AUTHORIZATION_HEADER, "Bearer " + secret);
    }

What is new in jhipster 5.1.0 with JWT? should i change the algorithm signature or how to fix this?

标签: jwtjhipsterjhipster-registry

解决方案


是的,我们改变了密钥的处理方式,看看这里的源代码。

不同之处在于,现在 JWT 密钥是用 Base64 编码的(这就是我们在这里创建编码器的原因)。

这本来是我的错:.signWith()来自 JJWT 的方法接受一个字符串,所以我只是给出了密钥(它是一个字符串)。但是如果您查看该方法的文档,您会注意到该字符串应该以 Base64 编码。所以现在你必须在任何地方使用加密版本的密钥。它最终并没有改变任何东西,事实上,它只是为了正确使用 API。


推荐阅读