Skip to content

Instantly share code, notes, and snippets.

@Grayda
Created March 26, 2019 04:14
Show Gist options
  • Save Grayda/2db601b34876f418ce731c287bd54fff to your computer and use it in GitHub Desktop.
Save Grayda/2db601b34876f418ce731c287bd54fff to your computer and use it in GitHub Desktop.
Verify a Patreon webhook hash with PHP
<?php
// This example can be copied and pasted into Laravel.
// If you're not using Laravel, change the $request related stuff into PHP's native stuff (e.g. file_get_contents("php:///input") etc.)
function verifyPatreonHash(Request $request) {
$patreonBody = $request->getContent(); // This is the raw **body** of the request, which will be JSON (but don't json_decode it!)
$patreonSignature = $request->header('X-Patreon-Signature'); // And this is the header from Patreon
$webhookSecret = "Patreon Webhook Secret Here"; // This'll be the secret Patreon gave you when you created the webhook
$webhookHash = hash_hmac('md5', $patreonBody, $webhookSecret); // This is the hash we've calculated, based on the body and the secret
if(strtolower($webhookHash) == strtolower($patreonSignature)) {
return true; // Verification succeeded
} else {
return false; // Verification failed
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment