This article mainly introduces the information shared by LDAP query instances under node. js. For more information, see:
Obtain uid = kxh user data from an LDAP Server
LDAP address: ldap: // 10.233.21.116: 389
In the project root directory, first npm an LDAP access library ldpajs
Npm install ldapjs
In the project root directory, create an app. js
Var ldap = require ("ldapjs"); // create an LDAP client and pass the server url to var client = ldap. createClient ({url: 'ldap: // 10.203.24.216: 000000'}); // create an ldap query option // filter is equivalent to the SQL condition var opts = {filter: '(uid = kxh)', // query condition filter, find the user node scope: 'sub' of uid = kxh, // query range: timeLimit: 500 // query timeout }; // bind the client to LDAP Server // The first parameter is the user, which must be the full path from the root node to the user node // The second parameter is the user password client. bind ('uid = supbind, cn = users, dc = tiger, dc = com', '000000', function (err, res1) {// start query // The first parameter: the basic query path, which means that the query user confidence will be performed under this path. This path starts from the root node // The second parameter: query options client. search ('DC = tiger, DC = com', opts, function (err, res2) {// query result Event Response res2.on ('searchentry ', function (entry) {// obtain the queried object var user = entry. object; var userText = JSON. stringify (user, null, 2); console. log (userText) ;}); res2.on ('searchrefer', function (referral) {console. log ('referral: '+ referral. uris. join () ;}); // query the error event res2.on ('error', function (err) {console. error ('error: '+ err. message); // The unbind operation, which must be a client. unbind () ;}); // query end res2.on ('end', function (result) {console. log ('search status: '+ result. status); // The unbind operation, which must be a client. unbind ();});});});
For more information about LDAP query instances under node. js, see PHP!