Class: Ingenico::Connect::SDK::DefaultImpl::DefaultAuthenticator

Inherits:
Authenticator
  • Object
show all
Defined in:
lib/ingenico/connect/sdk/defaultimpl/default_authenticator.rb

Overview

Authenticates requests made to the Ingenico ePayments platform using the HMAC algorithm.

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(authorization_type, api_key_id, secret_api_key) ⇒ DefaultAuthenticator

Construct a new DefaultAuthenticator instance that can sign requests with the provided api_key_id and secret_api_key.

authorization_type

The authorization protocol to use for authentication.

api_key_id

Identifier for the secret key used in authentication.

secret_api_key

The secret key that is used to generate the authentication signature.

Raises:

  • (ArgumentError)


21
22
23
24
25
26
27
28
29
# File 'lib/ingenico/connect/sdk/defaultimpl/default_authenticator.rb', line 21

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

  @authorization_type = authorization_type
  @api_key_id = api_key_id
  @secret_api_key = secret_api_key
end

Instance Method Details

#create_simple_authentication_signature(http_method, resource_uri, http_headers) ⇒ Object

Creates a signature to authenticate a request. Uses the following parameters:

http_method

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

resource_uri

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

request_headers

RequestHeader list that contains all headers used by the request

Raises:

  • (ArgumentError)


36
37
38
39
40
41
42
# File 'lib/ingenico/connect/sdk/defaultimpl/default_authenticator.rb', line 36

def create_simple_authentication_signature(http_method, resource_uri, http_headers)
  raise ArgumentError unless http_method and not http_method.strip.empty?
  raise ArgumentError unless resource_uri

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