How do I do an LDAP query with JavaScript?

As long as you want to run your JavaScript in a web browser, you are limited to the HTTP protocol and to the domain from which your script was loaded in the first place.

So, talking to an LDAP server will not be possible from a web browsers JavaScript engine.

There are JavaScript runtime environments that have less limitations where you can implement socket servers and clients. For LDAP conenctivity you'd have to write your own library or find some existing one.


As Selfawaresoup already mentioned there are limitations to perfoming this on client side alone, however, if you're able to host your application/page on nodejs you can utilise an LDAP plugin with it.

Links to nodejs are as follows: https://nodejs.org/en/ https://nodejs.org/en/download/

Nodejs LDAP plugin: http://ldapjs.org/

Instruction on setting up nodejs to serve http: https://www.sitepoint.com/build-a-simple-web-server-with-node-js/ https://blog.risingstack.com/your-first-node-js-http-server/

Although it's for a specific application here's a manual demonstrating the integration of LDAP query via nodejs: https://www.ibm.com/developerworks/library/se-use-ldap-authentication-authorization-node.js-bluemix-application/index.html

Here's a working demo of it (note this is for querying public facing LDAP servers): https://login-using-ldap.mybluemix.net/

Best of luck to you however you resolve this.


I am not sure answer 1 is correct. Domain would be limited to client's domain for an active directory ldap query. However, LDAP://server is not limited to just local domain. Its limited to 'reachable' domains. If you can ping it you should be able to query it, given proper credentials.


You could write a proxy web service that translates your HTTP requests into LDAP queries, forwards them to an LDAP server and returns the results back to you. Of course that'd have both security and scalability implications and is far from trivial.