I am using javascript sdk. The documentation says that you get a signed request from the response object, which returns FB.getLoginStatus () when the user status = connected, but now I need to parse the signed request. How to send it to php page Do I have parsing code? Do I include php code on the canvas application index page and then send signedRequest to the code on the same page? Or save the code on separate pages and pass SR.
The first block of code is on my index.html page. It checks the login status and receives the signed request parameter from the response object.
The second block is php code. facebook provides parsing of the signed request when it is captured through the registration plugin, but the plugin automatically sends SR to this page when you specify your URL as a parameter. In a canvas application, I have to pass it myself. How can I do it?
Javascript
FB.getLoginStatus(function(response) { if (response.status === 'connected') {
PHP page
<?php define('FACEBOOK_APP_ID', '3*****88&'); // Place your App Id here define('FACEBOOK_SECRET', '1345*****eb4f2da'); // Place your App Secret Here // No need to change the function body 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, '-_', '+/')); } if ($_REQUEST) { $response = parse_signed_request($_REQUEST['signed_request'], FACEBOOK_SECRET); } $name = $response["registration"]["name"]; $email = $response["registration"]["email"]; $password = $response["registration"]["password"]; $uID = $response["user_id"]; ?>
source share