Node-ldapjs: How do i bind the binddn in ldapjs to authenticate a user ..

Created on 3 May 2013  路  7Comments  路  Source: ldapjs/node-ldapjs

I have following configuration and could you please let me know the how to use the ldapjs to authenticate ...

question

Most helpful comment

@narendrachoudhary
If you're looking to authenticate a user DN and password, this might be a decent starting point:

var ldap = require('ldapjs');

function authDN(dn, password, cb) {
  var client = ldap.createClient({url: 'ldap://YOUR_SERVER:PORT'});

  client.bind(dn, password, function (err) {
    client.unbind();
    cb(err === null, err);
  });
}


function output(res, err) {
  if (res) {
    console.log('success');
  } else {
    console.log('failure');
  }
}

// should print "success"
authDN('cn=user', 'goodpasswd', output);
// should print "failure"
authDN('cn=user', 'badpasswd', output);

All 7 comments

@narendrachoudhary
If you're looking to authenticate a user DN and password, this might be a decent starting point:

var ldap = require('ldapjs');

function authDN(dn, password, cb) {
  var client = ldap.createClient({url: 'ldap://YOUR_SERVER:PORT'});

  client.bind(dn, password, function (err) {
    client.unbind();
    cb(err === null, err);
  });
}


function output(res, err) {
  if (res) {
    console.log('success');
  } else {
    console.log('failure');
  }
}

// should print "success"
authDN('cn=user', 'goodpasswd', output);
// should print "failure"
authDN('cn=user', 'badpasswd', output);

@pfmooney can you please help me with the code line cb(err === null, err); What does it mean I am very new to node.js

@mvgadagi Its calling the cb function which is passed in as the third argument.
err === null will evaluate to either true or false if 'err' is set or not, then is passes 'err' as the actual error.

@pfmooney Okay Thanks much!!

hello everyone,
i have the same topic to do but am a little bit confused.
This program will be on a .js file and we should link it with a html file to get the data( username and password), isn't it ?
thank you for you answer.
if you have a complete example i would be pleased to try it.
Thank you again.

connect ETIMEDOUT 192.168.95.66:389
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1097:14)

i am using the above code which is given above . iam getting the following error please provide the solution for the above error.

@srikanth9010 looks like the client is timing out when trying to connect to the server. You could set the connectTimeout option to try to wait longer before failing.

Was this page helpful?
0 / 5 - 0 ratings