Class: Convoy::Webhook

Inherits:
Object
  • Object
show all
Defined in:
lib/convoy/webhook.rb

Overview

webhook := Webhook.new(secret)

With Tolerance webhook := Webhook.new(secret, tolerance: 500)

with Encoding webhook = Webhook.new(secret, encoding: “base64”)

With Encoding and Tolerance webhook = Webhook.new(secret, encoding: “base64”, tolerance: 900)

Verify request webhook.verify(payload, headers)

Instance Method Summary collapse

Constructor Details

#initialize(secret, encoding: DEFAULT_ENCODING, tolerance: DEFAULT_TOLERANCE, hash: DEFAULT_HASH) ⇒ Webhook

Returns a new instance of Webhook.



25
26
27
28
29
30
# File 'lib/convoy/webhook.rb', line 25

def initialize(secret, encoding: DEFAULT_ENCODING, tolerance: DEFAULT_TOLERANCE, hash: DEFAULT_HASH)
  @secret = secret
  @encoding = encoding
  @tolerance = tolerance
  @hash = hash
end

Instance Method Details

#verify(payload, sig_header) ⇒ Object



32
33
34
35
36
37
38
39
40
41
# File 'lib/convoy/webhook.rb', line 32

def verify(payload, sig_header)
  # 1. Detect Signature Type.
  is_advanced = (sig_header.split(",")).length > 1
  
  if is_advanced
    return verify_advanced_signature(payload, sig_header)
  end

  verify_simple_signature(payload, sig_header)
end