Using Apache SSPI:
http://www.zorched.net/2007/06/04/active-directory-authentication-for-ruby-on-rails/
Using LDAP:
http://www.ruby-forum.com/topic/55450#37973
A slightly different version using LDAP:
require 'net/ldap'
class User
def self.authenticate(username, password)
return false if username.to_s.size == 0
return false if password.to_s.size == 0
begin
ldap = Net::LDAP.new(
:host => AD_DOMAIN_CONTROLLER,
ort => 389,
:auth => {
:method => :simple,
:username => "#{username}", # <- AD UPN
assword => "#{password}"
}
)
rescue
return false
end
ldap.bind ? User.find_by_login("#{username}") : nil
end
end