Sha256: 73aa179f68623b3124b4ab0c8b66406edffd252b1b7b0149fd158ebeb58f0dbb

Contents?: true

Size: 1.13 KB

Versions: 17

Compression:

Stored size: 1.13 KB

Contents

module Onfido
  class Webhook < Resource
    def create(payload)
      post(
        url: url_for('webhooks'),
        payload: payload
      )
    end

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

    def all(page: 1, per_page: 20)
      get(url: url_for("webhooks?page=#{page}&per_page=#{per_page}"))
    end

    # 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
    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

    def self.generate_signature(request_body, token)
      OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha1'), token, request_body)
    end
    private_class_method :generate_signature
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
onfido-0.15.1 lib/onfido/resources/webhook.rb
onfido-0.15.0 lib/onfido/resources/webhook.rb
onfido-0.14.0 lib/onfido/resources/webhook.rb
onfido-0.13.0 lib/onfido/resources/webhook.rb
onfido-0.12.0 lib/onfido/resources/webhook.rb
onfido-0.11.0 lib/onfido/resources/webhook.rb
onfido-0.10.0 lib/onfido/resources/webhook.rb
onfido-0.9.0 lib/onfido/resources/webhook.rb
onfido-0.8.4 lib/onfido/resources/webhook.rb
onfido-0.8.3 lib/onfido/resources/webhook.rb
onfido-0.8.2 lib/onfido/resources/webhook.rb
onfido-0.8.1 lib/onfido/resources/webhook.rb
onfido-0.7.1 lib/onfido/resources/webhook.rb
onfido-0.7.0 lib/onfido/resources/webhook.rb
onfido-0.6.1 lib/onfido/resources/webhook.rb
onfido-0.6.0 lib/onfido/resources/webhook.rb
onfido-0.5.0 lib/onfido/resources/webhook.rb