Search code examples
node.jsldapldapjs

LDAPjs find entry knowing cn


I have a remote LDAP server with entries like this:

CN=Fred Foobar, OU=Dept1, O=FooBar

Using LDAPjs as a client, how do I find this entry when only the CN is known at runtime?

I have tried each of the following, with no success:

ldap.search("cn=Fred Foobar", {}, callback); // returns an error
ldap.search("", {filter: "(cn=Fred Foobar)"}, callback); // returns nothing useful
ldap.search("", {filter: "(cn=Fred Foobar)", scope: "sub"}, callback); // returns an error

Solution

  • I never used ldapjs, but from the documentation I would try :

    ldap.search("O=FooBar", {scope:"sub", filter:"(cn=Fred Foobar)"},function(err, res) {
      // Code to handle the result
    });
    

    See doc : http://ldapjs.org/client.html#search