Skip to content

Instantly share code, notes, and snippets.

@samuel-cloete
Created February 15, 2017 05:39
Show Gist options
  • Save samuel-cloete/66440c9628ed49f42d9469921fef74ec to your computer and use it in GitHub Desktop.
Save samuel-cloete/66440c9628ed49f42d9469921fef74ec to your computer and use it in GitHub Desktop.
Verify whether a request came from your app on Facebook - specifically used for Laravel
/**
* Verify whether the given request really comes from your app on FB
*
* @param Illuminate\Http\Request $request
* @return bool
**/
public function verifySignature(Request $request)
{
if (! $request->hasHeader('X-Hub-Signature')) {
return false;
}
list($algo, $hash) = explode('=', $request->header('X-Hub-Signature'), 2) + array('', '');
if ($hash !== hash_hmac($algo, $request->getContent(), env('FACEBOOK_APP_SECRET')) {
return false;
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment