【问题标题】:JsonWebTokenError: Can't verify jwtJsonWebTokenError:无法验证 jwt
【发布时间】:2017-03-08 05:36:18
【问题描述】:

我在这里制作令牌:

var token = jwt.sign(user, new_secret, {expiresIn: 10000});

那我在这里尝试验证一下

var token = req.headers.authorization;

jwt.verify(token, new_secret, function(err, decoded) { 
    console.log(err);    
  if (err) {
    return res.json({ success: false, message: 'Failed to authenticate token.' });    
  } else {
    // if everything is good, save to request for use in other routes
    req.decoded = decoded;    
    next();
  }
});

我不知道我在哪里出错了。我是 jwt 的新手。

【问题讨论】:

  • 你这里用的是什么包?我指的是jwt
  • JsonWebTokenError: Can't verify jwt 是完全错误吗?
  • node-jsonwebtoken 是包
  • { [JsonWebTokenError: invalid token] name: 'JsonWebTokenError', message: 'invalid token' } 是错误

标签: node.js express jwt


【解决方案1】:

我能够通过使用 angular-jwt 在客户端更改前缀来使其工作。

它曾经是“承载者”;我发现证据表明它应该是“JWT”......它只有通过完全删除它才能起作用:

jwtInterceptorProvider.authPrefix = '';

我不确定这是否是最佳做法。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-08-25
    • 2018-07-14
    • 2022-07-05
    • 2021-11-03
    • 2020-11-26
    • 2019-07-29
    • 2020-12-25
    相关资源
    最近更新 更多