Sha256: e238986db1d3052094a971f96e99e921cdff598b623d667b1cd5052dfea7b78e

Contents?: true

Size: 1.04 KB

Versions: 1

Compression:

Stored size: 1.04 KB

Contents

module OmniAuth
  module MultiPassword
    module Base
      def self.included(base)
        base.class_eval do
          option :title,  "Restricted Access"
          option :fields, [ :username, :password ]

          uid  { username }
        end
      end

      def username_id
        options[:fields][0] || "username"
      end

      def password_id
        options[:fields][1] || "password"
      end

      def username
        @username || request[username_id].to_s
      end

      def init_authenticator(request, env, username)
        @request  = request
        @env      = env
        @username = username
      end

      def callback_phase
        if authenticate(username, request[password_id])
          super
        else
          fail!(:invalid_credentials)
        end
      end

      def request_phase
        OmniAuth::Form.build(:title => options.title, :url => callback_url) do |f|
          f.text_field     "Username", username_id
          f.password_field "Password", password_id
        end.to_response
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
omniauth-multipassword-0.4.2 lib/omniauth/multipassword/base.rb