如何使用完全自定义的负载创建JWT

huangapple 未分类评论49阅读模式
标题翻译

How to make a JWT with a fully custom payload

问题

我必须创建一个JWT以在REST API服务中发送它。
令牌的载荷是在没有“标准”声明的情况下定义的。

以下是在PHP中给出的示例:

$jwt = JWT::encode($payload, $privateKey, 'RS256');

其中$payload是带有载荷的自由JSON字符串。

我尝试使用Auth0,但是

JWT.create()

没有一个完全自定义的方法来将字符串或对象设置为载荷。是否有任何方法可以不使用标准JWT声明并设置自由载荷?

英文翻译

I have to create a JWT to send it in a REST API service.
The payload of the tocken was defined without "standard" claims.

This is the given example in PHP:

$jwt = JWT::encode($payload, $privateKey, 'RS256');

Where $payload is a free json string with the payload.

I tried to use Auth0 but

JWT.create()

doesn't have a fully custom method to set a string or an object as payload.
Is there any way to not use standard JWT claims and set a free payload?

答案1

得分: 2

你的问题出在你使用Auto0库来创建JWT输入对象的地方。如果这不可行,你需要使用另一个库,我建议使用Spring Framework来解决你的问题。请查看这个链接。

https://spring.io/projects/spring-framework

英文翻译

Your problem is where you are using the Auto0 library to create the JWT input object. If this is not possible you will need to use another library that I suggest using Framework spring to solve your problem. Take a look at this link.

https://spring.io/projects/spring-framework

huangapple
  • 本文由 发表于 2020年3月17日 02:22:18
  • 转载请务必保留本文链接:https://java.coder-hub.com/60711292.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定