Class: Onfido::WebhookEventVerifier
- Inherits:
-
Object
- Object
- Onfido::WebhookEventVerifier
- Defined in:
- lib/onfido/webhook_event_verifier.rb
Instance Method Summary collapse
-
#initialize(webhook_token) ⇒ WebhookEventVerifier
constructor
A new instance of WebhookEventVerifier.
- #read_payload(event_body, signature) ⇒ Object
Constructor Details
#initialize(webhook_token) ⇒ WebhookEventVerifier
Returns a new instance of WebhookEventVerifier.
8 9 10 |
# File 'lib/onfido/webhook_event_verifier.rb', line 8 def initialize(webhook_token) @webhook_token = webhook_token end |
Instance Method Details
#read_payload(event_body, signature) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/onfido/webhook_event_verifier.rb', line 12 def read_payload(event_body, signature) event_signature = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), @webhook_token, event_body) raise(OnfidoInvalidSignatureError, "Invalid signature for webhook event") unless OpenSSL.secure_compare(signature, event_signature) WebhookEvent.build_from_hash(JSON.parse(event_body)) end |