You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
mtmcfarl edited this page Feb 12, 2013
·
6 revisions
In config/initializers/ add a new file ldap_authenticatable.rb.
require 'net/ldap'
require 'devise/strategies/authenticatable'
module Devise
module Strategies
class LdapAuthenticatable < Authenticatable
def authenticate!
if params[:user]
ldap = Net::LDAP.new
ldap.host = [YOUR LDAP HOSTNAME]
ldap.port = [YOUR LDAP HOSTNAME PORT]
ldap.auth email, password
if ldap.bind
user = User.find_or_create_by_email(user_data)
success!(user)
else
fail(:invalid_login)
end
end
end
def email
params[:user][:email]
end
def password
params[:user][:password]
end
def user_data
{:email => email, :password => password, :password_confirmation => password}
end
end
end
end
Warden::Strategies.add(:ldap_authenticatable, Devise::Strategies::LdapAuthenticatable)
Add a configuration option in config/devise.rb
Devise.setup do |config|
config.warden do |manager|
manager.default_strategies(:scope => :user).unshift :ldap_authenticatable
end
# ... rest of devise config
end