Skip to content

Instantly share code, notes, and snippets.

@ryanbrainard
Created January 23, 2013 22:29
Show Gist options
  • Save ryanbrainard/4614910 to your computer and use it in GitHub Desktop.
Save ryanbrainard/4614910 to your computer and use it in GitHub Desktop.
function processSignedRequest($signedRequest, $secret) {
$sep = strpos($signedRequest, '.');
$encodedSig = substr($signedRequest, 0, $sep);
$encodedEnv = substr($signedRequest, $sep + 1);
$calcedSig = base64_encode(hash_hmac("sha256", $encodedEnv, $secret, true));
if ($calcedSig != $encodedSig) {
throw new Exception("Signed request authentication failed");
}
return json_decode(base64_decode($encodedEnv))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment