Last active
September 28, 2021 13:20
-
-
Save khamidou/1df27edb0f7fc08d47f0 to your computer and use it in GitHub Desktop.
Verifying Nylas webhooks using Ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'openssl' | |
# verify_webhook: check that a webhook was sent by a Nylas server. | |
# params: | |
# - request: the request object you get from Rails, | |
# - nylas_app_secret: your app secret. | |
def verify_webhook(request, nylas_app_secret) | |
digest = OpenSSL::Digest.new('sha256') | |
data = request.body.read | |
digest = OpenSSL::HMAC.hexdigest(digest, nylas_app_secret, data) | |
digest == request.headers['X-Nylas-Signature'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
still works!