I’m going to implement RESTful user authentication against an LDAP directory in my Rails app using net-ldap. I’ve already verified that this works, but where do you put this in a Rails app? Does that go in some kind of helper? In my UsersController?
Here’s an example of some authentication code:
require 'rubygems'
require 'net/ldap'
ldap = Net::LDAP.new
ldap.encryption :simple_tls
ldap.host = 'directory.company.com'
ldap.port = 636
ldap.auth 'uid=human,ou=people,o=mycompany', 'turboSecret'
if ldap.bind
puts 'win!'
else
puts 'fail :('
end
I put this in
app/controllers/sessions_controller.rb.sessions_controller.rb