Class: OnlinePayments::SDK::DefaultImpl::DefaultAuthenticator
- Inherits:
-
Authenticator
- Object
- Authenticator
- OnlinePayments::SDK::DefaultImpl::DefaultAuthenticator
- Defined in:
- lib/onlinepayments/sdk/defaultimpl/default_authenticator.rb
Overview
Authenticates requests made to the Online Payments 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
-
#create_simple_authentication_signature(http_method, resource_uri, http_headers) ⇒ String
Creates a signature to authenticate a request.
-
#initialize(api_key_id, secret_api_key, authorization_type = AuthorizationType::V1HMAC) ⇒ DefaultAuthenticator
constructor
Construct a new DefaultAuthenticator instance that can sign requests with the provided api_key_id and secret_api_key.
Constructor Details
#initialize(api_key_id, secret_api_key, authorization_type = AuthorizationType::V1HMAC) ⇒ DefaultAuthenticator
Construct a new DefaultAuthenticator instance that can sign requests with the provided api_key_id and secret_api_key.
22 23 24 25 26 27 28 29 30 |
# File 'lib/onlinepayments/sdk/defaultimpl/default_authenticator.rb', line 22 def initialize(api_key_id, secret_api_key, = AuthorizationType::V1HMAC) raise ArgumentError unless api_key_id && !api_key_id.strip.empty? raise ArgumentError unless secret_api_key && !secret_api_key.strip.empty? raise ArgumentError unless && !.strip.empty? @api_key_id = api_key_id @secret_api_key = secret_api_key @authorization_type = end |
Instance Method Details
#create_simple_authentication_signature(http_method, resource_uri, http_headers) ⇒ String
Creates a signature to authenticate a request.
38 39 40 41 42 43 44 |
# File 'lib/onlinepayments/sdk/defaultimpl/default_authenticator.rb', line 38 def create_simple_authentication_signature(http_method, resource_uri, http_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, http_headers) "GCS #{@authorization_type}:#{@api_key_id}:#{create_auth_signature(data_to_sign)}" end |