9

I am currently working on a web application in node.js in which a user needs to log in to access the information. I want to check the user login and password with an external active directory server. I have tried using node-ldapauth, but I can't get it work (I don't know if it works for active directories, maybe just openLdap). Any suggestions?

3 Answers 3

4

I used an rubyldap library to solve the problem thanks!

Update: As requested this is the library I used to solve the problem https://github.com/ruby-ldap/ruby-net-ldap/

After installing the ruby library on your server, using gem install (look it up it's not too hard)

 require 'rubygems'
  require 'net/ldap'

  ldap = Net::LDAP.new :host => server_ip_address,
       :port => 389,
       :auth => {
             :method => :simple,
             :username => "cn=manager, dc=example, dc=com",
             :password => "opensesame"
       }

  filter = Net::LDAP::Filter.eq("cn", "George*")
  treebase = "dc=example, dc=com"

  ldap.search(:base => treebase, :filter => filter) do |entry|
    puts "DN: #{entry.dn}"
    entry.each do |attribute, values|
      puts "   #{attribute}:"
      values.each do |value|
        puts "      --->#{value}"
      end
    end
  end

  p ldap.get_operation_result

Set up a ruby file as shown above.

You can run the ruby library by using

var ldap = 'ruby '+process.cwd()+'/src/ruby/ruby_file_name '+ user+' '+password;

To grab the user and password in ruby use ARGV[0] and ARGV1. You can grab the ruby returned result in node.js by using a call back function

var result = exec(ldap, theCallBack);

in the theCallBack function you can grab the returned ruby library results by passing in stdout

ex:

function theCallBack(err,stdout) {
    ----your code here, stdout is what you PUT in the ruby library.

Hope this helps!

1
  • 1
    It'd be great if you could edit this answer to include some more info/links/code about the solution you used so it can help others who may have this problem.
    – Dhaust
    Jul 27, 2012 at 0:56
0

Could you post the snipet of your code and the error you get?

I am trying to do the similar and came across the ldapjs library. It allows you to implement a client ldap connection to an LDAP server and you can, in doing the connection validate the users username and password.

I tried setting it up on windows with 0.8.2 and ran in to some issues, which it sounds like the developer is looking in to. The nice aspect of this library is it doesn't rely on the OpenLDAP binding that the one you referenced does.

4
  • github.com/mcavage/node-ldapjs/issues/81 is the issue mentioned the installation problem on Windows.
    – Christophe
    Jul 19, 2012 at 15:04
  • So a snippet of my code looks just like the ldapauth libary github.com/trentm/node-ldapauth pretty much used the example code
    – Denis
    Jul 19, 2012 at 21:37
  • If I console.log(ldap) i get something like this in return connection: { pair: [Object], writable: true, readable: true, _paused: false, _needDrain: false, _pending: [], _pendingCallbacks: [], _pendingBytes: 0, socket: [Object], encrypted: [Object], so on and so forth
    – Denis
    Jul 19, 2012 at 21:39
  • However when I call the ldap.authenticate nothing happens, which makes me think that perhaps it doesn't work with active directory. The Active Directory server in my case is already set up with all users information in the directory, so i really don't have the option to change the type of LDAP i am running on as it is a company Active Directory
    – Denis
    Jul 19, 2012 at 21:41
0

For having ldapjs installation working on Windows, I wrote the steps I followed here http://tochedev.blogspot.be/2012/07/i-wanted-to-add-ldapjs-to-my-windows.html

Hope this helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.