JWT Field' kid'出现在标题中,要求在有效载荷中
我正在产生JWT令牌。 但是对JWT令牌的要求是,一个称为密钥ID的字段应出现在JWT的有效载荷中,但它出现在标题中。我该如何实现?
我的代码:
Algorithm algorithm = Algorithm.HMAC256(Objects.requireNonNull(environment.getProperty("signing_secret")).getBytes());
Map<String, Object> headers = new HashMap<>();
headers.put("dd-ver", environment.getProperty("version"));
headers.put("auth-version", environment.getProperty("auth-version"));
String token = JWT.create()
.withHeader(headers)
.withAudience(environment.getProperty("audience"))
.withIssuer(environment.getProperty("developer_id"))
.withKeyId(environment.getProperty("key_id"))
.withIssuedAt(new Date(System.currentTimeMillis()))
.withExpiresAt(new Date(System.currentTimeMillis() + THIRTY_MINUTES))
.sign(algorithm);
I am generating a JWT token.
But the requirement for the JWT token is, that a field called key id 'kid' should appear in the payload of the JWT, but it is appearing in the header. How can I achieve that?
my code:
Algorithm algorithm = Algorithm.HMAC256(Objects.requireNonNull(environment.getProperty("signing_secret")).getBytes());
Map<String, Object> headers = new HashMap<>();
headers.put("dd-ver", environment.getProperty("version"));
headers.put("auth-version", environment.getProperty("auth-version"));
String token = JWT.create()
.withHeader(headers)
.withAudience(environment.getProperty("audience"))
.withIssuer(environment.getProperty("developer_id"))
.withKeyId(environment.getProperty("key_id"))
.withIssuedAt(new Date(System.currentTimeMillis()))
.withExpiresAt(new Date(System.currentTimeMillis() + THIRTY_MINUTES))
.sign(algorithm);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用Claim
可以将自定义属性添加到JWT主体。您可以像这样编写代码。我们可以从
com.auth0.jwt.jwtcreator
中找到一些插图:withClaim
can add a custom property to JWT body. You can write your code like this.We can find some illustrations from
com.auth0.jwt.JWTCreator
: