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?
Show activity on this post. var ldap = require('LDAP'); var ldapServer = new ldap({ uri: 'ldap://batman.lan', version: 3}); ldapServer. open(function(error) { if(error) { throw new Error('Cant not connect'); } else { console. log('---- connected to ldap ----'); username = '(cn='+username+')'; ldapServer.
Lightweight Directory Access Protocol (LDAP) is an application protocol for working with various directory services. In other words, while it's supported by Active Directory, it's also used with other services.
How does LDAP work with Active Directory? LDAP provides a means to manage user and group membership stored in Active Directory. LDAP is a protocol to authenticate and authorize granular access to IT resources, while Active Directory is a database of user and group information.
Select Start > Run, type ldp.exe, and then select OK. Select Connection > Connect. In Server and in Port, type the server name and the non-SSL/TLS port of your directory server, and then select OK. For an Active Directory Domain Controller, the applicable port is 389.
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With