javascript - UnauthorizedError:无效签名 - nodejs
问题描述
到目前为止,我已成功获取从前端传递的 jwt 令牌 - 角度到 nodejs 服务器。但是,我得到了错误 -
UnauthorizedError: invalid signature
你能指出我的语法/代码有什么问题吗?
app.component.ts
var token = localStorage.getItem('token')
return new Promise((resolve, reject) => {
var headers= new HttpHeaders({'Authorization': 'Bearer ' + token});
this.http.get(this.nodejsUrl + "getMongoDData/getSystem" +emptyObj, { headers:headers })
服务器.js
var cors = require('cors');
var expressJwt = require('express-jwt');
var session = require('express-session');
app.use(cors({
'Access-Control-Allow-Headers' : 'Content-Type, Authorization'
}));
app.use(expressJwt({
secret: config.secret,
credentialsRequired: false,
getToken: function (req) {
if (req.headers.authorization && req.headers.authorization.split(' ')[0] === 'Bearer') {
return req.headers.authorization.split(' ')[1];
} else if (req.query && req.query.token) {
return req.query.token;
}
return null;
}
})
.unless({
path: ['/forgotP/forgotPassword', '/login/authenticate',
]
})
);
解决方案
推荐阅读
- python - 从文件中为每个时间戳添加 15 分钟
- android - Webview 不加载 AdSense 广告
- angular - 您如何解决 d.ts 文件中的 angular typescript 错误?特别是 msal
- python-3.x - 机器人框架:将结果从一个关键字传递到另一个关键字
- ios - 缺少构建在结构中的 dSYM 文件。Gitlab 将构建上传到 Crashlytics
- dart - 我希望 IconButton 中的 onPressed 方法返回一个新的容器
- ios - 我只想访问 iOS 中的一个特定日历
- java - JFugue 笔记更改无法正常工作
- visual-c++ - 由于 exe 中缺少依赖项但存在于 dll 上,因此无法将 dll 从导入到我的 exe 进程
- python - 如何根据数组从(地理)熊猫数据框中选择多行或传播聚类算法结果的元数据?