Class: Challah::ApiKeyTechnique
- Inherits:
-
Object
- Object
- Challah::ApiKeyTechnique
- Defined in:
- lib/challah/techniques/api_key_technique.rb
Overview
Allows authentication with an api_key URL parameter.
Instance Attribute Summary collapse
-
#user_model ⇒ Object
Returns the value of attribute user_model.
Instance Method Summary collapse
- #authenticate ⇒ Object
-
#initialize(session) ⇒ ApiKeyTechnique
constructor
A new instance of ApiKeyTechnique.
- #persist? ⇒ Boolean
Constructor Details
#initialize(session) ⇒ ApiKeyTechnique
Returns a new instance of ApiKeyTechnique.
7 8 9 |
# File 'lib/challah/techniques/api_key_technique.rb', line 7 def initialize(session) @key = session.key? ? session.key : nil end |
Instance Attribute Details
#user_model ⇒ Object
Returns the value of attribute user_model.
5 6 7 |
# File 'lib/challah/techniques/api_key_technique.rb', line 5 def user_model @user_model end |
Instance Method Details
#authenticate ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# 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.[: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? ⇒ Boolean
27 28 29 |
# File 'lib/challah/techniques/api_key_technique.rb', line 27 def persist? false end |