我正在尝试使用passport-ldapauth和express对LDAP服务器进行身份验证。
使用ldap url(ldap://myserver ...)进行身份验证可以正常工作,但是使用ldaps可以得到:
TypeError: Cannot read property 'on' of undefined at setupSocket (...\ldapauth-fork\node_modules\ldapjs\lib\client\client.js:111:14) at Client._connect (...\ldapauth-fork\node_modules\ldapjs\lib\client\client.js:742:3) at new Client (...\ldapauth-fork\node_modules\ldapjs\lib\client\client.js:247:22) at Object.createClient (...\ldapauth-fork\node_modules\ldapjs\lib\client\index.js:60:12) at new LdapAuth (...\ldapauth-fork\lib\ldapauth.js:129:28) at handleAuthentication (...\passport-ldapauth\lib\passport-ldapauth\strategy.js:140:10) at Strategy.authenticate (...\passport-ldapauth\lib\passport-ldapauth\strategy.js:175:33) at attempt (...\passport\lib\middleware\authenticate.js:341:16) at authenticate (...\passport\lib\middleware\authenticate.js:342:7) at Layer.handle [as handle_request] (...\express\lib\router\layer.js:82:5)
My code is, basically, this:
...
passport.use(new LdapStrategy({
server: {
url: 'ldaps://myserver:636',
searchBase: '...',
searchFilter: '(uid={{username}})',
tlsOptions: {
ca: [
fs.readFileSync('myCAcert.pem')
]
}
},
session: false,
usernameField:'u',
passwordField:'p'
},
function(user, done) {
console.log("Interna: \nOK");
console.log("u:");
console.log(user.cn);
return done(null, user);
}));
app.use('/login',passport.authenticate('ldapauth',
{ session:false,
successRedirect:'/accessed',
failureRedirect: '/accessfail'
}
));
app.use('/accessed',function (req,res,next){
res.send("User OK");
});
app.use('/accessfail',function (req,res,next){
res.send("User MAL !!!!!!!");
});
app.listen(3336);
我的库版本是:
express @ 4.11.2, Passport @ 0.2.1, Passport [email protected]
有人可以帮我吗?
谢谢。
最佳答案
最后,我可以解决问题。
ldapauth-fork中使用的ldapjs版本不能与ldaps url一起使用。
解决方案是:
npm rm ldapjs
npm安装git://github.com/mcavage/node-ldapjs.git
FDO。
关于node.js - “未定义的属性”上的nodejs Passport ldapauth “Cannot read ',我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28773546/