Sha256: 7b60fda9bad6dfb77c59c3aeca5b55d173fe0d76558ffa01713a60a445c8e4c3

Contents?: true

Size: 1.99 KB

Versions: 14

Compression:

Stored size: 1.99 KB

Contents

module Authlogic
  module Session
    # Handles all authentication that deals with basic HTTP auth. Which is authentication built into the HTTP protocol:
    #
    #   http://username:password@whatever.com
    #
    # Also, if you are not comfortable letting users pass their raw username and password you can always use the single
    # access token. See Authlogic::Session::Params for more info.
    module HttpAuth
      def self.included(klass)
        klass.class_eval do
          extend Config
          include InstanceMethods
          persist :persist_by_http_auth, :if => :persist_by_http_auth?
        end
      end

      # Configuration for the HTTP basic auth feature of Authlogic.
      module Config
        # Do you want to allow your users to log in via HTTP basic auth?
        #
        # I recommend keeping this enabled. The only time I feel this should be disabled is if you are not comfortable
        # having your users provide their raw username and password. Whatever the reason, you can disable it here.
        #
        # * <tt>Default:</tt> true
        # * <tt>Accepts:</tt> Boolean
        def allow_http_basic_auth(value = nil)
          rw_config(:allow_http_basic_auth, value, true)
        end
        alias_method :allow_http_basic_auth=, :allow_http_basic_auth
      end

      # Instance methods for the HTTP basic auth feature of authlogic.
      module InstanceMethods
        private
          def persist_by_http_auth?
            allow_http_basic_auth? && login_field && password_field
          end

          def persist_by_http_auth
            controller.authenticate_with_http_basic do |login, password|
              if !login.blank? && !password.blank?
                send("#{login_field}=", login)
                send("#{password_field}=", password)
                return valid?
              end
            end

            false
          end

          def allow_http_basic_auth?
            self.class.allow_http_basic_auth == true
          end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
refinerycms-0.9.6.34 vendor/plugins/authlogic/lib/authlogic/session/http_auth.rb
refinerycms-0.9.6.33 vendor/plugins/authlogic/lib/authlogic/session/http_auth.rb
refinerycms-0.9.6.32 vendor/plugins/authlogic/lib/authlogic/session/http_auth.rb
refinerycms-0.9.6.31 vendor/plugins/authlogic/lib/authlogic/session/http_auth.rb
refinerycms-0.9.6.30 vendor/plugins/authlogic/lib/authlogic/session/http_auth.rb
refinerycms-0.9.6.29 vendor/plugins/authlogic/lib/authlogic/session/http_auth.rb
refinerycms-0.9.6.28 vendor/plugins/authlogic/lib/authlogic/session/http_auth.rb
refinerycms-0.9.6.27 vendor/plugins/authlogic/lib/authlogic/session/http_auth.rb
refinerycms-0.9.6.26 vendor/plugins/authlogic/lib/authlogic/session/http_auth.rb
refinerycms-0.9.6.25 vendor/plugins/authlogic/lib/authlogic/session/http_auth.rb
refinerycms-0.9.6.24 vendor/plugins/authlogic/lib/authlogic/session/http_auth.rb
refinerycms-0.9.6.23 vendor/plugins/authlogic/lib/authlogic/session/http_auth.rb
refinerycms-0.9.6.22 vendor/plugins/authlogic/lib/authlogic/session/http_auth.rb
refinerycms-0.9.6.21 vendor/plugins/authlogic/lib/authlogic/session/http_auth.rb