class Challah::ApiKeyTechnique

Allows authentication with an api_key URL parameter.

Attributes

user_model[RW]

Public Class Methods

new(session) click to toggle source
# File lib/challah/techniques/api_key_technique.rb, line 7
def initialize(session)
  @key        = session.key? ? session.key : nil
end

Public Instance Methods

authenticate() click to toggle source
# File lib/challah/techniques/api_key_technique.rb, line 11
def authenticate
  # Api key functionality is only enabled with the :api_key_enabled option. This is turned
  # off by default and must be manually enabled for security reasons.
  return nil unless Challah.options[:api_key_enabled]

  unless @key.to_s.blank?
    user = user_model.find_by_api_key(@key)

    if user and user.valid_session?
      return user
    end
  end

  nil
end
persist?() click to toggle source
# File lib/challah/techniques/api_key_technique.rb, line 27
def persist?
  false
end