Class: Worldline::Connect::SDK::Authentication::V1HMACAuthenticator

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

Overview

Authenticates requests made to the Worldline Global Collect platform using the HMAC algorithm.

Instance Method Summary collapse

Constructor Details

#initialize(api_key_id, secret_api_key) ⇒ V1HMACAuthenticator

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

Parameters:

  • api_key_id (String)

    identifier for the secret key used in authentication.

  • secret_api_key (String)

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

Raises:

  • (ArgumentError)


17
18
19
20
21
22
23
# File 'lib/worldline/connect/sdk/authentication/v1hmac_authenticator.rb', line 17

def initialize(api_key_id, secret_api_key)
  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?

  @api_key_id = api_key_id
  @secret_api_key = secret_api_key
end

Instance Method Details

#get_authorization(http_method, resource_uri, http_headers) ⇒ String

Creates a signature to authenticate a request.

Parameters:

  • http_method (String)

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

  • resource_uri (URI::HTTP)

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

  • http_headers (Array<Worldline::Connect::SDK::Communicator::RequestHeader>)

    list that contains all headers used by the request

Returns:

  • (String)

    the created signature

Raises:

  • (ArgumentError)


31
32
33
34
35
36
37
# File 'lib/worldline/connect/sdk/authentication/v1hmac_authenticator.rb', line 31

def get_authorization(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 v1HMAC:#{@api_key_id}:#{create_auth_signature(data_to_sign)}"
end