Recently struggling with this, not sure why it is not working.
The bottom line is using Devise with LDAP. I do not need to do anything other than authentication, so I do not need to use anything other than a special strategy.
I created one based on https://github.com/plataformatec/devise/wiki/How-To:-Authenticate-via-LDAP , and as far as I can tell, everything should work, unless I try to start the server (or rake route) I get a NameError
lib/devise/models.rb:88:in `const_get': uninitialized constant Devise::Models::LdapAuthenticatable (NameError)
I traced the error to my app/models/user.rb
class User < ActiveRecord::Base devise :ldap_authenticatable, :rememberable, :trackable, :timeoutable end
If I delete :ldap_authenticatable , then the failure will disappear, but I have no routes to user#session , and the login prompt may not be available.
My supporting files:
lib/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 = 'redacted' ldap.port = 389 ldap.auth login, password if ldap.bind user = User.where(login: login).first_or_create do |user| success!(user) else fail(:invalid_login) end end end def login params[:user][:login] end def password params[:user][:password] end end end end Warden::Strategies.add(:ldap_authenticatable, Devise::Strategies::LdapAuthenticatable)
And finally, inside config/initializers/devise.rb
Devise.setup do |config|
I have exhausted my search, maybe someone can see what I am missing.
Greetings
ruby ruby-on-rails ruby-on-rails-4 devise
Mike gabriel
source share