Ruby with LDAP or AD

Is there a way to solve and confirm with facts that integrate better and easier with Ruby. LDAP or ActiveDirectory?

+3
source share
3 answers

ActiveDirectory is an implementation of LDAP. You can use RubyLDAP to integrate with AD. I am currently using this stone to connect from an RHEL server to a Windows domain controller.

gem install ruby-ldap
+3
source

I use net-ldap gem to authenticate and request an ActiveDirectory server at work. It works well. Here is sample code to verify user credentials and get 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 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
+4
source

LDAP Ruby - , . , , ActiveDirectory LDAP. ActiveDirectory Ruby.

+1
source

Source: https://habr.com/ru/post/1746163/


All Articles