我在 Node.js 中对护照身份验证做了以下事情。
1)我正在使用 jwtFromRequest : ExtractJwt.fromAuthHeaderAsBearerToken()
,
module.exports = function(passport){
var opts = {};
opts.jwtFromRequest = ExtractJwt.fromAuthHeaderAsBearerToken();
opts.secretOrKey = config.secret;
console.log('Inside passport');
//opts.issuer = 'accounts.examplesoft.com';
//opts.audience = 'yoursite.net';
passport.use(new JwtStrategy(opts, function(jwt_payload, done) {
console.log('Payload :: '+jwt_payload._doc);
User.getUserById({id: jwt_payload._doc._id}, function(err, User) {
if (err) {
return done(err, false);
}
if (User) {
return done(null, User);
} else {
return done(null, false);
// or you could create a new account
}
});
}));
2) 调用方法如下:
userExpressRoutes.route('/profile')
.get(passport.authenticate('jwt', { session: false }), function (req, res) { });
3)在 Ppostman 中设置标题,如:Authorization:Bearer {token}
4)它正在提供undefined
有效载荷
Payload :: undefined
TypeError: Cannot read property '_id' of undefined
这里缺少什么来获取 Jwt_payload?
有人能帮我吗?