Class: Uploadcare::Param::WebhookSignatureVerifier

Inherits:
Object
  • Object
show all
Defined in:
lib/uploadcare/param/webhook_signature_verifier.rb

Overview

This object verifies a signature received along with webhook headers

Class Method Summary collapse

Class Method Details

.valid?(options = {}) ⇒ Boolean



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/uploadcare/param/webhook_signature_verifier.rb', line 10

def self.valid?(options = {})
  webhook_body_json = options[:webhook_body]
  signing_secret = options[:signing_secret] || ENV.fetch('UC_SIGNING_SECRET', nil)
  x_uc_signature_header = options[:x_uc_signature_header]

  digest = OpenSSL::Digest.new('sha256')

  calculated_signature = "v1=#{OpenSSL::HMAC.hexdigest(digest, signing_secret, webhook_body_json)}"

  calculated_signature == x_uc_signature_header
end