Sha256: a8624fb87c55e094764ad852e4d6288f097728230af7b4bcb8435dddd79e4313

Contents?: true

Size: 1.33 KB

Versions: 4

Compression:

Stored size: 1.33 KB

Contents

module AuthlogicHaapi
  # This module is responsible for allowing login via HTTP Auth using an API Key (Single access token)
  module Session
    def self.included(klass)
      klass.class_eval do
        extend Config
        include Methods
        persist :persist_by_http_auth_with_api_key, :if => :persist_by_http_auth_with_api_key?
      end
    end
    
    module Config
      # Do you want to allow your users to log in via HTTP basic auth using an API Key (single access token)?
      #
      #
      # * <tt>Default:</tt> true
      # * <tt>Accepts:</tt> Boolean
      def allow_http_basic_auth_with_api_key(value = nil)
        rw_config(:allow_http_basic_auth_with_api_key, value, true)
      end
      alias_method :allow_http_basic_auth_with_api_key=, :allow_http_basic_auth_with_api_key
    end
    
    module Methods
      
    private
      def persist_by_http_auth_with_api_key?
        allow_http_basic_auth_with_api_key?
      end
    
      def persist_by_http_auth_with_api_key
        controller.authenticate_with_http_basic do |api_key,_|
          self.unauthorized_record = search_for_record("find_by_single_access_token", api_key)
          self.valid?
        end
        false
      end
    
      def allow_http_basic_auth_with_api_key?
        self.class.allow_http_basic_auth_with_api_key == true
      end

    end
  end
end

Version data entries

4 entries across 4 versions & 3 rubygems

Version Path
quantipay-authlogic_haapi-1.0.2 lib/authlogic_haapi/session.rb
quantipay-authlogic_haapi-1.0.3 lib/authlogic_haapi/session.rb
authlogic_haapi-1.0.4 lib/authlogic_haapi/session.rb
nielsm-authlogic_haapi-1.0.4 lib/authlogic_haapi/session.rb