From e35f40528b8d3ed4c2239a558e9f6f42b8f19271 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Sun, 7 Dec 2008 19:58:16 -0500 Subject: trac750 added Facebook client libs for PHP to extlib dir darcs-hash:20081208005816-7b5ce-b7ec90e310ddc609fe88d54cfac5ec7bc67da6ca.gz --- extlib/facebook/facebook_desktop.php | 104 +++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 extlib/facebook/facebook_desktop.php (limited to 'extlib/facebook/facebook_desktop.php') diff --git a/extlib/facebook/facebook_desktop.php b/extlib/facebook/facebook_desktop.php new file mode 100644 index 000000000..90cdf66bd --- /dev/null +++ b/extlib/facebook/facebook_desktop.php @@ -0,0 +1,104 @@ +app_secret = $secret; + $this->verify_sig = false; + parent::__construct($api_key, $secret); + } + + public function do_get_session($auth_token) { + $this->api_client->secret = $this->app_secret; + $this->api_client->session_key = null; + $session_info = parent::do_get_session($auth_token); + if (!empty($session_info['secret'])) { + // store the session secret + $this->set_session_secret($session_info['secret']); + } + return $session_info; + } + + public function set_session_secret($session_secret) { + $this->secret = $session_secret; + $this->api_client->secret = $session_secret; + } + + public function require_login() { + if ($this->get_loggedin_user()) { + try { + // try a session-based API call to ensure that we have the correct + // session secret + $user = $this->api_client->users_getLoggedInUser(); + + // now that we have a valid session secret, verify the signature + $this->verify_sig = true; + if ($this->validate_fb_params(false)) { + return $user; + } else { + // validation failed + return null; + } + } catch (FacebookRestClientException $ex) { + if (isset($_GET['auth_token'])) { + // if we have an auth_token, use it to establish a session + $session_info = $this->do_get_session($_GET['auth_token']); + if ($session_info) { + return $session_info['uid']; + } + } + } + } + // if we get here, we need to redirect the user to log in + $this->redirect($this->get_login_url(self::current_url(), $this->in_fb_canvas())); + } + + public function verify_signature($fb_params, $expected_sig) { + // we don't want to verify the signature until we have a valid + // session secret + if ($this->verify_sig) { + return parent::verify_signature($fb_params, $expected_sig); + } else { + return true; + } + } +} -- cgit v1.2.3-54-g00ecf