I am using a Facebook connection. Over 50% of registrations receive a "Bad Signed JSON" signature. error. What causes this problem and how is it fixed?
Here is the code:
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'); header('location: /volunteerregistration?error=Facebook has failed to connect. Unknown algorithm. Expected HMAC-SHA256 Please register with Omprakash below. '); exit; } // check sig $expected_sig = hash_hmac('sha256', $payload, $secret, $raw = true); if ($sig !== $expected_sig) { error_log('Bad Signed JSON signature!'); header('location: /volunteerregistration?error=Facebook has failed to connect. Bad Signed JSON signature. Please register with Omprakash below.'); exit; } return $data; }
Thanks!
source share