3 * StatusNet, the distributed open-source microblogging tool
7 * LICENCE: This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 * @author Evan Prodromou <evan@status.net>
23 * @copyright 2009 StatusNet, Inc.
24 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
25 * @link http://status.net/
28 if (!defined('STATUSNET')) {
33 * Plugin for OpenID authentication and identity
35 * This class enables consumer support for OpenID, the distributed authentication
36 * and identity system.
40 * @author Evan Prodromou <evan@status.net>
41 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
42 * @link http://status.net/
43 * @link http://openid.net/
46 class OpenIDPlugin extends Plugin
49 * Initializer for the plugin.
52 function __construct()
54 parent::__construct();
58 * Add OpenID-related paths to the router table
60 * Hook for RouterInitialized event.
62 * @return boolean hook return
65 function onRouterInitialized(&$m)
67 $m->connect('main/openid', array('action' => 'openidlogin'));
68 $m->connect('settings/openid', array('action' => 'openidsettings'));
69 $m->connect('xrds', array('action' => 'publicxrds'));
70 $m->connect('index.php?action=finishopenidlogin', array('action' => 'finishopenidlogin'));
71 $m->connect('index.php?action=finishaddopenid', array('action' => 'finishaddopenid'));
76 function onEndLoginGroupNav(&$action)
78 $action_name = $action->trimmed('action');
80 $action->menuItem(common_local_url('openidlogin'),
82 _('Login or register with OpenID'),
83 $action_name === 'openidlogin');
88 function onEndAccountSettingsNav(&$action)
90 $action_name = $action->trimmed('action');
92 $action->menuItem(common_local_url('openidsettings'),
94 _('Add or remove OpenIDs'),
95 $action_name === 'openidsettings');
100 function onAutoload($cls)
104 case 'OpenidloginAction':
105 case 'FinishopenidloginAction':
106 case 'FinishaddopenidAction':
108 case 'PublicxrdsAction':
109 case 'OpenidsettingsAction':
110 require_once(INSTALLDIR.'/plugins/OpenID/' . strtolower(mb_substr($cls, 0, -6)) . '.php');
113 require_once(INSTALLDIR.'/plugins/OpenID/User_openid.php');
120 function onSensitiveAction($action, &$ssl)
124 case 'finishopenidlogin':
125 case 'finishaddopenid':
133 function onLoginAction($action, &$login)
138 case 'finishopenidlogin':
147 * We include a <meta> element linking to the publicxrds page, for OpenID
148 * client-side authentication.
153 function onEndHeadChildren($action)
155 // for client side of OpenID authentication
156 $action->element('meta', array('http-equiv' => 'X-XRDS-Location',
157 'content' => common_local_url('publicxrds')));
161 * Redirect to OpenID login if they have an OpenID
163 * @return boolean whether to continue
166 function onRedirectToLogin($action, $user)
168 if (!empty($user) && User_openid::hasOpenID($user->id)) {
169 common_redirect(common_local_url('openidlogin'), 303);
175 function onEndShowPageNotice($action)
177 $name = $action->trimmed('action');
182 $instr = '(Have an [OpenID](http://openid.net/)? ' .
183 'Try our [OpenID registration]'.
184 '(%%action.openidlogin%%)!)';
187 $instr = '(Have an [OpenID](http://openid.net/)? ' .
188 'Try our [OpenID login]'.
189 '(%%action.openidlogin%%)!)';
195 $output = common_markup_to_html($instr);
196 $action->raw($output);
200 function onStartLoadDoc(&$title, &$output)
202 if ($title == 'openid')
204 $filename = INSTALLDIR.'/plugins/OpenID/doc-src/openid';
206 $c = file_get_contents($filename);
207 $output = common_markup_to_html($c);
208 return false; // success!
214 function onEndLoadDoc($title, &$output)
216 if ($title == 'help')
218 $menuitem = '* [OpenID](%%doc.openid%%) - what OpenID is and how to use it with this service';
220 $output .= common_markup_to_html($menuitem);
226 function onCheckSchema() {
227 $schema = Schema::get();
228 $schema->ensureTable('user_openid',
229 array(new ColumnDef('canonical', 'varchar',
230 '255', false, 'PRI'),
231 new ColumnDef('display', 'varchar',
233 new ColumnDef('user_id', 'integer',
235 new ColumnDef('created', 'datetime',
237 new ColumnDef('modified', 'timestamp')));