Class: OnlinePayments::SDK::Authentication::V1HmacAuthenticator

Inherits:
Authenticator
  • Object
show all
Defined in:
lib/onlinepayments/sdk/authentication/v1hmac_authenticator.rb

Overview

Authenticates requests made to the Online Payments platform using V1Hmac.

Constant Summary collapse

HMAC_ALGOR =

HMAC algorithm used to generate the signature

'SHA256'.freeze
CONTENT_TYPE =
'Content-Type'.freeze
DATE =
'Date'.freeze
XGCS =
'x-gcs'.freeze

Instance Method Summary collapse

Constructor Details

#initialize(communicator_configuration) ⇒ V1HmacAuthenticator

Constructs a new V1HmacAuthenticator instance using the provided CommunicatorConfiguration.

Parameters:

  • communicator_configuration (OnlinePayments::SDK::CommunicatorConfiguration)

    The configuration object containing the V1Hmac authorization id and authorization secret, connection timeout, and socket timeout. None of these can be nil or empty, and the timeout values must be positive.

Raises:

  • (ArgumentError)


26
27
28
29
30
31
32
33
# File 'lib/onlinepayments/sdk/authentication/v1hmac_authenticator.rb', line 26

def initialize(communicator_configuration)
  raise ArgumentError unless communicator_configuration.api_key_id and not communicator_configuration.api_key_id.strip.empty?
  raise ArgumentError unless communicator_configuration.secret_api_key and not communicator_configuration.secret_api_key.strip.empty?

  @api_key_id = communicator_configuration.api_key_id
  @secret_api_key = communicator_configuration.secret_api_key
  @authorization_type = communicator_configuration.authorization_type
end

Instance Method Details

#get_authorization(http_method, resource_uri, request_headers) ⇒ Object

Parameters:

  • http_method (String, nil)

    ‘GET’, ‘PUT’, ‘POST’ or ‘DELETE’ indicating which HTTP method will be used with the request

  • resource_uri (URI::HTTP, nil)

    URI object that includes #path and #query of the URL that will be used, #query may be nil

  • request_headers (Array<OnlinePayments::SDK::Communication::RequestHeader>, nil)

    all headers used by the request

Raises:

  • (ArgumentError)


38
39
40
41
42
43
44
# File 'lib/onlinepayments/sdk/authentication/v1hmac_authenticator.rb', line 38

def get_authorization(http_method, resource_uri, request_headers)
  raise ArgumentError unless http_method && !http_method.strip.empty?
  raise ArgumentError unless resource_uri

  data_to_sign = to_data_to_sign(http_method, resource_uri, request_headers)
  "GCS #{@authorization_type}:#{@api_key_id}:#{create_auth_signature(data_to_sign)}"
end