ruby on rails - Creating a custom Devise Strategy -


been fighting while now, not sure why isn't working.

the gist looking use devise ldap. don't need except authenticate have no need use except custom strategy.

i created 1 based on https://github.com/plataformatec/devise/wiki/how-to:-authenticate-via-ldap , far can tell should work except whenever try run server (or rake route) nameerror

lib/devise/models.rb:88:in `const_get': uninitialized constant devise::models::ldapauthenticatable (nameerror) 

i've traced error down app/models/user.rb

class user < activerecord::base   devise :ldap_authenticatable, :rememberable, :trackable, :timeoutable end 

if remove :ldap_authenticatable crash goes away have no routes user#session , login prompt cannot accessed.

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 |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 |config|   # ==> ldap configuration   require 'ldap_authenticatable'   config.warden |manager|     manager.default_strategies(:scope => :user).unshift :ldap_authenticatable   end end 

i've exhausted searches, maybe can see missing.

cheers

is lib/ldap_authenticatable.rb in autoload path or explicitly required? since rails 3 code in lib folder isn't autoloaded default more. here 1 way on how solve it

imho devise great gem. in order write own strategy have familiar not devise warden source code well, , lot of boilerplate code needs written in various places, start investigate how make customizations easier devise , come gem devise_custom_authenticatable. can check , it'll solve problem in different way. gem used in production code base rather busy application, battle proven :)


Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -