class SendGrid::EventWebhook
This class allows you to use the Event Webhook feature. Read the docs for more details: sendgrid.com/docs/for-developers/tracking-events/event
Public Instance Methods
convert_public_key_to_ecdsa(public_key)
click to toggle source
verify_engine()
click to toggle source
# 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)
click to toggle source
-
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
-
# File lib/sendgrid/helpers/eventwebhook/eventwebhook.rb, line 22 def verify_signature(public_key, payload, signature, timestamp) verify_engine timestamped_playload = "#{timestamp}#{payload}" payload_digest = Digest::SHA256.digest(timestamped_playload) decoded_signature = Base64.decode64(signature) public_key.dsa_verify_asn1(payload_digest, decoded_signature) rescue StandardError false end