【问题标题】:Is there a way to remove 'iat' option from jwt payload in jsonwebtoken library typescript?有没有办法从 jsonwebtoken 库打字稿中的 jwt 有效负载中删除 'iat' 选项?
【发布时间】:2022-01-23 14:03:42
【问题描述】:

我想从标头中删除“iat”选项,以便为外部服务器创建正确的请求。我试图做这样的事情

let token = jwt.sign(
    {payload: payload, iat: undefined},
    generateAndGetDeviceKey(),
    { algorithm: 'HS512' }
);

但它不起作用。我有错误

未捕获(承诺中)错误:“iat”应该是几秒

【问题讨论】:

  • 为什么要删除那个号码?

标签: typescript react-redux jwt


【解决方案1】:

您可以传递noTimestamp 选项,这将阻止添加iat

这样的事情应该可以工作。

let token = jwt.sign(
    {payload: payload},
    generateAndGetDeviceKey(),
    { algorithm: 'HS512', noTimestamp: true }
);

【讨论】:

  • 这基本上是对的,但 OP 应该知道 noTimestamp 的字面意思是它所说的,所以令牌也没有 expnbf 时间戳。
  • 我假设 exp 可以手动添加到有效负载中,如果由于某种原因令牌应该有 exp 但没有 iat
  • 我认为 - 试一试!
  • 我将把它作为 OP 的练习 ;)
猜你喜欢
  • 2017-05-31
  • 2018-04-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-12-01
  • 2020-09-23
  • 2012-06-23
相关资源
最近更新 更多