javascript 使用 LDAP 连接 Node JS

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13138770/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 17:54:50  来源:igfitidea点击:

Connect Node JS with LDAP

javascriptnode.jsldap

提问by vinod

How to connect to LDAP using node js? Kindly help with sample code. I am not able to connect the LDAP as in post https://stackoverflow.com/questions/13134177/connect-ldap-using-node-js-segmentation-fault-error.

如何使用节点 js 连接到 LDAP?请帮助示例代码。我无法像在https://stackoverflow.com/questions/13134177/connect-ldap-using-node-js-segmentation-fault-error帖子中那样连接 LDAP 。

回答by Hüseyin BABAL

I prefer you node-LDAP.

我更喜欢你node-LDAP

In your application, you can use following structure

在您的应用程序中,您可以使用以下结构

var ldap = require('LDAP');
var ldapObj = new ldap({ uri: 'ldap://your_server', version: 3});

//check your connection
ldapObj.open(function(err) {
    if (err) {
       throw new Error('Connection problem occured!');
    }
    console.log("Connected to ldap");

});

//Search
search_options = {
    base: '',
    scope: '',
    filter: '',
    attrs: ''
}

ldapObj.search(search_options, function(err, data){
   if (err) {
      throw new Error('Search filed');
   } else {
      console.log("Search result:" + JSON.stringify(data))
   }

});

For more detail on search_options you can refer here

有关 search_options 的更多详细信息,您可以参考此处

Alternative option node-ldapjsis here

替代选项node-ldapjs这里