到目前为止,我已经成功获取了从前端-angular传递到nodejs服务器的jwt令牌。但是,我得到了错误-
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 })
server.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',
]
})
);