javascriptldaprequirejsclient-sideldapjs

how to make a request to Ldap with client-side Javascript?


I should make a request to LDAP client side possibly with Javascript. I searched in the web finding ldapjs that does what I want, but server side. This:

var ldap = require('ldapjs');

var server = ldap.createServer();

server.search('o=example', function(req, res, next) {
  var obj = {
    dn: req.dn.toString(),
    attributes: {
      objectclass: ['organization', 'top'],
      o: 'example'
    }
  };

  if (req.filter.matches(obj.attributes))
    res.send(obj);

  res.end();
});

server.listen(1389, function() {
  console.log('LDAP server listening at %s', server.url);
});

So I tried using requirejs to import a library ldapjs client side, but was unable to make it work. There is no file called ldapjs to import. I'm on the right track? There are other ways?

I'm forced to stay on the client side


Solution

  • 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.

    For do that install node.js and run your application locally.