Verifying request of Webhook Verifying request of Webhook wordpress wordpress

Verifying request of Webhook


Ok I figured out the issue I was having. In case anyone else is trying to work with WooCommerce web hook it seems my issue was appropriately grabbing the header file of the request to match it against my calculated HMAC.

SHARED_SECRET = "my_secret"def verify_webhook(data, hmac_header)    hash  = OpenSSL::Digest::Digest.new('sha256')    calculated_hmac = Base64.encode64(OpenSSL::HMAC.digest(hash, SHARED_SECRET, data)).strip    Rack::Utils.secure_compare(calculated_hmac, hmac_header)enddef restrict_access    data = request.body.read    head = request.headers["X-WC-Webhook-Signature"]    verified = verify_webhook(data, head)    if verified        return    else        render nothing: true, status: :unauthorized    endend