1

I am currently trying to build a proof of concept build of an LDAP connector in electron/Reactjs. My two main goals of building this connector are to be able to check if the user enters the correct credentials and LDAP address then they get a connection successful message. My second goal is to be able to make a group filter on change, so for example, if a user starts typing in a group name it will try to autofill/show groups that have that prefix/name. I have looked into two npm packages (LDAPjs & LDAPauth) but I am not sure if those packages would meet my needs as I am not trying to do any user authentication. Any tips or guidance on where to start on this are greatly appreciated!

Austin S
  • 145
  • 1
  • 10

1 Answers1

1

You can try the activedirectory2 package. It's a wrapper around ldapjs. AD has some quirks that other LDAP directories don't, so it handles some of those quirks for you. You can use its findGroups() function to look for groups by a partial name. For example:

var opts = {
    filter: "cn=*admin*",
    sizeLimit: 20
}
ad.findGroups(opts, function(err, groups) {
    //do stuff with groups
}

That would look for the first 20 groups with "admin" in the name. Just note that making a "contains" type search like this makes it impossible for AD to use any indexes, so it has to look at every group on the domain to find a match. If possible, it's better to make a "starts with" type search like "cn=admin*", which will complete much faster.

If these groups are distributions lists, you may want to search by displayName instead ("displayName=admin*"). Most environments set the displayName the same as the name of the object (cn), but that may not be the case for your environment. For distribution lists, the displayName is what is displayed to users in, say, Outlook.

You can tweak the sizeLimit to whatever you want to display. If the user enters only 2 or 3 characters, there's a good chance it'll match to a ton of groups, and it won't serve any useful purpose showing them all on the screen. So use this to limit the results to something manageable.

Gabriel Luci
  • 38,328
  • 4
  • 55
  • 84
  • I tried implementing activedirectory2 in my project but got this error any thoughts? client.js:1039 Uncaught TypeError: net.connect is not a function at connectSocket (client.js:1039) at Backoff. (client.js:1203) at Backoff.emit (events.js:152) at Backoff.push../node_modules/backoff/lib/backoff.js.Backoff.onBackoff_ (backoff.js:53) – Austin S May 22 '20 at 15:54
  • @AustinS That depends what your code is. You're better off creating a new question for that, showing your code. – Gabriel Luci May 22 '20 at 17:01
  • I created a new question here: https://stackoverflow.com/questions/61961896/using-activedirectory2-package-in-electron-react-application – Austin S May 22 '20 at 18:47