Sha256: c8c65cf4d2d327adc0dcf1517105e36e2a2f8e8ec5f183a2587e7428fc552c0e

Contents?: true

Size: 925 Bytes

Versions: 3

Compression:

Stored size: 925 Bytes

Contents

# frozen_string_literal: true

module SolidusJwt
  module DeviseStrategies
    class Password < Base
      def authenticate!
        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 resource
        @resource ||= mapping.to.find_for_database_authentication(auth_hash)
      end

      def auth_hash
        { email: username }
      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.2.2 lib/solidus_jwt/devise_strategies/password.rb
solidus_jwt-1.2.1 lib/solidus_jwt/devise_strategies/password.rb
solidus_jwt-1.2.0 lib/solidus_jwt/devise_strategies/password.rb