Class: Challah::ApiKeyTechnique

Inherits:
Object
  • Object
show all
Defined in:
lib/challah/techniques/api_key_technique.rb

Overview

Allows authentication with an api_key URL parameter.

Instance Method Summary collapse

Constructor Details

#initialize(session) ⇒ ApiKeyTechnique

Returns a new instance of ApiKeyTechnique.



4
5
6
# File 'lib/challah/techniques/api_key_technique.rb', line 4

def initialize(session)
  @key = session.key? ? session.key : nil
end

Instance Method Details

#authenticateObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/challah/techniques/api_key_technique.rb', line 8

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.find_by_api_key(@key)

    if user and user.active?
      return user
    end
  end

  nil
end

#persist?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/challah/techniques/api_key_technique.rb', line 24

def persist?
  false
end