Example code of FBML App that uses signed_request?
We did not know that Oct 1 is also deadline for signed_request. Does anyone have example code to do signed_request for FBML apps? We开发者_Go百科 are trying to beat the deadline on Oct 1. Thanks!
The signed_request documentation shows how to do it in PHP. It's pretty easy to do in any language.
function parse_signed_request($signed_request, $secret) {
list($encoded_sig, $payload) = explode('.', $signed_request, 2);
// decode the data
$sig = base64_url_decode($encoded_sig);
$data = json_decode(base64_url_decode($payload), true);
if (strtoupper($data['algorithm']) !== 'HMAC-SHA256') {
error_log('Unknown algorithm. Expected HMAC-SHA256');
return null;
}
// check sig
$expected_sig = hash_hmac('sha256', $payload, $secret, $raw = true);
if ($sig !== $expected_sig) {
error_log('Bad Signed JSON signature!');
return null;
}
return $data;
}
function base64_url_decode($input) {
return base64_decode(strtr($input, '-_', '+/'));
}
精彩评论