Is there a way of deciding and confirming with facts regarding, which is better and easier to integrate with Ruby. LDAP or ActiveDirectory?
I use the net-ldap gem to authenticate and query the ActiveDirectory server at work. It works well. Here's some sample code for verifying a user's login credentials and getting their full name.
def name_for_login( email, password )
email = email[/\A\w+/].downcase # Throw out the domain, if it was there
email << "@mycompany.com" # I only check people in my company
ldap = Net::LDAP.new(
host: 'ldap.mycompany.com', # Thankfully this is a standard name
auth: { method: :simple, email: email, password:password }
)
if ldap.bind
# Yay, the login credentials were valid!
# Get the user's full name and return it
ldap.search(
base: "OU=Users,OU=Accounts,DC=mycompany,DC=com",
filter: Net::LDAP::Filter.eq( "mail", email ),
attributes: %w[ displayName ],
return_result:true
).first.displayName.first
end
end
ActiveDirectory is an implementation of the LDAP. You can use the RubyLDAP gem to integrate with AD. I am currently using this gem to connect from a RHEL server to a Windows Domain Controller.
gem install ruby-ldap
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