plugin_openid:

* Delegation: Configure what OpenID version the provider is supporting
(Version 1 or 2 or both)
* A little refactoring done to make code more readable.
This commit is contained in:
Grischa Brockhaus 2012-03-29 14:01:39 +02:00
parent 6acb2ef440
commit cb8fe52efe
5 changed files with 164 additions and 99 deletions

View file

@ -1,3 +1,8 @@
Version 1.0 (brockhaus)
---------------------------------
* Delegation: Configure what OpenID version the provider is supporting (Version 1 or 2 or both)
* A little refactoring done to make code more readable.
Version 0.9 (brockhaus)
---------------------------------
* If no user has configured his OpenID yet, there will be no OpenID login but a info about that.

View file

@ -40,6 +40,12 @@ Wenn Du das aber nicht magst, kannst Du diese Auswahl ausschalten. Dann wird bei
@define('PLUGIN_OPENID_XRDS_LOC', 'OpenID XRDS Location');
@define('PLUGIN_OPENID_XRDS_LOC_DESC', 'URL des XRDS Dokumentes (wird meist nicht benötigt)');
@define('PLUGIN_OPENID_VERSION_SUPPORTED', 'OpenID Version');
@define('PLUGIN_OPENID_VERSION_SUPPORTED_DESC', 'Die OpenID Version, die Dein Provider unterstützt. Normaler Weise ist "Beide" die richtige Einstellung, aber wenn Du weißt, dass Dein Provider nur Version 1 oder nur Version 2 unterstützt, dann kannst Du das hier einstellen..');
@define('PLUGIN_OPENID_VERSION_SUPPORTED_V1', 'Nur OpenID Version 1');
@define('PLUGIN_OPENID_VERSION_SUPPORTED_V2', 'Nur OpenID Version 2');
@define('PLUGIN_OPENID_VERSION_SUPPORTED_BOTH', 'Beide OpenID Versionen');
@define('PLUGIN_OPENID_LOGIN_INPUT', 'Melde Dich mit Deiner OpenID an.');
@define('PLUGIN_OPENID_UPDATE_SUCCESS', 'Deine OpenID wurde erneuert.');

View file

@ -40,6 +40,12 @@ Wenn Du das aber nicht magst, kannst Du diese Auswahl ausschalten. Dann wird bei
@define('PLUGIN_OPENID_XRDS_LOC', 'OpenID XRDS Location');
@define('PLUGIN_OPENID_XRDS_LOC_DESC', 'URL des XRDS Dokumentes (wird meist nicht benötigt)');
@define('PLUGIN_OPENID_VERSION_SUPPORTED', 'OpenID Version');
@define('PLUGIN_OPENID_VERSION_SUPPORTED_DESC', 'Die OpenID Version, die Dein Provider unterstützt. Normaler Weise ist "Beide" die richtige Einstellung, aber wenn Du weißt, dass Dein Provider nur Version 1 oder nur Version 2 unterstützt, dann kannst Du das hier einstellen..');
@define('PLUGIN_OPENID_VERSION_SUPPORTED_V1', 'Nur OpenID Version 1');
@define('PLUGIN_OPENID_VERSION_SUPPORTED_V2', 'Nur OpenID Version 2');
@define('PLUGIN_OPENID_VERSION_SUPPORTED_BOTH', 'Beide OpenID Versionen');
@define('PLUGIN_OPENID_LOGIN_INPUT', 'Melde Dich mit Deiner OpenID an.');
@define('PLUGIN_OPENID_UPDATE_SUCCESS', 'Deine OpenID wurde erneuert.');

View file

@ -40,6 +40,12 @@ But if you don\'t like that you can switch this off and there will be a normal O
@define('PLUGIN_OPENID_XRDS_LOC', 'OpenID XRDS Location');
@define('PLUGIN_OPENID_XRDS_LOC_DESC', 'URL for XRDS Document Location (not needed normaly)');
@define('PLUGIN_OPENID_VERSION_SUPPORTED', 'OpenID Version');
@define('PLUGIN_OPENID_VERSION_SUPPORTED_DESC', 'The version your OpenID provider is supporting. Normaly "both" is okay, but if you know your provider does support only version 1 or only version 2 you can configure it here.');
@define('PLUGIN_OPENID_VERSION_SUPPORTED_V1', 'OpenID Version 1 only');
@define('PLUGIN_OPENID_VERSION_SUPPORTED_V2', 'OpenID Version 2 only');
@define('PLUGIN_OPENID_VERSION_SUPPORTED_BOTH', 'Both OpenID Versions');
@define('PLUGIN_OPENID_LOGIN_INPUT', 'Logon using your OpenID.');
@define('PLUGIN_OPENID_UPDATE_SUCCESS', 'Your OpenID has been updated');

View file

@ -13,7 +13,7 @@ class serendipity_event_openid extends serendipity_event
$propbag->add('description', PLUGIN_OPENID_DESC);
$propbag->add('stackable', false);
$propbag->add('author', 'Grischa Brockhaus, Rob Richards');
$propbag->add('version', '0.9');
$propbag->add('version', '1.0');
$propbag->add('requirements', array(
'serendipity' => '1.2',
'smarty' => '2.6.7',
@ -34,7 +34,8 @@ class serendipity_event_openid extends serendipity_event
'delegation_desc',
'server',
'delegate',
'xrds_location'
'xrds_location',
'openid_version'
));
}
@ -73,6 +74,18 @@ class serendipity_event_openid extends serendipity_event
$propbag->add('description', PLUGIN_OPENID_XRDS_LOC_DESC);
$propbag->add('default', '');
break;
case 'openid_version':
$id_services = array(
'both' => PLUGIN_OPENID_VERSION_SUPPORTED_BOTH,
'v2' => PLUGIN_OPENID_VERSION_SUPPORTED_V2,
'v1' => PLUGIN_OPENID_VERSION_SUPPORTED_V1,
);
$propbag->add('type', 'select');
$propbag->add('name', PLUGIN_OPENID_VERSION_SUPPORTED);
$propbag->add('description', PLUGIN_OPENID_VERSION_SUPPORTED_DESC);
$propbag->add('select_values', $id_services);
$propbag->add('default', 'both');
break;
default:
return false;
}
@ -127,20 +140,7 @@ class serendipity_event_openid extends serendipity_event
}
break;
case 'frontend_header':
$server = $this->get_config('server');
$openidurl = $this->get_config('delegate');
$xrdsloc = $this->get_config('xrds_location');
if (! empty($server) && (! empty($openidurl) || ! empty($xrdsloc))) {
/* Make sure linefeeds exist otherwise OpenID does not always work correctly */
echo "\n";
echo '<link rel="openid.server" href="'.$server.'" /> '."\n";
if (! empty($openidurl)) {
echo '<link rel="openid.delegate" href="'.$openidurl.'" /> '."\n";
}
if (! empty($xrdsloc)) {
echo '<meta http-equiv="X-XRDS-Location" content="'.$xrdsloc.'" /> '."\n";
}
}
$this->print_header();
break;
case 'backend_login_page':
@ -152,91 +152,10 @@ class serendipity_event_openid extends serendipity_event
break;
case 'backend_login':
$inOpenIdChange = !empty($serendipity['POST']['openidflag']) && ($serendipity['POST']['openidflag']==3);
if ($eventData && !$inOpenIdChange) { // Eventdata holds "isAuthentificated". So if she is, let her in.
return true;
}
$openidurl = NULL;
if (!empty($serendipity['POST']['openid_url'])) {
$openidurl = $serendipity['POST']['openid_url'];
}
elseif (isset($_POST['openIDLoginGoogle_x']) || isset($_POST['openIDLoginGoogle_y'])) { // If the Google Button was pressed
$openidurl = "https://www.google.com/accounts/o8/id";
}
elseif (isset($_POST['openIDLoginYahoo_x']) || isset($_POST['openIDLoginYahoo_y'])) { // If the Google Button was pressed
$openidurl = "https://me.yahoo.com";
}
elseif (isset($_POST['openIDLoginAol_x']) || isset($_POST['openIDLoginAol_y'])) { // If the Google Button was pressed
$openidurl = "https://www.aol.com";
}
if ($_SESSION['serendipityAuthedUser'] == true) {
$eventData = serendipity_common_openid::reauth_openid();
if (!empty($openidurl) && !empty($serendipity['POST']['openidflag'])) {
/* Check that openid isn't already associated with another login */
$tmpRet = serendipity_common_openid::redir_openidserver($openidurl, $this->get_consumertest_path(), 3);
/* If updating an OpenID it is not a real login attempt */
if (($tmpRet === false) && (($serendipity['GET']['openidflag']==3) || ($serendipity['POST']['openidflag']==3))) {
return;
}
$eventData = $tmpRet;
} elseif (!empty($serendipity['POST']['openidflag'])) {
$eventData = serendipity_common_openid::reauth_openid();
}
} else if (! empty($serendipity['GET']['openidflag']) && ($serendipity['GET']['openidflag']==1)) {
$eventData = serendipity_common_openid::authenticate_openid($_GET, $this->get_consumertest_path());
} else if (! empty($openidurl) && ! empty($serendipity['POST']['action'])) {
$eventData = serendipity_common_openid::redir_openidserver($openidurl, $this->get_consumertest_path(), 1);
}
return $eventData;
return $this->do_login($eventData);
case 'backend_sidebar_entries_event_display_profiles':
if (($_SESSION['serendipityAuthedUser'] == true)) {
if (! empty($serendipity['GET']['openidflag']) && ($serendipity['GET']['openidflag']==3)) {
if ($checkRet = serendipity_common_openid::authenticate_openid($_GET, $this->get_consumertest_path(), true)) {
if (serendipity_common_openid::updateOpenID($checkRet['openID'], $serendipity['authorid'])) {
echo '<strong>' . htmlspecialchars(PLUGIN_OPENID_UPDATE_SUCCESS) . '</strong><br /><br />';
} else {
echo '<strong>' . htmlspecialchars(PLUGIN_OPENID_UPDATE_FAIL) . '</strong><br /><br />';
}
} else {
echo '<strong>' . htmlspecialchars(PLUGIN_OPENID_INVALID_RESPONSE) . '</strong><br /><br />';
}
// Job done.
unset($serendipity['GET']['openidflag']);
} elseif (! empty($serendipity['POST']['openidflag']) && ($serendipity['POST']['openidflag']==3)) {
echo '<strong>' . htmlspecialchars(PLUGIN_OPENID_INVALID_RESPONSE) . '</strong><br /><br />';
}
}
$imgopenid = $serendipity['baseURL'] . 'index.php?/plugin/openid.png';
$imggoogle = $serendipity['baseURL'] . 'index.php?/plugin/oids_google.png';
$imgyahoo = $serendipity['baseURL'] . 'index.php?/plugin/oids_yahoo.png';
$imgaol = $serendipity['baseURL'] . 'index.php?/plugin/oids_aol.png';
echo '<div>';
echo '<strong>' . htmlspecialchars(PLUGIN_EVENT_OPENID_SELECT) . '</strong><br /><br />';
// To allow ENTER in the input line we have to create two forms:
echo '<form action="?" method="post">';
echo '<input type="hidden" name="serendipity[adminModule]" value="event_display" />';
echo '<input type="hidden" name="serendipity[adminAction]" value="profiles" />';
echo '<input type="hidden" name="serendipity[openidflag]" value="3" />';
echo '<img src="' . $imgopenid . '" alt="OpenID URL"> <input type="text" size="50" name="serendipity[openid_url]" value="'. serendipity_common_openid::getOpenID($serendipity['authorid']) .'" />';
echo ' <input type="submit" name="submit" value="' . EDIT . '" placeholder="' . PLUGIN_OPENID_LOGIN_INPUT . '"/>';
echo '</form>';
echo '<form action="?" method="post">';
echo '<input type="hidden" name="serendipity[adminModule]" value="event_display" />';
echo '<input type="hidden" name="serendipity[adminAction]" value="profiles" />';
echo '<input type="hidden" name="serendipity[openidflag]" value="3" />';
echo '<input name="openIDLoginGoogle" type="image" src="' . $imggoogle . '" alt="' . PLUGIN_OPENID_SET_GOOGLE_OID .'" title="'. PLUGIN_OPENID_SET_GOOGLE_OID .'"/> ';
echo '<input name="openIDLoginYahoo" type="image" src="' . $imgyahoo . '" alt="' . PLUGIN_OPENID_SET_YAHOO_OID .'" title="'. PLUGIN_OPENID_SET_YAHOO_OID .'"/> ';
echo '<input name="openIDLoginAol" type="image" src="' . $imgaol . '" alt="' . PLUGIN_OPENID_SET_AOL_OID .'" title="'. PLUGIN_OPENID_SET_AOL_OID .'"/> ';
echo '</form>';
echo '</div><br /><hr />';
$this->print_sidebar();
return true;
default:
return false;
@ -245,7 +164,130 @@ class serendipity_event_openid extends serendipity_event
return false;
}
}
function do_login(&$eventData) {
global $serendipity;
$inOpenIdChange = !empty($serendipity['POST']['openidflag']) && ($serendipity['POST']['openidflag']==3);
if ($eventData && !$inOpenIdChange) { // Eventdata holds "isAuthentificated". So if she is, let her in.
return true;
}
$openidurl = NULL;
if (!empty($serendipity['POST']['openid_url'])) {
$openidurl = $serendipity['POST']['openid_url'];
}
elseif (isset($_POST['openIDLoginGoogle_x']) || isset($_POST['openIDLoginGoogle_y'])) { // If the Google Button was pressed
$openidurl = "https://www.google.com/accounts/o8/id";
}
elseif (isset($_POST['openIDLoginYahoo_x']) || isset($_POST['openIDLoginYahoo_y'])) { // If the Google Button was pressed
$openidurl = "https://me.yahoo.com";
}
elseif (isset($_POST['openIDLoginAol_x']) || isset($_POST['openIDLoginAol_y'])) { // If the Google Button was pressed
$openidurl = "https://www.aol.com";
}
if ($_SESSION['serendipityAuthedUser'] == true) {
$eventData = serendipity_common_openid::reauth_openid();
if (!empty($openidurl) && !empty($serendipity['POST']['openidflag'])) {
/* Check that openid isn't already associated with another login */
$tmpRet = serendipity_common_openid::redir_openidserver($openidurl, $this->get_consumertest_path(), 3);
/* If updating an OpenID it is not a real login attempt */
if (($tmpRet === false) && (($serendipity['GET']['openidflag']==3) || ($serendipity['POST']['openidflag']==3))) {
return;
}
$eventData = $tmpRet;
} elseif (!empty($serendipity['POST']['openidflag'])) {
$eventData = serendipity_common_openid::reauth_openid();
}
} else if (! empty($serendipity['GET']['openidflag']) && ($serendipity['GET']['openidflag']==1)) {
$eventData = serendipity_common_openid::authenticate_openid($_GET, $this->get_consumertest_path());
} else if (! empty($openidurl) && ! empty($serendipity['POST']['action'])) {
$eventData = serendipity_common_openid::redir_openidserver($openidurl, $this->get_consumertest_path(), 1);
}
return $eventData;
}
function print_header() {
$server = $this->get_config('server');
$openidurl = $this->get_config('delegate');
$xrdsloc = $this->get_config('xrds_location');
if (! empty($server) && (! empty($openidurl) || ! empty($xrdsloc))) {
$supported_version = $this->get_config('openid_version', 'both');
if ('v1'==$supported_version) {
$rel_oserver = "openid.server";
$rel_odelegate = "openid.delegate";
}
elseif ('v2'==$supported_version) {
$rel_oserver = "openid2.provider";
$rel_odelegate = "openid2.local_id";
}
else {
$rel_oserver = "openid.server openid2.provider";
$rel_odelegate = "openid.delegate openid2.local_id";
}
/* Make sure linefeeds exist otherwise OpenID does not always work correctly */
echo "\n";
echo '<link rel="' . $rel_oserver .'" href="'.$server.'" /> '."\n";
if (! empty($openidurl)) {
echo '<link rel="' . $rel_odelegate .'" href="'.$openidurl.'" /> '."\n";
}
if (! empty($xrdsloc)) {
echo '<meta http-equiv="X-XRDS-Location" content="'.$xrdsloc.'" /> '."\n";
}
}
}
function print_sidebar() {
global $serendipity;
if (($_SESSION['serendipityAuthedUser'] == true)) {
if (! empty($serendipity['GET']['openidflag']) && ($serendipity['GET']['openidflag']==3)) {
if ($checkRet = serendipity_common_openid::authenticate_openid($_GET, $this->get_consumertest_path(), true)) {
if (serendipity_common_openid::updateOpenID($checkRet['openID'], $serendipity['authorid'])) {
echo '<strong>' . htmlspecialchars(PLUGIN_OPENID_UPDATE_SUCCESS) . '</strong><br /><br />';
} else {
echo '<strong>' . htmlspecialchars(PLUGIN_OPENID_UPDATE_FAIL) . '</strong><br /><br />';
}
} else {
echo '<strong>' . htmlspecialchars(PLUGIN_OPENID_INVALID_RESPONSE) . '</strong><br /><br />';
}
// Job done.
unset($serendipity['GET']['openidflag']);
} elseif (! empty($serendipity['POST']['openidflag']) && ($serendipity['POST']['openidflag']==3)) {
echo '<strong>' . htmlspecialchars(PLUGIN_OPENID_INVALID_RESPONSE) . '</strong><br /><br />';
}
}
$imgopenid = $serendipity['baseURL'] . 'index.php?/plugin/openid.png';
$imggoogle = $serendipity['baseURL'] . 'index.php?/plugin/oids_google.png';
$imgyahoo = $serendipity['baseURL'] . 'index.php?/plugin/oids_yahoo.png';
$imgaol = $serendipity['baseURL'] . 'index.php?/plugin/oids_aol.png';
echo '<div>';
echo '<strong>' . htmlspecialchars(PLUGIN_EVENT_OPENID_SELECT) . '</strong><br /><br />';
// To allow ENTER in the input line we have to create two forms:
echo '<form action="?" method="post">';
echo '<input type="hidden" name="serendipity[adminModule]" value="event_display" />';
echo '<input type="hidden" name="serendipity[adminAction]" value="profiles" />';
echo '<input type="hidden" name="serendipity[openidflag]" value="3" />';
echo '<img src="' . $imgopenid . '" alt="OpenID URL"> <input type="text" size="50" name="serendipity[openid_url]" value="'. serendipity_common_openid::getOpenID($serendipity['authorid']) .'" />';
echo ' <input type="submit" name="submit" value="' . EDIT . '" placeholder="' . PLUGIN_OPENID_LOGIN_INPUT . '"/>';
echo '</form>';
echo '<form action="?" method="post">';
echo '<input type="hidden" name="serendipity[adminModule]" value="event_display" />';
echo '<input type="hidden" name="serendipity[adminAction]" value="profiles" />';
echo '<input type="hidden" name="serendipity[openidflag]" value="3" />';
echo '<input name="openIDLoginGoogle" type="image" src="' . $imggoogle . '" alt="' . PLUGIN_OPENID_SET_GOOGLE_OID .'" title="'. PLUGIN_OPENID_SET_GOOGLE_OID .'"/> ';
echo '<input name="openIDLoginYahoo" type="image" src="' . $imgyahoo . '" alt="' . PLUGIN_OPENID_SET_YAHOO_OID .'" title="'. PLUGIN_OPENID_SET_YAHOO_OID .'"/> ';
echo '<input name="openIDLoginAol" type="image" src="' . $imgaol . '" alt="' . PLUGIN_OPENID_SET_AOL_OID .'" title="'. PLUGIN_OPENID_SET_AOL_OID .'"/> ';
echo '</form>';
echo '</div><br /><hr />';
}
function get_consumertest_path() {
global $serendipity;