0
處定義我正在嘗試在我們正在開發的Intranet應用程序上創建LDAP身份驗證的原型,這裏是我編寫的一些示例代碼,用於演示它是否可行。但是,我遇到了錯誤,我無法在任何地方在線找到解決方案。node-ldapauth ReferenceError:err未在
以下是完整的錯誤,我得到:
ReferenceError: err is not defined at /Users/tdeshpande/Dropbox/NodeAuth/app.js:32:54 at
Object.handle (/Users/tdeshpande/node_modules/express/node_modules/connect/lib/middleware
/basicAuth.js:89:7) at next (/Users/tdeshpande/node_modules/express/node_modules/connect
/lib/proto.js:193:15) at Object.expressInit [as handle] (/Users/tdeshpande/node_modules
/express/lib/middleware.js:30:5) at next (/Users/tdeshpande/node_modules/express
/node_modules/connect/lib/proto.js:193:15) at Object.query [as handle] (/Users/tdeshpande
/node_modules/express/node_modules/connect/lib/middleware/query.js:45:5) at next (/Users
/tdeshpande/node_modules/express/node_modules/connect/lib/proto.js:193:15) at
Function.app.handle (/Users/tdeshpande/node_modules/express/node_modules/connect
/lib/proto.js:201:3) at Server.app (/Users/tdeshpande/node_modules/express/node_modules
/connect/lib/connect.js:65:37) at Server.EventEmitter.emit (events.js:98:17)
這裏是我的代碼
var connect = require('connect');
var LdapAuth = require('ldapauth');
var express = require('express');
var app = express();
// Config from a .json or .ini file or whatever.
var config = {
url: 'ldap://intranetldapserver:389',
adminDn: 'userName',
adminPassword: 'secret',
searchBase: 'dc=corp,dc=company,dc=com, ou=People',
searchFilter: '(&(objectcategory=person)(samaccountname=*))',
searchAttributes: ['samaccountname']
};
var ldap = new LdapAuth(config);
var LdapAuthfunc = function(err, user) {
if (err) {
console.log("LDAP Auth error: %s", err);
callback(err);
}
else {
callback(err, user);
}
}
//Authenticator
app.use(express.basicAuth(function (username, password, callback) {
ldap.authenticate(username, password, LdapAuthfunc(err, user));
}));
// Basic Authenticator
// app.use(express.basicAuth('testUser', 'testPassword'));
app.get('/', function(req, res) {
res.send('Test Completed');
});
app.listen(8080);
誰能告訴我什麼,我做錯了什麼?
謝謝!
我不知道。我應該如何處理登錄失敗呢? – Tejas
@Tejas:見編輯。 – Ryan
此外,我使用http://stackoverflow.com/questions/20525070/why-is-node-ldapauth-so-slow-even-when-cached作爲編寫此原型的參考之一。 – Tejas