Rails authentication with LDAP -


i learning rails(no experience in web development , mvc), , improve skills, wanted implement application authentication done in ldap. have been reading rails 4 in action ryan bigg , ruby on rails tutorial michael hartl. in tutorials, applications developed needs authentication system. build authentication system scratch. since username/passwords saved in database generate user model. question is, if save user data in ldap(and authentication via ldap), need generate user model? user model used saving cookies(to remember user sessions). mean should generate user model save session data? pointer appreciated.

you not need create model inheriting activerecord::base class, having class hold user information suitable - if duration of run time. or wanto authentication , forget user?

if interested in using ldap de facto standard rails gem authentication - devise , take @ wiki page https://github.com/plataformatec/devise/wiki/how-to:-authenticate-via-ldap.

all have do, use custom authentification strategy.

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: email) #optional lookup             success!(user) # have return object           else             fail(:invalid_login)           end         end       end        def email         params[:user][:email]       end        def password         params[:user][:password]       end      end   end end  warden::strategies.add(:ldap_authenticatable, devise::strategies::ldapauthenticatable) 

if want avoid using devise go warden-ldap https://github.com/renewablefunding/warden-ldap.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -