From 5ea04611450645e3b6b8c36627243e699be5f367 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Tue, 2 Nov 2010 23:14:45 +0000 Subject: [PATCH] Facebook SSO - Log the user out of Facebook when s/he logs out of StatusNet --- plugins/FacebookSSO/FacebookSSOPlugin.php | 89 ++++++++++++++++++----- plugins/FacebookSSO/facebooklogin.php | 18 +++-- 2 files changed, 81 insertions(+), 26 deletions(-) diff --git a/plugins/FacebookSSO/FacebookSSOPlugin.php b/plugins/FacebookSSO/FacebookSSOPlugin.php index fca0275af0..da109e9c47 100644 --- a/plugins/FacebookSSO/FacebookSSOPlugin.php +++ b/plugins/FacebookSSO/FacebookSSOPlugin.php @@ -68,7 +68,6 @@ class FacebookSSOPlugin extends Plugin */ function initialize() { - common_debug("XXXXXXXXXXXX " . $this->appId); // Check defaults and configuration for application ID and secret if (empty($this->appId)) { $this->appId = common_config('facebook', 'appid'); @@ -79,7 +78,6 @@ class FacebookSSOPlugin extends Plugin } if (empty($this->facebook)) { - common_debug('instantiating facebook obj'); $this->facebook = new Facebook( array( 'appId' => $this->appId, @@ -89,8 +87,6 @@ class FacebookSSOPlugin extends Plugin ); } - common_debug("FACEBOOK = " . var_export($this->facebook, true)); - return true; } @@ -243,7 +239,7 @@ class FacebookSSOPlugin extends Plugin } /* - * Add a tab for managing Facebook Connect settings + * Add a tab for user-level Facebook settings * * @param Action &action the current action * @@ -254,13 +250,14 @@ class FacebookSSOPlugin extends Plugin if ($this->hasApplication()) { $action_name = $action->trimmed('action'); - $action->menuItem(common_local_url('facebooksettings'), - // @todo CHECKME: Should be 'Facebook Connect'? - // TRANS: Menu item tab. - _m('MENU','Facebook'), - // TRANS: Tooltip for menu item "Facebook". - _m('Facebook Connect Settings'), - $action_name === 'facebooksettings'); + $action->menuItem( + common_local_url('facebooksettings'), + // TRANS: Menu item tab. + _m('MENU','Facebook'), + // TRANS: Tooltip for menu item "Facebook". + _m('Facebook settings'), + $action_name === 'facebooksettings' + ); } return true; @@ -325,19 +322,75 @@ ENDOFSCRIPT; return true; } + /* + * Log the user out of Facebook, per the Facebook authentication guide + * + * @param Action action the action + */ + function onEndLogout($action) + { + $session = $this->facebook->getSession(); + $fbuser = null; + $fbuid = null; + + if ($session) { + try { + $fbuid = $this->facebook->getUser(); + $fbuser = $this->facebook->api('/me'); + } catch (FacebookApiException $e) { + common_log(LOG_ERROR, $e, __FILE__); + } + } + + if (!empty($fbuser)) { + + $logoutUrl = $this->facebook->getLogoutUrl( + array('next' => common_local_url('public')) + ); + + common_log( + LOG_INFO, + sprintf( + "Logging user out of Facebook (fbuid = %s)", + $fbuid + ), + __FILE__ + ); + + common_redirect($logoutUrl, 303); + } + } + + /* + * Add fbml namespace so Facebook's JavaScript SDK can parse and render + * XFBML tags (e.g: ) + * + * @param Action $action current action + * @param array $attrs array of attributes for the HTML tag + * + * @return nothing + */ function onStartHtmlElement($action, $attrs) { $attrs = array_merge($attrs, array('xmlns:fb' => 'http://www.facebook.com/2008/fbml')); return true; } + /* + * Add version info for this plugin + * + * @param array &$versions plugin version descriptions + */ function onPluginVersion(&$versions) { - $versions[] = array('name' => 'Facebook Single-Sign-On', - 'version' => STATUSNET_VERSION, - 'author' => 'Zach Copley', - 'homepage' => 'http://status.net/wiki/Plugin:FacebookSSO', - 'rawdescription' => - _m('A plugin for single-sign-on with Facebook.')); + $versions[] = array( + 'name' => 'Facebook Single-Sign-On', + 'version' => STATUSNET_VERSION, + 'author' => 'Zach Copley', + 'homepage' => 'http://status.net/wiki/Plugin:FacebookSSO', + 'rawdescription' => + _m('A plugin for single-sign-on with Facebook.') + ); + return true; } } diff --git a/plugins/FacebookSSO/facebooklogin.php b/plugins/FacebookSSO/facebooklogin.php index fce481fc03..bb30be1af7 100644 --- a/plugins/FacebookSSO/facebooklogin.php +++ b/plugins/FacebookSSO/facebooklogin.php @@ -20,7 +20,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . * - * @category Pugin + * @category Plugin * @package StatusNet * @author Zach Copley * @copyright 2010 StatusNet, Inc. @@ -34,6 +34,7 @@ if (!defined('STATUSNET')) { class FacebookloginAction extends Action { + function handle($args) { parent::handle($args); @@ -53,7 +54,7 @@ class FacebookloginAction extends Action ); $session = $facebook->getSession(); - $me = null; + $fbuser = null; if ($session) { try { @@ -86,10 +87,11 @@ class FacebookloginAction extends Action if (!empty($user)) { - common_debug( + common_log( + LOG_INFO, sprintf( - 'Logged in Facebook user $s as user %d (%s)', - $this->fbuid, + 'Logged in Facebook user %s as user %s (%s)', + $fbuid, $user->id, $user->nickname ), @@ -150,9 +152,9 @@ class FacebookloginAction extends Action $this->elementStart('fieldset'); $attrs = array( - 'show-faces' => 'true', - 'width' => '100', - 'max-rows' => '2', + //'show-faces' => 'true', + //'max-rows' => '4', + //'width' => '600', 'perms' => 'user_location,user_website,offline_access,publish_stream' ); -- 2.39.2