Class: DIDWW::Callback::RequestValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/didww/callback/request_validator.rb

Overview

signature = env validator.validate(uri, params, signature) #=> true if the request is from DIDWW # or with rails

Examples:

validator = DIDWW::Callback::RequestValidator.new(api_key)
uri = request.original_url
if request.post?
  # Collect all parameters passed from DIDWW.
  params = env['rack.request.form_hash']
else
  params = env['rack.request.query_hash']
end

Constant Summary collapse

DIGEST_ALGO =
'SHA1'
HEADER =
'X-DIDWW-Signature'

Instance Method Summary collapse

Constructor Details

#initialize(api_key) ⇒ RequestValidator

Returns a new instance of RequestValidator.



23
24
25
# File 'lib/didww/callback/request_validator.rb', line 23

def initialize(api_key)
  @api_key = api_key
end

Instance Method Details

#validate(url, payload, signature) ⇒ Boolean

Returns whether signature valid or not.

Parameters:

  • url (String)
  • payload (Hash)
  • signature (String)

Returns:

  • (Boolean)

    whether signature valid or not.



31
32
33
34
35
# File 'lib/didww/callback/request_validator.rb', line 31

def validate(url, payload, signature)
  return false if signature.blank?

  signature == valid_signature(url, payload)
end