Sha256: 6f0e05b4398e7de52e02b996a94daedb62c618c46b2acaffbfa3e5d49f7a0ba8

Contents?: true

Size: 1.52 KB

Versions: 2

Compression:

Stored size: 1.52 KB

Contents

module Devise
  module Strategies
    class RemoteAuthenticatable < Authenticatable

      # def valid?
      #   true || params[scope]
      # end

      # For an example check : https://github.com/plataformatec/devise/blob/master/lib/devise/strategies/database_authenticatable.rb
      # Method called by warden to authenticate a resource.
      def authenticate!
        # authentication_hash doesn't include the password
        auth_params = params[scope]


        # mapping.to is a wrapper over the resource model
        resource = mapping.to.new.remote_authentication(auth_params)

        return fail! unless resource

        # remote_authentication method is defined in Devise::Models::RemoteAuthenticatable
        #
        # validate is a method defined in Devise::Strategies::Authenticatable. It takes
        # a block which must return a boolean value.
        #
        # If the block returns true the resource will be loged in
        # If the block returns false the authentication will fail!
        if validate(resource) { resource.password_valid }
          success!(resource)
        end
      end
    end
  end
end

Warden::Strategies.add :remote_authenticatable, Devise::Strategies::RemoteAuthenticatable
Devise.add_module :remote_authenticatable, strategy: true, controller: :sessions, route: :session

Warden::Manager.after_authentication do |user, auth, opts|
  Rails.cache.delete(['user', user.to_key]) if user
end

Warden::Manager.before_logout do |user, auth, opts|
  Rails.cache.delete(['user', user.to_key]) if user
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mno-enterprise-core-3.4.0 lib/devise/strategies/remote_authenticatable.rb
mno-enterprise-core-3.3.3 lib/devise/strategies/remote_authenticatable.rb