Node. js LDAP query instance sharing _ node. js

Source: Internet
Author: User
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: // 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: // 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 ();});});});
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.