Skip to content

Instantly share code, notes, and snippets.

@williamdias
Created September 6, 2017 17:03
Show Gist options
  • Select an option

  • Save williamdias/b349370d657a8e295343999a2c821d3b to your computer and use it in GitHub Desktop.

Select an option

Save williamdias/b349370d657a8e295343999a2c821d3b to your computer and use it in GitHub Desktop.
Verifying NFe.io webhook request authenticity
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