2009-08-04 11:43:26 +01:00
|
|
|
<?php
|
|
|
|
/**
|
2009-09-16 02:22:15 +01:00
|
|
|
* StatusNet, the distributed open-source microblogging tool
|
2009-08-04 11:43:26 +01:00
|
|
|
*
|
|
|
|
* PHP version 5
|
|
|
|
*
|
|
|
|
* LICENCE: This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* @category Plugin
|
2009-09-16 02:22:15 +01:00
|
|
|
* @package StatusNet
|
|
|
|
* @author Evan Prodromou <evan@status.net>
|
2012-07-09 20:59:10 +01:00
|
|
|
* @author Craig Andrews <candrews@integralblue.com>
|
2010-05-18 18:39:56 +01:00
|
|
|
* @copyright 2009-2010 StatusNet, Inc.
|
2010-05-27 23:26:47 +01:00
|
|
|
* @copyright 2009 Free Software Foundation, Inc http://www.fsf.org
|
2009-08-04 11:43:26 +01:00
|
|
|
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
|
2009-09-16 02:22:15 +01:00
|
|
|
* @link http://status.net/
|
2009-08-04 11:43:26 +01:00
|
|
|
*/
|
|
|
|
|
2009-09-16 02:22:15 +01:00
|
|
|
if (!defined('STATUSNET')) {
|
2009-08-04 11:43:26 +01:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Plugin for OpenID authentication and identity
|
|
|
|
*
|
|
|
|
* This class enables consumer support for OpenID, the distributed authentication
|
|
|
|
* and identity system.
|
|
|
|
*
|
2013-09-30 16:13:03 +01:00
|
|
|
* Depends on: WebFinger plugin for HostMeta-lookup (user@host format)
|
|
|
|
*
|
2009-08-04 11:43:26 +01:00
|
|
|
* @category Plugin
|
2009-09-16 02:22:15 +01:00
|
|
|
* @package StatusNet
|
|
|
|
* @author Evan Prodromou <evan@status.net>
|
2010-05-27 23:26:47 +01:00
|
|
|
* @author Craig Andrews <candrews@integralblue.com>
|
|
|
|
* @copyright 2009 Free Software Foundation, Inc http://www.fsf.org
|
2009-08-04 11:43:26 +01:00
|
|
|
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
|
2009-09-16 02:22:15 +01:00
|
|
|
* @link http://status.net/
|
2009-08-04 11:43:26 +01:00
|
|
|
* @link http://openid.net/
|
|
|
|
*/
|
|
|
|
class OpenIDPlugin extends Plugin
|
|
|
|
{
|
2019-06-03 01:56:52 +01:00
|
|
|
const PLUGIN_VERSION = '2.0.0';
|
|
|
|
|
2010-05-18 18:39:56 +01:00
|
|
|
// Plugin parameter: set true to disallow non-OpenID logins
|
|
|
|
// If set, overrides the setting in database or $config['site']['openidonly']
|
|
|
|
public $openidOnly = null;
|
|
|
|
|
|
|
|
function initialize()
|
|
|
|
{
|
|
|
|
parent::initialize();
|
|
|
|
if ($this->openidOnly !== null) {
|
|
|
|
global $config;
|
|
|
|
$config['site']['openidonly'] = (bool)$this->openidOnly;
|
|
|
|
}
|
|
|
|
}
|
2009-08-04 11:43:26 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add OpenID-related paths to the router table
|
|
|
|
*
|
|
|
|
* Hook for RouterInitialized event.
|
|
|
|
*
|
2014-11-07 14:24:05 +00:00
|
|
|
* @param URLMapper $m URL mapper
|
2010-03-23 15:36:02 +00:00
|
|
|
*
|
2009-08-04 11:43:26 +01:00
|
|
|
* @return boolean hook return
|
|
|
|
*/
|
2014-11-07 14:24:05 +00:00
|
|
|
public function onStartInitializeRouter(URLMapper $m)
|
2009-08-04 11:43:26 +01:00
|
|
|
{
|
|
|
|
$m->connect('main/openid', array('action' => 'openidlogin'));
|
2009-10-29 20:01:25 +00:00
|
|
|
$m->connect('main/openidtrust', array('action' => 'openidtrust'));
|
2009-08-04 11:43:26 +01:00
|
|
|
$m->connect('settings/openid', array('action' => 'openidsettings'));
|
2010-03-23 15:36:02 +00:00
|
|
|
$m->connect('index.php?action=finishopenidlogin',
|
|
|
|
array('action' => 'finishopenidlogin'));
|
|
|
|
$m->connect('index.php?action=finishaddopenid',
|
|
|
|
array('action' => 'finishaddopenid'));
|
2009-10-29 20:01:25 +00:00
|
|
|
$m->connect('main/openidserver', array('action' => 'openidserver'));
|
2011-01-23 15:18:35 +00:00
|
|
|
$m->connect('panel/openid', array('action' => 'openidadminpanel'));
|
2010-01-08 01:41:55 +00:00
|
|
|
|
2009-08-04 11:43:26 +01:00
|
|
|
return true;
|
|
|
|
}
|
2009-08-04 12:20:17 +01:00
|
|
|
|
2010-03-23 16:58:10 +00:00
|
|
|
/**
|
|
|
|
* In OpenID-only mode, disable paths for password stuff
|
|
|
|
*
|
|
|
|
* @param string $path path to connect
|
|
|
|
* @param array $defaults path defaults
|
|
|
|
* @param array $rules path rules
|
|
|
|
* @param array $result unused
|
|
|
|
*
|
|
|
|
* @return boolean hook return
|
|
|
|
*/
|
|
|
|
function onStartConnectPath(&$path, &$defaults, &$rules, &$result)
|
|
|
|
{
|
2010-05-18 18:39:56 +01:00
|
|
|
if (common_config('site', 'openidonly')) {
|
2010-09-30 20:35:25 +01:00
|
|
|
// Note that we should not remove the login and register
|
|
|
|
// actions. Lots of auth-related things link to them,
|
|
|
|
// such as when visiting a private site without a session
|
|
|
|
// or revalidating a remembered login for admin work.
|
|
|
|
//
|
|
|
|
// We take those two over with redirects to ourselves
|
|
|
|
// over in onArgsInitialize().
|
|
|
|
static $block = array('main/recoverpassword',
|
2010-03-23 16:58:10 +00:00
|
|
|
'settings/password');
|
|
|
|
|
|
|
|
if (in_array($path, $block)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If we've been hit with password-login args, redirect
|
|
|
|
*
|
|
|
|
* @param array $args args (URL, Get, post)
|
|
|
|
*
|
|
|
|
* @return boolean hook return
|
|
|
|
*/
|
|
|
|
function onArgsInitialize($args)
|
|
|
|
{
|
2010-05-18 18:39:56 +01:00
|
|
|
if (common_config('site', 'openidonly')) {
|
2010-03-23 16:58:10 +00:00
|
|
|
if (array_key_exists('action', $args)) {
|
|
|
|
$action = trim($args['action']);
|
|
|
|
if (in_array($action, array('login', 'register'))) {
|
|
|
|
common_redirect(common_local_url('openidlogin'));
|
|
|
|
} else if ($action == 'passwordsettings') {
|
|
|
|
common_redirect(common_local_url('openidsettings'));
|
|
|
|
} else if ($action == 'recoverpassword') {
|
2011-06-17 11:20:20 +01:00
|
|
|
// TRANS: Client exception thrown when an action is not available.
|
|
|
|
throw new ClientException(_m('Unavailable action.'));
|
2010-03-23 16:58:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-03-23 15:36:02 +00:00
|
|
|
/**
|
|
|
|
* Public XRDS output hook
|
|
|
|
*
|
|
|
|
* Puts the bits of code needed by some OpenID providers to show
|
|
|
|
* we're good citizens.
|
|
|
|
*
|
|
|
|
* @param Action $action Action being executed
|
|
|
|
* @param XMLOutputter &$xrdsOutputter Output channel
|
|
|
|
*
|
|
|
|
* @return boolean hook return
|
|
|
|
*/
|
2015-06-04 00:08:03 +01:00
|
|
|
function onEndPublicXRDS(Action $action, &$xrdsOutputter)
|
2009-10-29 20:01:25 +00:00
|
|
|
{
|
|
|
|
$xrdsOutputter->elementStart('XRD', array('xmlns' => 'xri://$xrd*($v*2.0)',
|
2010-03-23 15:36:02 +00:00
|
|
|
'xmlns:simple' => 'http://xrds-simple.net/core/1.0',
|
|
|
|
'version' => '2.0'));
|
2009-10-29 20:01:25 +00:00
|
|
|
$xrdsOutputter->element('Type', null, 'xri://$xrds*simple');
|
|
|
|
//consumer
|
|
|
|
foreach (array('finishopenidlogin', 'finishaddopenid') as $finish) {
|
|
|
|
$xrdsOutputter->showXrdsService(Auth_OpenID_RP_RETURN_TO_URL_TYPE,
|
2010-03-23 15:36:02 +00:00
|
|
|
common_local_url($finish));
|
2009-10-29 20:01:25 +00:00
|
|
|
}
|
|
|
|
//provider
|
|
|
|
$xrdsOutputter->showXrdsService('http://specs.openid.net/auth/2.0/server',
|
2010-03-23 15:36:02 +00:00
|
|
|
common_local_url('openidserver'),
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
'http://specs.openid.net/auth/2.0/identifier_select');
|
2009-10-29 20:01:25 +00:00
|
|
|
$xrdsOutputter->elementEnd('XRD');
|
|
|
|
}
|
|
|
|
|
2010-03-23 16:58:10 +00:00
|
|
|
/**
|
|
|
|
* If we're in OpenID-only mode, hide all the main menu except OpenID login.
|
|
|
|
*
|
|
|
|
* @param Action $action Action being run
|
|
|
|
*
|
|
|
|
* @return boolean hook return
|
|
|
|
*/
|
2010-03-23 16:10:26 +00:00
|
|
|
function onStartPrimaryNav($action)
|
|
|
|
{
|
2010-05-18 18:39:56 +01:00
|
|
|
if (common_config('site', 'openidonly') && !common_logged_in()) {
|
2010-03-23 16:10:26 +00:00
|
|
|
// TRANS: Tooltip for main menu option "Login"
|
2011-04-27 19:37:44 +01:00
|
|
|
$tooltip = _m('TOOLTIP', 'Login to the site.');
|
2010-03-23 16:10:26 +00:00
|
|
|
$action->menuItem(common_local_url('openidlogin'),
|
2010-04-30 22:07:19 +01:00
|
|
|
// TRANS: Main menu option when not logged in to log in
|
2010-03-23 16:10:26 +00:00
|
|
|
_m('MENU', 'Login'),
|
|
|
|
$tooltip,
|
|
|
|
false,
|
|
|
|
'nav_login');
|
|
|
|
// TRANS: Tooltip for main menu option "Help"
|
|
|
|
$tooltip = _m('TOOLTIP', 'Help me!');
|
|
|
|
$action->menuItem(common_local_url('doc', array('title' => 'help')),
|
2010-04-30 22:07:19 +01:00
|
|
|
// TRANS: Main menu option for help on the StatusNet site
|
2010-03-23 16:10:26 +00:00
|
|
|
_m('MENU', 'Help'),
|
|
|
|
$tooltip,
|
|
|
|
false,
|
|
|
|
'nav_help');
|
|
|
|
if (!common_config('site', 'private')) {
|
|
|
|
// TRANS: Tooltip for main menu option "Search"
|
2011-04-27 19:37:44 +01:00
|
|
|
$tooltip = _m('TOOLTIP', 'Search for people or text.');
|
2010-03-23 16:10:26 +00:00
|
|
|
$action->menuItem(common_local_url('peoplesearch'),
|
2010-04-30 22:07:19 +01:00
|
|
|
// TRANS: Main menu option when logged in or when the StatusNet instance is not private
|
2010-03-23 16:10:26 +00:00
|
|
|
_m('MENU', 'Search'), $tooltip, false, 'nav_search');
|
|
|
|
}
|
|
|
|
Event::handle('EndPrimaryNav', array($action));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Menu for login
|
|
|
|
*
|
|
|
|
* If we're in openidOnly mode, we disable the menu for all other login.
|
|
|
|
*
|
2011-01-18 20:34:27 +00:00
|
|
|
* @param Action $action Action being executed
|
2010-03-23 16:10:26 +00:00
|
|
|
*
|
|
|
|
* @return boolean hook return
|
|
|
|
*/
|
2011-01-18 20:34:27 +00:00
|
|
|
function onStartLoginGroupNav($action)
|
2010-03-23 16:10:26 +00:00
|
|
|
{
|
2010-05-18 18:39:56 +01:00
|
|
|
if (common_config('site', 'openidonly')) {
|
2010-03-23 16:10:26 +00:00
|
|
|
$this->showOpenIDLoginTab($action);
|
|
|
|
// Even though we replace this code, we
|
|
|
|
// DON'T run the End* hook, to keep others from
|
|
|
|
// adding tabs. Not nice, but.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-03-23 15:36:02 +00:00
|
|
|
/**
|
|
|
|
* Menu item for login
|
|
|
|
*
|
2011-01-18 20:34:27 +00:00
|
|
|
* @param Action $action Action being executed
|
2010-03-23 15:36:02 +00:00
|
|
|
*
|
|
|
|
* @return boolean hook return
|
|
|
|
*/
|
2011-01-18 20:34:27 +00:00
|
|
|
function onEndLoginGroupNav($action)
|
2010-03-23 16:10:26 +00:00
|
|
|
{
|
|
|
|
$this->showOpenIDLoginTab($action);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show menu item for login
|
|
|
|
*
|
|
|
|
* @param Action $action Action being executed
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function showOpenIDLoginTab($action)
|
2009-08-04 12:20:17 +01:00
|
|
|
{
|
|
|
|
$action_name = $action->trimmed('action');
|
|
|
|
|
|
|
|
$action->menuItem(common_local_url('openidlogin'),
|
2010-04-30 22:07:19 +01:00
|
|
|
// TRANS: OpenID plugin menu item on site logon page.
|
|
|
|
_m('MENU', 'OpenID'),
|
|
|
|
// TRANS: OpenID plugin tooltip for logon menu item.
|
2011-04-27 19:37:44 +01:00
|
|
|
_m('Login or register with OpenID.'),
|
2009-08-04 12:20:17 +01:00
|
|
|
$action_name === 'openidlogin');
|
2010-03-23 16:10:26 +00:00
|
|
|
}
|
2009-08-04 12:20:17 +01:00
|
|
|
|
2010-03-23 16:10:26 +00:00
|
|
|
/**
|
|
|
|
* Show menu item for password
|
|
|
|
*
|
|
|
|
* We hide it in openID-only mode
|
|
|
|
*
|
|
|
|
* @param Action $menu Widget for menu
|
|
|
|
* @param void &$unused Unused value
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function onStartAccountSettingsPasswordMenuItem($menu, &$unused) {
|
2010-05-18 18:39:56 +01:00
|
|
|
if (common_config('site', 'openidonly')) {
|
2010-03-23 16:10:26 +00:00
|
|
|
return false;
|
|
|
|
}
|
2009-08-04 12:20:17 +01:00
|
|
|
return true;
|
|
|
|
}
|
2009-08-04 12:22:56 +01:00
|
|
|
|
2010-03-23 15:36:02 +00:00
|
|
|
/**
|
2010-03-23 16:10:26 +00:00
|
|
|
* Menu item for OpenID settings
|
2010-03-23 15:36:02 +00:00
|
|
|
*
|
2011-01-18 20:34:27 +00:00
|
|
|
* @param Action $action Action being executed
|
2010-03-23 15:36:02 +00:00
|
|
|
*
|
|
|
|
* @return boolean hook return
|
|
|
|
*/
|
2011-01-18 20:34:27 +00:00
|
|
|
function onEndAccountSettingsNav($action)
|
2009-08-04 12:22:56 +01:00
|
|
|
{
|
|
|
|
$action_name = $action->trimmed('action');
|
|
|
|
|
|
|
|
$action->menuItem(common_local_url('openidsettings'),
|
2010-04-30 22:07:19 +01:00
|
|
|
// TRANS: OpenID plugin menu item on user settings page.
|
|
|
|
_m('MENU', 'OpenID'),
|
|
|
|
// TRANS: OpenID plugin tooltip for user settings menu item.
|
2011-04-27 19:37:44 +01:00
|
|
|
_m('Add or remove OpenIDs.'),
|
2009-08-04 12:22:56 +01:00
|
|
|
$action_name === 'openidsettings');
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2009-08-04 12:40:41 +01:00
|
|
|
|
2010-03-23 15:36:02 +00:00
|
|
|
/**
|
|
|
|
* Autoloader
|
|
|
|
*
|
|
|
|
* Loads our classes if they're requested.
|
|
|
|
*
|
|
|
|
* @param string $cls Class requested
|
|
|
|
*
|
|
|
|
* @return boolean hook return
|
|
|
|
*/
|
2009-08-04 12:40:41 +01:00
|
|
|
function onAutoload($cls)
|
|
|
|
{
|
|
|
|
switch ($cls)
|
|
|
|
{
|
2010-05-18 18:39:56 +01:00
|
|
|
case 'Auth_OpenID_TeamsExtension':
|
|
|
|
case 'Auth_OpenID_TeamsRequest':
|
|
|
|
case 'Auth_OpenID_TeamsResponse':
|
|
|
|
require_once dirname(__FILE__) . '/extlib/teams-extension.php';
|
2009-11-16 20:24:25 +00:00
|
|
|
return false;
|
2009-08-04 12:40:41 +01:00
|
|
|
}
|
2013-08-28 14:54:26 +01:00
|
|
|
|
|
|
|
return parent::onAutoload($cls);
|
2009-08-04 12:40:41 +01:00
|
|
|
}
|
2009-08-04 14:00:58 +01:00
|
|
|
|
2010-03-23 15:36:02 +00:00
|
|
|
/**
|
|
|
|
* Login actions
|
|
|
|
*
|
|
|
|
* These actions should be visible even when the site is marked private
|
|
|
|
*
|
|
|
|
* @param Action $action Action to show
|
|
|
|
* @param boolean &$login Whether it's a login action
|
|
|
|
*
|
|
|
|
* @return boolean hook return
|
|
|
|
*/
|
2009-08-04 16:16:43 +01:00
|
|
|
function onLoginAction($action, &$login)
|
|
|
|
{
|
|
|
|
switch ($action)
|
|
|
|
{
|
2010-03-23 15:36:02 +00:00
|
|
|
case 'openidlogin':
|
|
|
|
case 'finishopenidlogin':
|
|
|
|
case 'openidserver':
|
2009-08-04 16:16:43 +01:00
|
|
|
$login = true;
|
|
|
|
return false;
|
2010-03-23 15:36:02 +00:00
|
|
|
default:
|
2009-08-04 16:16:43 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2009-08-04 18:04:31 +01:00
|
|
|
|
|
|
|
/**
|
2013-09-30 16:13:03 +01:00
|
|
|
* We include a <meta> element linking to the webfinger resource page,
|
|
|
|
* for OpenID client-side authentication.
|
2009-08-04 18:04:31 +01:00
|
|
|
*
|
2010-03-23 15:36:02 +00:00
|
|
|
* @param Action $action Action being shown
|
|
|
|
*
|
2009-08-04 18:04:31 +01:00
|
|
|
* @return void
|
|
|
|
*/
|
2015-06-04 00:08:03 +01:00
|
|
|
function onEndShowHeadElements(Action $action)
|
2009-08-04 18:04:31 +01:00
|
|
|
{
|
2010-03-23 15:36:02 +00:00
|
|
|
if ($action instanceof ShowstreamAction) {
|
2009-10-29 20:01:25 +00:00
|
|
|
$action->element('link', array('rel' => 'openid2.provider',
|
|
|
|
'href' => common_local_url('openidserver')));
|
|
|
|
$action->element('link', array('rel' => 'openid2.local_id',
|
2015-07-10 12:44:47 +01:00
|
|
|
'href' => $action->getTarget()->getUrl()));
|
2009-10-29 20:01:25 +00:00
|
|
|
$action->element('link', array('rel' => 'openid.server',
|
|
|
|
'href' => common_local_url('openidserver')));
|
|
|
|
$action->element('link', array('rel' => 'openid.delegate',
|
2015-07-10 12:44:47 +01:00
|
|
|
'href' => $action->getTarget()->getUrl()));
|
2009-10-28 18:38:19 +00:00
|
|
|
}
|
2015-06-04 00:08:03 +01:00
|
|
|
|
|
|
|
if ($action instanceof SitestreamAction) {
|
|
|
|
$action->element('meta', array('http-equiv' => 'X-XRDS-Location',
|
|
|
|
'content' => common_local_url('publicxrds')));
|
|
|
|
}
|
2009-10-28 18:38:19 +00:00
|
|
|
return true;
|
2009-08-04 18:04:31 +01:00
|
|
|
}
|
2009-08-04 18:17:43 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Redirect to OpenID login if they have an OpenID
|
|
|
|
*
|
2010-03-23 15:36:02 +00:00
|
|
|
* @param Action $action Action being executed
|
|
|
|
* @param User $user User doing the action
|
|
|
|
*
|
2009-08-04 18:17:43 +01:00
|
|
|
* @return boolean whether to continue
|
|
|
|
*/
|
|
|
|
function onRedirectToLogin($action, $user)
|
|
|
|
{
|
2016-01-04 15:36:05 +00:00
|
|
|
if (common_config('site', 'openidonly') || (!empty($user) && User_openid::hasOpenID($user->id))) {
|
2009-08-04 18:17:43 +01:00
|
|
|
common_redirect(common_local_url('openidlogin'), 303);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2009-08-04 18:27:22 +01:00
|
|
|
|
2010-03-23 15:36:02 +00:00
|
|
|
/**
|
|
|
|
* Show some extra instructions for using OpenID
|
|
|
|
*
|
|
|
|
* @param Action $action Action being executed
|
|
|
|
*
|
|
|
|
* @return boolean hook value
|
|
|
|
*/
|
2009-08-04 18:27:22 +01:00
|
|
|
function onEndShowPageNotice($action)
|
|
|
|
{
|
|
|
|
$name = $action->trimmed('action');
|
|
|
|
|
|
|
|
switch ($name)
|
|
|
|
{
|
2010-03-23 15:36:02 +00:00
|
|
|
case 'register':
|
2010-02-20 21:57:05 +00:00
|
|
|
if (common_logged_in()) {
|
2011-06-17 11:20:20 +01:00
|
|
|
// TRANS: Page notice for logged in users to try and get them to add an OpenID account to their StatusNet account.
|
|
|
|
// TRANS: This message contains Markdown links in the form (description)[link].
|
|
|
|
$instr = _m('(Have an [OpenID](http://openid.net/)? ' .
|
|
|
|
'[Add an OpenID to your account](%%action.openidsettings%%)!');
|
2010-02-20 21:57:05 +00:00
|
|
|
} else {
|
2011-06-17 11:20:20 +01:00
|
|
|
// TRANS: Page notice for anonymous users to try and get them to register with an OpenID account.
|
|
|
|
// TRANS: This message contains Markdown links in the form (description)[link].
|
|
|
|
$instr = _m('(Have an [OpenID](http://openid.net/)? ' .
|
2010-02-20 21:57:05 +00:00
|
|
|
'Try our [OpenID registration]'.
|
2011-06-17 11:20:20 +01:00
|
|
|
'(%%action.openidlogin%%)!)');
|
2010-02-20 21:57:05 +00:00
|
|
|
}
|
2009-08-04 18:27:22 +01:00
|
|
|
break;
|
2010-03-23 15:36:02 +00:00
|
|
|
case 'login':
|
2011-06-17 11:20:20 +01:00
|
|
|
// TRANS: Page notice on the login page to try and get them to log on with an OpenID account.
|
|
|
|
// TRANS: This message contains Markdown links in the form (description)[link].
|
|
|
|
$instr = _m('(Have an [OpenID](http://openid.net/)? ' .
|
2009-08-04 18:27:22 +01:00
|
|
|
'Try our [OpenID login]'.
|
2011-06-17 11:20:20 +01:00
|
|
|
'(%%action.openidlogin%%)!)');
|
2009-08-04 18:27:22 +01:00
|
|
|
break;
|
2010-03-23 15:36:02 +00:00
|
|
|
default:
|
2009-08-04 18:27:22 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
$output = common_markup_to_html($instr);
|
|
|
|
$action->raw($output);
|
|
|
|
return true;
|
|
|
|
}
|
2009-08-21 22:01:48 +01:00
|
|
|
|
2010-03-23 15:36:02 +00:00
|
|
|
/**
|
|
|
|
* Load our document if requested
|
|
|
|
*
|
|
|
|
* @param string &$title Title to fetch
|
|
|
|
* @param string &$output HTML to output
|
|
|
|
*
|
|
|
|
* @return boolean hook value
|
|
|
|
*/
|
2009-08-21 22:01:48 +01:00
|
|
|
function onStartLoadDoc(&$title, &$output)
|
|
|
|
{
|
2010-03-23 15:36:02 +00:00
|
|
|
if ($title == 'openid') {
|
2009-08-21 22:01:48 +01:00
|
|
|
$filename = INSTALLDIR.'/plugins/OpenID/doc-src/openid';
|
|
|
|
|
2010-03-23 15:36:02 +00:00
|
|
|
$c = file_get_contents($filename);
|
2009-08-21 22:01:48 +01:00
|
|
|
$output = common_markup_to_html($c);
|
|
|
|
return false; // success!
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-03-23 15:36:02 +00:00
|
|
|
/**
|
|
|
|
* Add our document to the global menu
|
|
|
|
*
|
|
|
|
* @param string $title Title being fetched
|
|
|
|
* @param string &$output HTML being output
|
|
|
|
*
|
|
|
|
* @return boolean hook value
|
|
|
|
*/
|
2011-09-30 19:24:27 +01:00
|
|
|
function onEndDocsMenu(&$items) {
|
|
|
|
$items[] = array('doc',
|
|
|
|
array('title' => 'openid'),
|
|
|
|
_m('MENU', 'OpenID'),
|
|
|
|
_('Logging in with OpenID'),
|
|
|
|
'nav_doc_openid');
|
2009-08-21 22:01:48 +01:00
|
|
|
return true;
|
|
|
|
}
|
2009-10-01 20:43:57 +01:00
|
|
|
|
2010-03-23 15:36:02 +00:00
|
|
|
/**
|
|
|
|
* Data definitions
|
|
|
|
*
|
|
|
|
* Assure that our data objects are available in the DB
|
|
|
|
*
|
|
|
|
* @return boolean hook value
|
|
|
|
*/
|
|
|
|
function onCheckSchema()
|
|
|
|
{
|
2009-10-01 20:43:57 +01:00
|
|
|
$schema = Schema::get();
|
2013-08-19 16:08:18 +01:00
|
|
|
$schema->ensureTable('user_openid', User_openid::schemaDef());
|
|
|
|
$schema->ensureTable('user_openid_trustroot', User_openid_trustroot::schemaDef());
|
2012-07-09 21:51:36 +01:00
|
|
|
$schema->ensureTable('user_openid_prefs', User_openid_prefs::schemaDef());
|
|
|
|
|
2011-08-22 22:52:02 +01:00
|
|
|
/* These are used by JanRain OpenID library */
|
|
|
|
|
|
|
|
$schema->ensureTable('oid_associations',
|
|
|
|
array(
|
|
|
|
'fields' => array(
|
|
|
|
'server_url' => array('type' => 'blob', 'not null' => true),
|
2015-02-19 20:01:43 +00:00
|
|
|
'handle' => array('type' => 'varchar', 'length' => 191, 'not null' => true, 'default' => ''), // character set latin1,
|
2011-08-22 22:52:02 +01:00
|
|
|
'secret' => array('type' => 'blob'),
|
|
|
|
'issued' => array('type' => 'int'),
|
|
|
|
'lifetime' => array('type' => 'int'),
|
|
|
|
'assoc_type' => array('type' => 'varchar', 'length' => 64),
|
|
|
|
),
|
2015-02-19 20:01:43 +00:00
|
|
|
'primary key' => array(array('server_url', 191), 'handle'),
|
2011-08-22 22:52:02 +01:00
|
|
|
));
|
|
|
|
$schema->ensureTable('oid_nonces',
|
|
|
|
array(
|
|
|
|
'fields' => array(
|
|
|
|
'server_url' => array('type' => 'varchar', 'length' => 2047),
|
|
|
|
'timestamp' => array('type' => 'int'),
|
|
|
|
'salt' => array('type' => 'char', 'length' => 40),
|
|
|
|
),
|
|
|
|
'unique keys' => array(
|
2015-02-19 20:01:43 +00:00
|
|
|
'oid_nonces_server_url_timestamp_salt_key' => array(array('server_url', 191), 'timestamp', 'salt'),
|
2011-08-22 22:52:02 +01:00
|
|
|
),
|
|
|
|
));
|
|
|
|
|
2009-10-01 20:43:57 +01:00
|
|
|
return true;
|
|
|
|
}
|
2009-11-08 13:33:22 +00:00
|
|
|
|
2010-03-23 15:36:02 +00:00
|
|
|
/**
|
|
|
|
* Add our tables to be deleted when a user is deleted
|
|
|
|
*
|
|
|
|
* @param User $user User being deleted
|
|
|
|
* @param array &$tables Array of table names
|
|
|
|
*
|
|
|
|
* @return boolean hook value
|
|
|
|
*/
|
2009-11-08 13:33:22 +00:00
|
|
|
function onUserDeleteRelated($user, &$tables)
|
|
|
|
{
|
|
|
|
$tables[] = 'User_openid';
|
2009-11-12 15:38:45 +00:00
|
|
|
$tables[] = 'User_openid_trustroot';
|
2009-11-08 13:33:22 +00:00
|
|
|
return true;
|
|
|
|
}
|
2010-01-08 01:41:55 +00:00
|
|
|
|
2010-05-18 18:39:56 +01:00
|
|
|
/**
|
|
|
|
* Add an OpenID tab to the admin panel
|
|
|
|
*
|
|
|
|
* @param Widget $nav Admin panel nav
|
|
|
|
*
|
|
|
|
* @return boolean hook value
|
|
|
|
*/
|
|
|
|
function onEndAdminPanelNav($nav)
|
|
|
|
{
|
|
|
|
if (AdminPanelAction::canAdmin('openid')) {
|
|
|
|
|
|
|
|
$action_name = $nav->action->trimmed('action');
|
|
|
|
|
|
|
|
$nav->out->menuItem(
|
|
|
|
common_local_url('openidadminpanel'),
|
2010-10-21 01:02:37 +01:00
|
|
|
// TRANS: OpenID configuration menu item.
|
|
|
|
_m('MENU','OpenID'),
|
|
|
|
// TRANS: Tooltip for OpenID configuration menu item.
|
2011-04-27 19:37:44 +01:00
|
|
|
_m('OpenID configuration.'),
|
2010-05-18 18:39:56 +01:00
|
|
|
$action_name == 'openidadminpanel',
|
|
|
|
'nav_openid_admin_panel'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-09-05 23:03:31 +01:00
|
|
|
/**
|
|
|
|
* Add OpenID information to the Account Management Control Document
|
|
|
|
* Event supplied by the Account Manager plugin
|
|
|
|
*
|
|
|
|
* @param array &$amcd Array that expresses the AMCD
|
|
|
|
*
|
|
|
|
* @return boolean hook value
|
|
|
|
*/
|
|
|
|
|
|
|
|
function onEndAccountManagementControlDocument(&$amcd)
|
|
|
|
{
|
|
|
|
$amcd['auth-methods']['openid'] = array(
|
|
|
|
'connect' => array(
|
|
|
|
'method' => 'POST',
|
|
|
|
'path' => common_local_url('openidlogin'),
|
|
|
|
'params' => array(
|
|
|
|
'identity' => 'openid_url'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2010-03-23 15:36:02 +00:00
|
|
|
/**
|
|
|
|
* Add our version information to output
|
|
|
|
*
|
|
|
|
* @param array &$versions Array of version-data arrays
|
|
|
|
*
|
|
|
|
* @return boolean hook value
|
|
|
|
*/
|
2015-06-06 21:04:01 +01:00
|
|
|
function onPluginVersion(array &$versions)
|
2010-01-08 01:41:55 +00:00
|
|
|
{
|
|
|
|
$versions[] = array('name' => 'OpenID',
|
2019-06-03 01:56:52 +01:00
|
|
|
'version' => self::PLUGIN_VERSION,
|
2010-01-08 01:41:55 +00:00
|
|
|
'author' => 'Evan Prodromou, Craig Andrews',
|
2016-01-22 16:38:42 +00:00
|
|
|
'homepage' => 'https://git.gnu.io/gnu/gnu-social/tree/master/plugins/OpenID',
|
2010-01-08 01:41:55 +00:00
|
|
|
'rawdescription' =>
|
2011-04-27 19:37:44 +01:00
|
|
|
// TRANS: Plugin description.
|
2010-01-08 01:41:55 +00:00
|
|
|
_m('Use <a href="http://openid.net/">OpenID</a> to login to the site.'));
|
|
|
|
return true;
|
|
|
|
}
|
2010-10-20 23:59:27 +01:00
|
|
|
|
2010-10-21 00:14:32 +01:00
|
|
|
function onStartOAuthLoginForm($action, &$button)
|
2010-10-20 23:59:27 +01:00
|
|
|
{
|
|
|
|
if (common_config('site', 'openidonly')) {
|
|
|
|
// Cancel the regular password login form, we won't need it.
|
|
|
|
$this->showOAuthLoginForm($action);
|
2010-10-21 00:14:32 +01:00
|
|
|
// TRANS: button label for OAuth authorization page when needing OpenID authentication first.
|
|
|
|
$button = _m('BUTTON', 'Continue');
|
2010-10-20 23:59:27 +01:00
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
// Leave the regular password login form in place.
|
|
|
|
// We'll add an OpenID link at bottom...?
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @fixme merge with common code for main OpenID login form
|
|
|
|
* @param HTMLOutputter $action
|
|
|
|
*/
|
|
|
|
protected function showOAuthLoginForm($action)
|
|
|
|
{
|
2010-10-21 00:14:32 +01:00
|
|
|
$action->elementStart('fieldset');
|
|
|
|
// TRANS: OpenID plugin logon form legend.
|
2011-04-27 19:37:44 +01:00
|
|
|
$action->element('legend', null, _m('LEGEND','OpenID login'));
|
2010-10-21 00:14:32 +01:00
|
|
|
|
2010-10-20 23:59:27 +01:00
|
|
|
$action->elementStart('ul', 'form_data');
|
|
|
|
$action->elementStart('li');
|
|
|
|
$provider = common_config('openid', 'trusted_provider');
|
|
|
|
$appendUsername = common_config('openid', 'append_username');
|
|
|
|
if ($provider) {
|
2010-10-21 01:02:37 +01:00
|
|
|
// TRANS: Field label.
|
2010-10-20 23:59:27 +01:00
|
|
|
$action->element('label', array(), _m('OpenID provider'));
|
|
|
|
$action->element('span', array(), $provider);
|
|
|
|
if ($appendUsername) {
|
|
|
|
$action->element('input', array('id' => 'openid_username',
|
|
|
|
'name' => 'openid_username',
|
|
|
|
'style' => 'float: none'));
|
|
|
|
}
|
|
|
|
$action->element('p', 'form_guide',
|
2010-10-21 01:02:37 +01:00
|
|
|
// TRANS: Form guide.
|
2010-10-20 23:59:27 +01:00
|
|
|
($appendUsername ? _m('Enter your username.') . ' ' : '') .
|
2010-10-21 01:02:37 +01:00
|
|
|
// TRANS: Form guide.
|
2010-10-20 23:59:27 +01:00
|
|
|
_m('You will be sent to the provider\'s site for authentication.'));
|
|
|
|
$action->hidden('openid_url', $provider);
|
|
|
|
} else {
|
|
|
|
// TRANS: OpenID plugin logon form field label.
|
|
|
|
$action->input('openid_url', _m('OpenID URL'),
|
|
|
|
'',
|
|
|
|
// TRANS: OpenID plugin logon form field instructions.
|
2011-04-27 19:37:44 +01:00
|
|
|
_m('Your OpenID URL.'));
|
2010-10-20 23:59:27 +01:00
|
|
|
}
|
|
|
|
$action->elementEnd('li');
|
|
|
|
$action->elementEnd('ul');
|
2010-10-21 00:14:32 +01:00
|
|
|
|
|
|
|
$action->elementEnd('fieldset');
|
2010-10-20 23:59:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle a POST user credential check in apioauthauthorization.
|
|
|
|
* If given an OpenID URL, we'll pass us over to the regular things
|
|
|
|
* and then redirect back here on completion.
|
|
|
|
*
|
|
|
|
* @fixme merge with common code for main OpenID login form
|
|
|
|
* @param HTMLOutputter $action
|
|
|
|
*/
|
|
|
|
function onStartOAuthLoginCheck($action, &$user)
|
|
|
|
{
|
|
|
|
$provider = common_config('openid', 'trusted_provider');
|
|
|
|
if ($provider) {
|
|
|
|
$openid_url = $provider;
|
|
|
|
if (common_config('openid', 'append_username')) {
|
|
|
|
$openid_url .= $action->trimmed('openid_username');
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$openid_url = $action->trimmed('openid_url');
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($openid_url) {
|
|
|
|
require_once dirname(__FILE__) . '/openid.php';
|
|
|
|
oid_assert_allowed($openid_url);
|
|
|
|
|
2010-10-22 03:08:38 +01:00
|
|
|
$returnto = common_local_url(
|
2013-10-06 11:40:58 +01:00
|
|
|
'ApiOAuthAuthorize',
|
2010-10-22 03:08:38 +01:00
|
|
|
array(),
|
|
|
|
array(
|
|
|
|
'oauth_token' => $action->arg('oauth_token'),
|
|
|
|
'mode' => $action->arg('mode')
|
|
|
|
)
|
|
|
|
);
|
2010-10-20 23:59:27 +01:00
|
|
|
common_set_returnto($returnto);
|
|
|
|
|
|
|
|
// This will redirect if functional...
|
|
|
|
$result = oid_authenticate($openid_url,
|
|
|
|
'finishopenidlogin');
|
|
|
|
if (is_string($result)) { # error message
|
|
|
|
throw new ServerException($result);
|
|
|
|
} else {
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2010-12-01 18:43:34 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add link in user's XRD file to allow OpenID login.
|
2011-04-27 19:37:44 +01:00
|
|
|
*
|
2010-12-01 18:43:34 +00:00
|
|
|
* This link in the XRD should let users log in with their
|
|
|
|
* Webfinger identity to services that support it. See
|
|
|
|
* http://webfinger.org/login for an example.
|
|
|
|
*
|
2013-09-30 16:13:03 +01:00
|
|
|
* @param XML_XRD $xrd Currently-displaying resource descriptor
|
|
|
|
* @param Profile $target The profile that it's for
|
2011-04-27 19:37:44 +01:00
|
|
|
*
|
2010-12-01 18:43:34 +00:00
|
|
|
* @return boolean hook value (always true)
|
|
|
|
*/
|
|
|
|
|
2013-10-20 14:32:56 +01:00
|
|
|
function onEndWebFingerProfileLinks(XML_XRD $xrd, Profile $target)
|
2010-12-01 18:43:34 +00:00
|
|
|
{
|
2013-09-30 16:13:03 +01:00
|
|
|
$xrd->links[] = new XML_XRD_Element_Link(
|
|
|
|
'http://specs.openid.net/auth/2.0/provider',
|
|
|
|
$target->profileurl);
|
2011-04-27 19:37:44 +01:00
|
|
|
|
2010-12-01 18:43:34 +00:00
|
|
|
return true;
|
|
|
|
}
|
2012-07-09 17:55:05 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add links in the user's profile block to their OpenID URLs.
|
|
|
|
*
|
|
|
|
* @param Profile $profile The profile being shown
|
|
|
|
* @param Array &$links Writeable array of arrays (href, text, image).
|
|
|
|
*
|
|
|
|
* @return boolean hook value (true)
|
|
|
|
*/
|
|
|
|
|
|
|
|
function onOtherAccountProfiles($profile, &$links)
|
|
|
|
{
|
2013-08-18 12:04:58 +01:00
|
|
|
$prefs = User_openid_prefs::getKV('user_id', $profile->id);
|
2012-07-09 21:51:36 +01:00
|
|
|
|
|
|
|
if (empty($prefs) || !$prefs->hide_profile_link) {
|
2012-07-09 17:55:05 +01:00
|
|
|
|
2012-07-09 21:51:36 +01:00
|
|
|
$oid = new User_openid();
|
2012-07-09 17:55:05 +01:00
|
|
|
|
2012-07-09 21:51:36 +01:00
|
|
|
$oid->user_id = $profile->id;
|
|
|
|
|
|
|
|
if ($oid->find()) {
|
|
|
|
while ($oid->fetch()) {
|
|
|
|
$links[] = array('href' => $oid->display,
|
|
|
|
'text' => _('OpenID'),
|
|
|
|
'image' => $this->path("icons/openid-16x16.gif"));
|
|
|
|
}
|
2012-07-09 17:55:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2009-08-04 14:00:58 +01:00
|
|
|
}
|