【发布时间】:2015-06-17 18:50:37
【问题描述】:
尝试使用 express 设置节点和通行证,我偶然发现了一个问题,我在调试时遇到了一些问题。
有一个非常基本的注册表格,它可以一直工作到按下注册按钮。但是,注册不起作用。没有错误消息,但代码确实识别出注册失败(不是错误,而是没有用户)。经过一番折腾后,我设法达到了该 passport.authenticate(signup-local 在 info 中发送一条消息,上面写着“缺少凭据”,但我不知道什么凭据或为什么。
我在帖子中使用的返回码是:
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
我想看看帖子收到了什么,但不确定如何以简单的方式获得:)
【问题讨论】:
-
请发布您的策略配置。 (以“passport.use”开头的那个)
-
我真的没有这个 passport.use 文件了,是否有任何特定类型的 passport.use 你需要一份副本(在过去 10 个月里写得更好了) :)
-
如果没有策略配置,您的问题毫无意义。您可能很容易遇到属性名称问题或在那里验证回调。没关系,你终于想通了,但是对于stackoverlow的格式来说,这个问题太不完整了。
-
正如你所说,我确实解决了这个问题,并认为这是我错过的东西。护照(至少我尝试使用它的方式)如果没有 urlencodedParser 将无法工作。
标签: node.js passport.js