在过去的几天里,我发布了各种问题,试图将护照配置为通过passport-ldap
我的 Node Express 服务器上的 LDAP(使用)运行。无论如何,我发现里面的authenticate
函数node_modules/passport/lib/passport/middleware/authenticate.js
正在运行一个无限循环,一遍又一遍地调用自己。我使用了 Node 调试器并debugger
在我的代码中放置了一堆语句,发现每次我输入正确的登录凭据时它都会重复(login_fail
当我输入错误的凭据时它会正确地重定向到我的页面)。
这是我的调试器在命令行上的样子:
Bootstrapping server...
< setting up stylus compile
< passport/authenticate
< Bootstrap db connection
< Bootstrap models
< reading model: entry.js
< Initializing EntrySchema
< reading model: user.js
< Initializing UserSchema
< Bootstrap passport
< [Error: Symbol DTraceProviderBindings_module not found.]
< { [Error: Cannot find module './build/default/DTraceProviderBindings'] code: 'MODULE_NOT_FOUND' }
< { [Error: Cannot find module './build/Debug/DTraceProviderBindings'] code: 'MODULE_NOT_FOUND' }
< Bootstrap routes
< passport/authenticate
< Express app started on port 3000
break in node_modules/passport/lib/passport/middleware/authenticate.js:79
77
78 return function authenticate(req, res, next) {
79 debugger;
80 var passport = this;
81
debug> cont
break in node_modules/passport/lib/passport/middleware/authenticate.js:176
174 var delegate = {};
175
176 debugger;
177
178 delegate.success = function(user, info) {
debug> cont
break in node_modules/passport/lib/passport/middleware/authenticate.js:268
266 if (!layer) { return allFailed(); }
267
268 debugger;
269
270 // Get the strategy, which will be used as prototype from which to create
debug> cont
< GET /login 304 36764ms
break in node_modules/passport/lib/passport/middleware/authenticate.js:79
77
78 return function authenticate(req, res, next) {
79 debugger;
80 var passport = this;
81
debug> cont
break in node_modules/passport/lib/passport/middleware/authenticate.js:176
174 var delegate = {};
175
176 debugger;
177
178 delegate.success = function(user, info) {
debug> cont
break in node_modules/passport/lib/passport/middleware/authenticate.js:268
266 if (!layer) { return allFailed(); }
267
268 debugger;
269
270 // Get the strategy, which will be used as prototype from which to create
debug> cont
break in node_modules/passport/lib/passport/middleware/authenticate.js:79
77
78 return function authenticate(req, res, next) {
79 debugger;
80 var passport = this;
81
debug> cont
break in node_modules/passport/lib/passport/middleware/authenticate.js:176
174 var delegate = {};
175
176 debugger;
177
178 delegate.success = function(user, info) {
debug> cont
break in node_modules/passport/lib/passport/middleware/authenticate.js:268
266 if (!layer) { return allFailed(); }
267
268 debugger;
269
270 // Get the strategy, which will be used as prototype from which to create
debug> cont
break in node_modules/passport/lib/passport/middleware/authenticate.js:259
257 // push this failure into the accumulator and attempt authentication
258 // using the next strategy
259 debugger;
260 failures.push({ challenge: challenge, status: status });
261 attempt(i + 1);
debug> cont
break in node_modules/passport/lib/passport/middleware/authenticate.js:176
174 var delegate = {};
175
176 debugger;
177
178 delegate.success = function(user, info) {
debug> cont
break in node_modules/passport/lib/passport/middleware/authenticate.js:87
85 function allFailed() {
86
87 debugger;
88
89 if (callback) {
debug> cont
break in node_modules/passport/lib/passport/middleware/authenticate.js:99
97 }
98
99 debugger;
100
101 // Strategies are ordered by priority. For the purpose of flashing a
debug> cont
< POST /users/session 302 174136ms - 78b
break in node_modules/passport/lib/passport/middleware/authenticate.js:79
77
78 return function authenticate(req, res, next) {
79 debugger;
80 var passport = this;
81
debug> cont
break in node_modules/passport/lib/passport/middleware/authenticate.js:176
174 var delegate = {};
175
176 debugger;
177
178 delegate.success = function(user, info) {
debug> cont
break in node_modules/passport/lib/passport/middleware/authenticate.js:268
266 if (!layer) { return allFailed(); }
267
268 debugger;
269
270 // Get the strategy, which will be used as prototype from which to create
debug> cont
break in node_modules/passport/lib/passport/middleware/authenticate.js:79
77
78 return function authenticate(req, res, next) {
79 debugger;
80 var passport = this;
81
debug> cont
break in node_modules/passport/lib/passport/middleware/authenticate.js:176
174 var delegate = {};
175
176 debugger;
177
178 delegate.success = function(user, info) {
debug> cont
break in node_modules/passport/lib/passport/middleware/authenticate.js:268
266 if (!layer) { return allFailed(); }
267
268 debugger;
269
270 // Get the strategy, which will be used as prototype from which to create
debug> cont
break in node_modules/passport/lib/passport/middleware/authenticate.js:259
257 // push this failure into the accumulator and attempt authentication
258 // using the next strategy
259 debugger;
260 failures.push({ challenge: challenge, status: status });
261 attempt(i + 1);
debug> cont
break in node_modules/passport/lib/passport/middleware/authenticate.js:176
174 var delegate = {};
175
176 debugger;
177
178 delegate.success = function(user, info) {
debug> cont
break in node_modules/passport/lib/passport/middleware/authenticate.js:87
85 function allFailed() {
86
87 debugger;
88
89 if (callback) {
debug> cont
break in node_modules/passport/lib/passport/middleware/authenticate.js:99
97 }
98
99 debugger;
100
101 // Strategies are ordered by priority. For the purpose of flashing a
debug> cont
< POST /users/session 302 9485ms - 78b
break in node_modules/passport/lib/passport/middleware/authenticate.js:79
77
78 return function authenticate(req, res, next) {
79 debugger;
80 var passport = this;
81
debug> cont
break in node_modules/passport/lib/passport/middleware/authenticate.js:176
174 var delegate = {};
175
176 debugger;
177
178 delegate.success = function(user, info) {
debug> cont
break in node_modules/passport/lib/passport/middleware/authenticate.js:268
266 if (!layer) { return allFailed(); }
267
268 debugger;
269
270 // Get the strategy, which will be used as prototype from which to create
debug>
正如你所看到的,它重复了很多次相同的行(如果我一直在输入cont
)它会继续这样做,直到服务器超时。任何想法为什么会发生这种情况?另外,请注意,当我最初启动服务器时,我无法弄清楚为什么会出现该错误;这会导致循环吗?我已经用谷歌搜索了 3 或 4 次,但还没有找到可行的解决方案。
编辑:我想我发现了问题。代码程序完全跳过了res.on
如下定义的这条语句node_modules/passport-ldap/lib/passport-ldap/strategy.js
:
break in node_modules/passport-ldap/lib/passport-ldap/strategy.js:93
91 }
92
93 debugger
94 console.log(err)
95 console.log(r)
debug> cont
< null
< { domain: null, _events: {}, _maxListeners: 10 }
break in node_modules/passport-ldap/lib/passport-ldap/strategy.js:124
122 });
123 });
124 debugger
125 });
126 });
debug>
作为参考,这是我所有debugger
陈述的功能:
Strategy.prototype.authenticate = function(req, options) {
var self = this;
if (!req.body.username || !req.body.password) {
return self.fail(401);
}
self.client.bind(req.body.username, req.body.password, function(err) {
if (err) {
return self.fail(403);
}
self.client.search(self._options.base, self._options.search, function(err, r) {
if (err) {
return self.fail(403);
}
debugger
console.log(err)
console.log(r)
r.on('searchEntry', function(entry) {
debugger
var profile = JSON.stringify(entry.object);
console.log(profile)
debugger
self._verify(profile, function(err, user) {
debugger
if (err) {
return self.error(err);
}
debugger
if (!user) {
return self.fail(self._challenge());
}
debugger
self.success(user);
});
});
debugger
});
});
};