我在过去几天发布了各种问题,试图在我的Node Express服务器上配置通过LDAP(使用passport-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
),它会继续执行此操作直到服务器超时。任何想法为什么会这样?另外,旁注,我无法弄清楚为什么我在最初启动服务器时遇到错误;可以导致循环吗?我用Google搜索了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
});
});
};