【发布时间】:2015-04-30 15:58:12
【问题描述】:
我正在尝试使用 passport-ldapauth 和 express 对 LDAP 服务器进行身份验证。
使用 ldap url (ldap://myserver...) 的身份验证工作正常,但使用 ldaps 我得到:
TypeError:无法读取未定义的属性“on” 在 setupSocket (...\ldapauth-fork\node_modules\ldapjs\lib\client\client.js:111:14) 在 Client._connect (...\ldapauth-fork\node_modules\ldapjs\lib\client\client.js:742:3) 在新客户端 (...\ldapauth-fork\node_modules\ldapjs\lib\client\client.js:247:22) 在 Object.createClient (...\ldapauth-fork\node_modules\ldapjs\lib\client\index.js:60:12) 在新的 LdapAuth (...\ldapauth-fork\lib\ldapauth.js:129:28) 在 handleAuthentication (...\passport-ldapauth\lib\passport-ldapauth\strategy.js:140:10) 在 Strategy.authenticate (...\passport-ldapauth\lib\passport-ldapauth\strategy.js:175:33) 尝试 (...\passport\lib\middleware\authenticate.js:341:16) 在验证 (...\passport\lib\middleware\authenticate.js:342:7) 在 Layer.handle [as handle_request] (...\express\lib\router\layer.js:82:5)我的代码基本上是这样的:
...
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-ldapauth@0.3.0
有人可以帮助我吗?
谢谢。
【问题讨论】:
标签: node.js ssl ldap passport.js