Class: Onfido::Webhook

Inherits:
Resource show all
Defined in:
lib/onfido/resources/webhook.rb

Constant Summary

Constants inherited from Resource

Resource::REQUEST_TIMEOUT_HTTP_CODE, Resource::VALID_HTTP_METHODS

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Resource

#initialize

Constructor Details

This class inherits a constructor from Onfido::Resource

Class Method Details

.valid?(request_body, request_signature, token) ⇒ Boolean

As well as being a normal resource, Onfido::Webhook also supports verifying the authenticity of a webhook by comparing the signature on the request to one computed from the body

Returns:

  • (Boolean)


19
20
21
22
23
24
25
26
27
# File 'lib/onfido/resources/webhook.rb', line 19

def self.valid?(request_body, request_signature, token)
  if [request_body, request_signature, token].any?(&:nil?)
    raise ArgumentError, "A request body, request signature and token " \
                         "must be provided"
  end

  computed_signature = generate_signature(request_body, token)
  Rack::Utils.secure_compare(request_signature, computed_signature)
end

Instance Method Details

#allObject



12
13
14
# File 'lib/onfido/resources/webhook.rb', line 12

def all
  get(path: 'webhooks')
end

#create(url:, **payload) ⇒ Object



3
4
5
6
# File 'lib/onfido/resources/webhook.rb', line 3

def create(url:, **payload)
  payload[:url] = url
  post(path: 'webhooks', payload: payload)
end

#find(webhooks_id) ⇒ Object



8
9
10
# File 'lib/onfido/resources/webhook.rb', line 8

def find(webhooks_id)
  get(path: "webhooks/#{webhooks_id}")
end