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
});
});
};