【问题标题】:nodejs passport ldapauth "Cannot read 'on' property of undefined"nodejs护照ldapauth“无法读取未定义的'on'属性”
【发布时间】: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


    【解决方案1】:

    终于可以解决问题了。

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

    解决办法是:

    1. 使用以下命令从 ldapauth-fork 中删除 ldapjs:

      npm rm ldapjs

    2. 使用以下命令从 github 安装新版本:

      npm install git://github.com/mcavage/node-ldapjs.git

    FDO。

    【讨论】:

    【解决方案2】:

    只有在使用 SSL 时 Node 0.12 和 io.js 才会发生这种情况,请参阅 ldapjs issue。您可以在项目package.json中添加对未发布版本的依赖:

    {
      "dependencies": {
        "ldapjs": "mcavage/node-ldapjs",
        "ldapauth-fork": "2.3.1"
      }
    }
    

    【讨论】:

    • @Paul 现在应该在没有这个的情况下使用最新版本,ldapauth-fork 使用 ldapjs 1.0.0。
    • 很高兴知道。但是,我使用的 passport-ldapauth 版本没有,所以这让我走上了正确的道路。
    猜你喜欢
    • 2021-11-19
    • 1970-01-01
    • 2015-11-25
    • 2021-11-23
    • 1970-01-01
    • 2022-06-15
    • 2018-12-17
    • 2016-06-30
    • 2016-05-09
    相关资源
    最近更新 更多