11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/k2-connect-ruby/k2_utilities/k2_authenticator.rb', line 11
def authenticate(body, api_secret_key, signature)
if body.blank? || api_secret_key.blank? || signature.blank?
raise ArgumentError, "Nil Authentication Argument!\n Check whether your Input is Empty"
end
digest = OpenSSL::Digest.new("sha256")
hmac = OpenSSL::HMAC.hexdigest(digest, api_secret_key, body.to_json)
unless ActiveSupport::SecurityUtils.secure_compare(hmac, signature)
raise ArgumentError, "Invalid Details Given!\n Ensure that your the Arguments Given are correct, namely:\n\t- The Response Body\n\t- Secret Key\n\t- Signature"
end
true
end
|