Node.js 护照登记本地报税表“;“缺少凭据”;
尝试使用express设置节点和passport时,我遇到了一个问题,调试时遇到了一些问题 有一个非常基本的注册表单,它可以一直工作到按下注册按钮。但是,注册不起作用。没有错误消息,但代码确认注册失败(没有错误,但没有用户)。经过一点吹毛求疵之后,我终于拿到了passport.authenticate(注册本地)发送了一条信息,上面写着“缺少凭据”,但我不知道是什么凭据或为什么 我在邮件中使用的返回代码是:Node.js 护照登记本地报税表“;“缺少凭据”;,node.js,passport.js,Node.js,Passport.js,尝试使用express设置节点和passport时,我遇到了一个问题,调试时遇到了一些问题 有一个非常基本的注册表单,它可以一直工作到按下注册按钮。但是,注册不起作用。没有错误消息,但代码确认注册失败(没有错误,但没有用户)。经过一点吹毛求疵之后,我终于拿到了passport.authenticate(注册本地)发送了一条信息,上面写着“缺少凭据”,但我不知道是什么凭据或为什么 我在邮件中使用的返回代码是: app.post('/signup', function(req, res, next)
app.post('/signup', function(req, res, next) {
passport.authenticate('local-signup', function(err, user, info) {
if (err) {
return next(err); // will generate a 500 error
}
// Generate a JSON response reflecting authentication status
if (! user) {
console.log('Got the following back');
console.log('Error: ' + err);
console.log('User: ' + user);
info = JSON.stringify(info);
console.log('Info: '+ info);
for(var key in info) {
console.log(key);
}
return res.send({ success : false, message : 'authentication failed'});
}
return res.send({ success : true, message : 'authentication succeeded' });
})(req, res, next);
});
回报是:
GET /signup 304 24.943 ms - -
Got the following back
Error: null
User: false
Info: {"message":"Missing credentials"}
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
POST /signup 200 6.933 ms - 51
我想看看这篇文章收到了什么,但不确定如何以一种简单的方式得到它:)好的,所以经过一番努力,我发现了问题所在 您需要加载urlencodedParser。因此,在路线的开头添加了以下内容
var bodyParser = require('body-parser');
module.exports = function(app, passport) {
var urlencodedParser = bodyParser.urlencoded({ extended: false })
完成后,您所要做的就是通过urlencodedParser传递呼叫,然后Bobs您叔叔
app.post('/signup', urlencodedParser, function(req, res, next) {
passport.authenticate('local-signup', function(err, user, info) {
if (err) {
return next(err); // will generate a 500 error
}
// Generate a JSON response reflecting authentication status
if (! user) {
console.log('Got the following back');
console.log('Error: ' + err);
console.log('User: ' + user);
info = JSON.stringify(info);
console.log('Info: '+ info);
for(var key in info) {
console.log(key);
}
var userd = JSON.stringify(req.body);
console.log('Request : ' + userd);
return res.send({ success : false, message : 'authentication failed'});
}
return res.send({ success : true, message : 'authentication succeeded' });
})(req, res, next);
});
请张贴您的策略配置。(以“passport.use”开头的那一个)我已经没有这个passport.use文件了,还有什么特定类型的passport.use吗?你需要一份(在过去10个月里写得更好了:)如果没有策略配置,你的问题毫无意义。您可能很容易在属性名或验证回调方面遇到问题。没关系,你终于弄明白了,但在我看来,这个问题对于stackoverlow的格式来说太不完整了。正如你所说,我确实解决了这个问题,并且认为这是我遗漏的。passport(至少是我尝试使用它的方式)如果没有urlencodedParser就无法工作。