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
email << "@mycompany.com"
ldap = Net::LDAP.new(
host: 'ldap.mycompany.com',
auth: { method: :simple, email: email, password:password }
)
if ldap.bind
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
source
share