Class: HashAuth::Strategies::Default

Inherits:
Base
  • Object
show all
Defined in:
lib/hash-auth/strategies/default.rb

Class Method Summary collapse

Class Method Details

.acquire_string_to_hash(controller, client) ⇒ Object



9
10
11
12
# File 'lib/hash-auth/strategies/default.rb', line 9

def self.acquire_string_to_hash(controller, client)
  params = controller.params.select{|k,v| !['controller', 'action', 'format', client.signature_param].include? k }.map{|k,v| "#{k}=#{v}"}.join('&')
  params + client.customer_key.to_s
end

.hash_string(client, string) ⇒ Object



14
15
16
17
# File 'lib/hash-auth/strategies/default.rb', line 14

def self.hash_string(client, string)
  digest = Digest::SHA256.new
  digest.hexdigest string
end

.identifierObject



5
6
7
# File 'lib/hash-auth/strategies/default.rb', line 5

def self.identifier
  :default
end

.on_authentication(client, controller) ⇒ Object



24
25
26
# File 'lib/hash-auth/strategies/default.rb', line 24

def self.on_authentication(client, controller)
  # Do nothing
end

.on_failure(client, controller, type) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/hash-auth/strategies/default.rb', line 28

def self.on_failure(client, controller, type)
  case type
  when :no_matching_client
    controller.instance_variable_set '@failure_message', 'Not a valid client'
  when :invalid_domain
    controller.instance_variable_set '@failure_message', 'Request coming from invalid domain'
  when :invalid_hash
    controller.instance_variable_set '@failure_message', 'Signature hash is invalid'
  when :invalid_ip
    controller.instance_variable_set '@failure_message', 'Request coming from invalid IP' 
  end
end

.sign_request(client, verb, params) ⇒ Object



41
42
43
# File 'lib/hash-auth/strategies/default.rb', line 41

def self.sign_request(client, verb, params)
  self.hash_string(client, params.map{|k,v| "#{k}=#{v}"}.join('&') + client.customer_key.to_s)
end

.verify_hash(target_string, client, controller) ⇒ Object



19
20
21
22
# File 'lib/hash-auth/strategies/default.rb', line 19

def self.verify_hash(target_string, client, controller)
  return false if controller.params[client.signature_param] == nil
  target_string == controller.params[client.signature_param]
end