Denis
Denis

Reputation: 133

ldap nodejs active directory authentication

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?

Upvotes: 9

Views: 9058

Answers (3)

Christophe
Christophe

Reputation: 175

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.

Upvotes: 0

Denis
Denis

Reputation: 133

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!

Upvotes: 4

Patrick Doran
Patrick Doran

Reputation: 36

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.

Upvotes: 0

Related Questions