public function post_request($method, $params) { $params['method'] = $method; $params['session_key'] = $this->session_key; $params['api_key'] = $this->api_key; $params['call_id'] = microtime(true); if ($params['call_id'] <= $this->last_call_id) { $params['call_id'] = $this->last_call_id + 0.001; } $this->last_call_id = $params['call_id']; if (!isset($params['v'])) { $params['v'] = '1.0'; } $post_params = array(); foreach ($params as $key => &$val) { if (is_array($val)) { $val = implode(',', $val); } $post_params[] = $key . '=' . urlencode($val); } if ($this->desktop && $method != 'facebook.auth.getSession' && $method != 'facebook.auth.createToken') { $secret = $this->session_secret; } else { $secret = $this->secret; } $post_params[] = 'sig=' . api_generate_sig($params, $secret); $post_string = implode('&', $post_params); // Use CURL if installed if (function_exists('curl_init')) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $this->server_addr); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_USERAGENT, 'Facebook API PHP5 Client 1.0 (curl) ' . phpversion()); $result = curl_exec($ch); curl_close($ch); } else { // non-curl based version... // Using fopen with ssl transport requires OpenSSL to be installed. if (strncmp($this->server_addr, 'https', 5) == 0 && function_exists('openssl_open')) { $protocol = 'https'; } else { // switch back to http $protocol = 'http'; $this->server_addr = str_replace('https://', 'http://', $this->server_addr); } $context = array($protocol => array('method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded' . "\r\n" . 'User-Agent: Facebook API PHP5 Client 1.0 (non-curl) ' . phpversion() . "\r\n" . 'Content-length: ' . strlen($post_string), 'content' => $post_string)); $contextid = stream_context_create($context); $sock = fopen($this->server_addr, 'r', false, $contextid); if ($sock) { $result = ''; while (!feof($sock)) { $result .= fgets($sock, 4096); } fclose($sock); } } return $result; }
function api_request_is_properly_signed($params_array, $secret, $signature) { $good_sig = api_generate_sig($params_array, $secret); return $good_sig === $signature; }
function get_fb_validation_vars($user, $app_id, $others = array(), $logged_in_others = array(), $require_login = null) { global $DEMO_SESSION_KEY; $app_info = application_get_short_info($app_id); $secret = $app_info['secret']; $others['time'] = (string) microtime(true); if (is_array($user)) { $user = $user['user']; } if ($user) { $others['added'] = (int) is_platform_app_installed($app_id, $user); $session_key = $DEMO_SESSION_KEY; // FBOPEN:NOTE - stub: assume user session exists if ($session_key) { $others['user'] = $user; $others['session_key'] = $session_key; $session_info = api_session_get_info($session_key, $app_id); if ($app_info['desktop']) { // use the session secret instead of the normal one $secret = $session_info['session_secret']; } if ($session_info['session_timeout'] == 0) { $others['expires'] = 0; } else { $others['expires'] = $session_info['key_create_time'] + $session_info['session_timeout']; } $others += $logged_in_others; } elseif ($require_login) { $others['user'] = $user; } } $others['api_key'] = $app_info['apikey']; $vars = array(); foreach ($others as $n => $v) { $vars['fb_sig_' . $n] = $v; } $vars['fb_sig'] = api_generate_sig($others, $secret); return $vars; }
private function post_request($method, $params) { $params['method'] = $method; $params['session_key'] = $this->session_key; $params['api_key'] = $this->api_key; $params['call_id'] = microtime(true); $post_params = array(); foreach ($params as $key => &$val) { if (is_array($val)) { $val = implode(',', $val); } $post_params[] = $key . '=' . urlencode($val); } if ($this->desktop && $method != 'facebook.auth.getSession' && $method != 'facebook.auth.createToken') { $secret = $this->session_secret; } else { $secret = $this->secret; } $post_params[] = 'sig=' . api_generate_sig($params, $secret); $post_string = implode('&', $post_params); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $this->server_addr); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $result = curl_exec($ch); curl_close($ch); return $result; }