【发布时间】:2015-05-02 17:54:34
【问题描述】:
我在我的项目中使用 jwt 令牌验证来保护一些重要数据:
if (req.headers.auth) {
var token = req.headers.auth.split(' ')[5];
var payload = jwt.decode(token, 'blablabla...');
if (!payload.sub) {
res.status(401).send({
message: 'Authentication failed'
});
}
if (!req.headers.auth) {
return res.status(301).send({
message:'You are not authorized'
});
}
res.send(data);
} else {
res.header(404).send('Go away!');
}
是否可以使用这种方法来保护静态路由,使用快速静态中间件添加?
更新!!! 好的,现在我的静态路由上设置了 jwt 令牌验证。但是我遇到了另一个问题 - 如何在我的 Angular 应用程序上传之前将这个令牌发送到 node.js 服务器(因为现在它被新的中间件阻止了)并开始将令牌插入到 http 标头中。我是否需要一些额外的模块,或者我的新中间件可以以某种方式从浏览器请求该 jwt 令牌?
【问题讨论】:
-
在单独的问题中询问您的更新。
标签: node.js validation express static