Class: GenerateHttpSignature

Inherits:
Object
  • Object
show all
Defined in:
lib/AuthenticationSDK/authentication/http/HttpSignatureHeader.rb

Overview

Paramter ‘Signature’ must contain all the paramters mentioned in header above in given order

Instance Method Summary collapse

Instance Method Details

#getsignatureHeader(request_type) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/AuthenticationSDK/authentication/http/HttpSignatureHeader.rb', line 36

def getsignatureHeader(request_type)
  headers = ''
  if request_type == Constants::POST_REQUEST_TYPE
    headers = 'host date (request-target) digest ' + Constants::V_C_MERCHANT_ID
  elsif request_type == Constants::GET_REQUEST_TYPE || request_type == Constants::DELETE_REQUEST_TYPE
    headers = 'host date (request-target)' + ' ' + Constants::V_C_MERCHANT_ID
  elsif request_type == Constants::PUT_REQUEST_TYPE
    headers = 'host date (request-target) digest ' + Constants::V_C_MERCHANT_ID
  elsif request_type == Constants::PATCH_REQUEST_TYPE
    headers = 'host date (request-target) digest ' + Constants::V_C_MERCHANT_ID
  else
    raise StandardError.new(Constants::ERROR_PREFIX + Constants::INVALID_REQUEST_TYPE_METHOD)
  end
  return headers
end

#getToken(merchantconfig_obj, gmtdatetime, log_obj) ⇒ Object

Generates Signature based on the requestType



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/AuthenticationSDK/authentication/http/HttpSignatureHeader.rb', line 19

def getToken(merchantconfig_obj, gmtdatetime, log_obj)
  request_type = merchantconfig_obj.requestType.upcase
  signatureHeaderValue =''
  signatureHeaderValue << Constants::KEY_ID + merchantconfig_obj.merchantKeyId + "\""
  # Algorithm should be always HmacSHA256 for http signature
  signatureHeaderValue << ', ' + Constants::ALGORITHM + Constants::SIGNATURE_ALGORITHM + "\""
  # Headers - list is choosen based on HTTP method
  signatureheader=getsignatureHeader(request_type)
  signatureHeaderValue << ', ' + Constants::HEADERS_PARAM + signatureheader + "\""
  # Get Value for parameter 'Signature' to be passed to Signature Header
  signature_value = SignatureParameter.new.generateSignatureParameter(merchantconfig_obj, gmtdatetime, log_obj)
  signatureHeaderValue << ', ' + Constants::SIGNATURE_PARAM + signature_value + "\""
  return signatureHeaderValue
rescue StandardError => err
  ApiException.new.apiexception(err,log_obj)
  exit!
end