module Button::Utils
Generally handy functions for various aspects of a Button
integration
Public Class Methods
webhook_authentic?(webhook_secret, request_body, sent_signature)
click to toggle source
Used to verify that requests sent to a webhook endpoint are from Button
and that their payload can be trusted. Returns true if a webhook request body matches the sent signature and false otherwise.
# File lib/button/utils.rb, line 11 def webhook_authentic?(webhook_secret, request_body, sent_signature) computed_signature = OpenSSL::HMAC.hexdigest( OpenSSL::Digest.new('sha256'), webhook_secret, request_body ) sent_signature == computed_signature end
Private Instance Methods
webhook_authentic?(webhook_secret, request_body, sent_signature)
click to toggle source
Used to verify that requests sent to a webhook endpoint are from Button
and that their payload can be trusted. Returns true if a webhook request body matches the sent signature and false otherwise.
# File lib/button/utils.rb, line 11 def webhook_authentic?(webhook_secret, request_body, sent_signature) computed_signature = OpenSSL::HMAC.hexdigest( OpenSSL::Digest.new('sha256'), webhook_secret, request_body ) sent_signature == computed_signature end