Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby with LDAP or AD [closed]

Tags:

ruby

ldap

Is there a way of deciding and confirming with facts regarding, which is better and easier to integrate with Ruby. LDAP or ActiveDirectory?

like image 560
topgun_ivard Avatar asked May 10 '26 02:05

topgun_ivard


2 Answers

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
like image 176
Phrogz Avatar answered May 11 '26 19:05

Phrogz


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
like image 34
blocktator Avatar answered May 11 '26 20:05

blocktator



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!