Class: SendGrid::EventWebhook
- Inherits:
-
Object
- Object
- SendGrid::EventWebhook
- Defined in:
- lib/sendgrid/helpers/eventwebhook/eventwebhook.rb
Overview
This class allows you to use the Event Webhook feature. Read the docs for more details: sendgrid.com/docs/for-developers/tracking-events/event
Defined Under Namespace
Classes: Error, NotSupportedError
Instance Method Summary collapse
-
#convert_public_key_to_ecdsa(public_key) ⇒ Object
-
Args : -
public_key
-> verification key under Mail Settings.
-
- #verify_engine ⇒ Object
-
#verify_signature(public_key, payload, signature, timestamp) ⇒ Object
-
Args : -
public_key
-> elliptic curve public key -payload
-> event payload in the request body -signature
-> signature value obtained from the ‘X-Twilio-Email-Event-Webhook-Signature’ header -timestamp
-> timestamp value obtained from the ‘X-Twilio-Email-Event-Webhook-Timestamp’ header.
-
Instance Method Details
#convert_public_key_to_ecdsa(public_key) ⇒ Object
-
Args :
-
public_key
-> verification key under Mail Settings
-
12 13 14 15 |
# File 'lib/sendgrid/helpers/eventwebhook/eventwebhook.rb', line 12 def convert_public_key_to_ecdsa(public_key) verify_engine OpenSSL::PKey::EC.new(Base64.decode64(public_key)) end |
#verify_engine ⇒ Object
32 33 34 35 |
# File 'lib/sendgrid/helpers/eventwebhook/eventwebhook.rb', line 32 def verify_engine # JRuby does not fully support ECDSA: https://github.com/jruby/jruby-openssl/issues/193 raise NotSupportedError, "Event Webhook verification is not supported by JRuby" if RUBY_PLATFORM == "java" end |
#verify_signature(public_key, payload, signature, timestamp) ⇒ Object
-
Args :
-
public_key
-> elliptic curve public key -
payload
-> event payload in the request body -
signature
-> signature value obtained from the ‘X-Twilio-Email-Event-Webhook-Signature’ header -
timestamp
-> timestamp value obtained from the ‘X-Twilio-Email-Event-Webhook-Timestamp’ header
-
22 23 24 25 26 27 28 29 30 |
# File 'lib/sendgrid/helpers/eventwebhook/eventwebhook.rb', line 22 def verify_signature(public_key, payload, signature, ) verify_engine = "#{}#{payload}" payload_digest = Digest::SHA256.digest() decoded_signature = Base64.decode64(signature) public_key.dsa_verify_asn1(payload_digest, decoded_signature) rescue StandardError false end |