Created
January 23, 2013 22:29
-
-
Save ryanbrainard/4614910 to your computer and use it in GitHub Desktop.
Sample of processing an SFDC signed request in PHP. To see it in context in in Workbench, see: https://github.com/ryanbrainard/forceworkbench/blob/b9d9ba376c255a8970bc8d10686124747fab9039/workbench/controllers/LoginController.php#L143-L164
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
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