Sha256: a536de4786a8bf606951bb916c3a6d6e4509f9e27eaa8fe7d79c8299b1105350

Contents?: true

Size: 1013 Bytes

Versions: 3

Compression:

Stored size: 1013 Bytes

Contents

module SolidusJwt
  module DeviseStrategies
    class Password < Devise::Strategies::Base
      def valid?
        valid_grant_type? && valid_params?
      end

      def authenticate!
        resource = mapping.to.find_for_database_authentication(auth_hash)

        block = proc { resource.valid_password?(password) }

        if resource&.valid_for_authentication?(&block)
          resource.after_database_authentication
          return success!(resource)
        end

        fail!(:invalid)
      end

      private

      def auth_hash
        { email: username }
      end

      def grant_type
        params[:grant_type]
      end

      def username
        params[:username]
      end

      def password
        params[:password]
      end

      def valid_grant_type?
        grant_type == 'password'
      end

      def valid_params?
        username.present? && password.present?
      end
    end
  end
end

Warden::Strategies.add(:solidus_jwt_password, SolidusJwt::DeviseStrategies::Password)

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
solidus_jwt-1.0.0 lib/solidus_jwt/devise_strategies/password.rb
solidus_jwt-1.0.0.beta2 lib/solidus_jwt/devise_strategies/password.rb
solidus_jwt-1.0.0.beta1 lib/solidus_jwt/devise_strategies/password.rb