Ruby on Rails HTTP Basic Auth with LDAP
// December 8th, 2008 // 8 Comments » // Blog
My friend Fred has a nifty tip over on his Binary Fever blog about Ruby on Rails LDAP authentication using HTTP Basic Auth. I took what he had done and made a few minor improvements:
# mygeneric_controller.rb
LDAPBASE = ‘, ou=active, ou=employees, ou=people, o=host.com’
before_filter :authenticate
protected
def authenticate
authenticate_or_request_with_http_basic('LDAP Login') do |username, password|
ldap = Net::LDAP.new :host => ‘ldap.host.com’, :base => LDAPBASE
ldap.auth ‘uid=’ + username + LDAPBASE, password
if ldap.bind
@point_person = PointPerson.find_by_username(username)
if !@point_person.nil?
return true
end
else
return false
end
end
end



