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

exit!



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/AuthenticationSDK/authentication/http/HttpSignatureHeader.rb', line 44

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) ⇒ Object

Generates Signature based on the requestType



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/AuthenticationSDK/authentication/http/HttpSignatureHeader.rb', line 21

def getToken(merchantconfig_obj, gmtdatetime)
  @log_obj = Log.new merchantconfig_obj.log_config, "GenerateHttpSignature"

  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)
  signatureHeaderValue << ', ' + Constants::SIGNATURE_PARAM + signature_value + "\""
  return signatureHeaderValue
rescue StandardError => err
  @log_obj.logger.error(ExceptionHandler.new.new_api_exception err)
  raise err
  # exit!
end