Class: Whatsapp::Webhook::Signature
- Inherits:
-
Object
- Object
- Whatsapp::Webhook::Signature
- Defined in:
- lib/ruby/whatsapp/webhook/signature.rb
Overview
Verifies the X-Hub-Signature-256 header Meta attaches to every webhook POST,
an HMAC-SHA256 of the raw request body keyed by the app secret.
Source: https://developers.facebook.com/documentation/business-messaging/whatsapp/webhooks/overview
Constant Summary collapse
- PREFIX =
"sha256="
Class Method Summary collapse
-
.valid?(payload:, header:, app_secret: Whatsapp.configuration.app_secret) ⇒ Boolean
Whether the header matches the computed signature.
Class Method Details
.valid?(payload:, header:, app_secret: Whatsapp.configuration.app_secret) ⇒ Boolean
Returns Whether the header matches the computed signature.
18 19 20 21 22 23 24 |
# File 'lib/ruby/whatsapp/webhook/signature.rb', line 18 def valid?(payload:, header:, app_secret: Whatsapp.configuration.app_secret) return false if header.nil? || header.empty? return false if app_secret.nil? || app_secret.empty? expected = PREFIX + OpenSSL::HMAC.hexdigest("SHA256", app_secret, payload) ActiveSupport::SecurityUtils.secure_compare(expected, header) end |