gpt4 book ai didi

node.js - nodejs passport ldapauth "Cannot read ' on' property of undefined"

转载 作者:搜寻专家 更新时间:2023-10-31 22:23:51 24 4
gpt4 key购买 nike

我正在尝试使用 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-ldapauth@0.3.0

有人可以帮助我吗?

谢谢。

最佳答案

终于,我可以解决这个问题了。

在 ldapauth-fork 中使用的 ldapjs 版本,不能使用 ldaps url。

解决方案是:

  1. 使用以下命令从 ldapauth-fork 中的 ldapauth-fork 下的 node_modules 目录中删除 ldapjs(在我的用户的 node_modules 中 passport-ldap 下的其他 node_modules 目录下 !!!!!):

    npm rm ldapjs

  2. 使用 github 安装新版本:

    npm 安装 git://github.com/mcavage/node-ldapjs.git

FDO.

关于node.js - nodejs passport ldapauth "Cannot read ' on' property of undefined",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28773546/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com