Created
September 6, 2017 17:03
-
-
Save williamdias/b349370d657a8e295343999a2c821d3b to your computer and use it in GitHub Desktop.
Verifying NFe.io webhook request authenticity
This file contains hidden or 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
| def request_is_authentic? | |
| body = request.body.read | |
| hmac = OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha1'), ENV.fetch("NFEIO_WEBHOOK_SECRET"), body) | |
| hash = 'sha1=' + Base64.strict_encode64(hmac) | |
| signature = request.headers['X-NFEIO-Signature'] | |
| ActiveSupport::SecurityUtils.secure_compare(hash, signature) | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment