1

I'm binding and authentication a user to ldap as it is shown in the code below. Now i'm getting all the attributes of the object, what i want is to get just the 'distingushedName' for example. Is there a method in ldapjs for that? Is it a filter question?

Thank you !

'use strict';
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
var ldap = require('ldapjs');
const assert = require('assert');

var creds = {
  url: "ldap://************.local:389",
  bindDN: "DC=***,DC=***,DC=local"
};

var opts = {
  filter: "(&(objectClass=user))",
  scope: "sub",
  client: "*"
};
//binding
function authDN(user, baseDN, password, cb) {
  client.bind(baseDN, password, function (err) {
    client.unbind();
    cb(err === null, err);
  });
}

function output(res, err) {    
  if (res) {
    console.log('success :' + res);
  } else {
    console.log(['Error :',err.code, err.dn, err.message ]);
  }
}

var client = ldap.createClient(creds);
authDN(client, 'username', 'password', output);

//search
  client.search('CN=*** ,OU=****,...,OU=****,DC=***,DC=***,DC=local', opts, function(err, res) {
  assert.ifError(err);

  res.on('searchEntry', function(entry) {
    console.log('entry: ' + JSON.stringify(entry.object));
  });
  res.on('searchReference', function(referral) {
    console.log('referral: ' + referral.uris.join());
  });
  res.on('error', function(err) {
    console.error('error: ' + err.message);
  });
  res.on('end', function(result) {
    console.log('status: ' + result.status);
    console.log('result: ' + result);
    process.exit(1);
  });

});
Sarah ßezi
  • 99
  • 1
  • 2
  • 6

1 Answers1

1

found it, it may help somebody =)

i just added (attributes: ['distinguishedName']) to options like below :

var opts = {
  filter: "(&(objectClass=user))",
  scope: "sub",
  client: "*",
  attributes: ['distinguishedName']
};
Sarah ßezi
  • 99
  • 1
  • 2
  • 6