Created
February 15, 2017 05:39
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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