Merge branch 'browserid'
This commit is contained in:
commit
4674b4c36b
11
serendipity_event_browserid/UTF-8/lang_de.inc.php
Normal file
11
serendipity_event_browserid/UTF-8/lang_de.inc.php
Normal file
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
|
||||
@define('PLUGIN_BROWSERID_NAME', 'BrowserID Authentifizierung');
|
||||
@define('PLUGIN_BROWSERID_DESC', 'Ermöglicht Autoren, sich mittels de BrowserID Services einzuloggen.');
|
||||
|
||||
@define('PLUGIN_BROWSERID_DESCRIPTION',
|
||||
'<h3>BrowserID benutzen, um sich im Blog anzumelden</h3>' .
|
||||
'<p>BrowserID benötigt keinerlei Konfiguration. Du kannst Dich mit der EMail Adresse anmelden, die mit <a href="serendipity_admin.php?serendipity[adminModule]=personal">Deinem Accout</a> verknüpft ist.<br/>
|
||||
Wenn Du Deine EMail bisher noch nicht bei BrowserID registriert hast, dann kannst Du das im Login Prozess nachholen oder es jetzt direkt bei <a href="https://browserid.org/" target="_blank">der BrowserID Webseite</a> tun.<br/>
|
||||
BrowserID muss zuerst verifizieren, dass die EMail wirklich Dir gehört. Danach kannst Du BrowserID als Login Methode benutzen.</p>'
|
||||
);
|
BIN
serendipity_event_browserid/browserid_signin.png
Normal file
BIN
serendipity_event_browserid/browserid_signin.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.8 KiB |
11
serendipity_event_browserid/lang_de.inc.php
Normal file
11
serendipity_event_browserid/lang_de.inc.php
Normal file
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
|
||||
@define('PLUGIN_BROWSERID_NAME', 'BrowserID Authentifizierung');
|
||||
@define('PLUGIN_BROWSERID_DESC', 'Ermöglicht Autoren, sich mittels de BrowserID Services einzuloggen.');
|
||||
|
||||
@define('PLUGIN_BROWSERID_DESCRIPTION',
|
||||
'<h3>BrowserID benutzen, um sich im Blog anzumelden</h3>' .
|
||||
'<p>BrowserID benötigt keinerlei Konfiguration. Du kannst Dich mit der EMail Adresse anmelden, die mit <a href="serendipity_admin.php?serendipity[adminModule]=personal">Deinem Accout</a> verknüpft ist.<br/>
|
||||
Wenn Du Deine EMail bisher noch nicht bei BrowserID registriert hast, dann kannst Du das im Login Prozess nachholen oder es jetzt direkt bei <a href="https://browserid.org/" target="_blank">der BrowserID Webseite</a> tun.<br/>
|
||||
BrowserID muss zuerst verifizieren, dass die EMail wirklich Dir gehört. Danach kannst Du BrowserID als Login Methode benutzen.</p>'
|
||||
);
|
11
serendipity_event_browserid/lang_en.inc.php
Normal file
11
serendipity_event_browserid/lang_en.inc.php
Normal file
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
|
||||
@define('PLUGIN_BROWSERID_NAME', 'BrowserID Authentification');
|
||||
@define('PLUGIN_BROWSERID_DESC', 'Allows authors to authenticate using the BrowserID service.');
|
||||
|
||||
@define('PLUGIN_BROWSERID_DESCRIPTION',
|
||||
'<h3>Using BrwoserID to log into your blog</h3>' .
|
||||
'<p>BrowserID does not need any configuration. You will login naming the email address associated with <a href="serendipity_admin.php?serendipity[adminModule]=personal">your blog account</a>.<br/>
|
||||
If you did not register your email with BrowserID yet, you can do so while login or you can directly do it at <a href="https://browserid.org/" target="_blank">the BrowserID website</a>.<br/>
|
||||
BrowserID needs to verify first, that you are the owner of this email. After this process you are ready to use your new BrowserID as login.</p>'
|
||||
);
|
48
serendipity_event_browserid/serendipity_event_browserid.js
Normal file
48
serendipity_event_browserid/serendipity_event_browserid.js
Normal file
|
@ -0,0 +1,48 @@
|
|||
(function() {
|
||||
var request, but = document.querySelector('button');
|
||||
|
||||
but.addEventListener('click', function(ev) {
|
||||
|
||||
navigator.id.getVerifiedEmail(function(assertion) {
|
||||
if (assertion) {
|
||||
verify(assertion);
|
||||
} else {
|
||||
alert('I still don\'t know you. Did you cancel?');
|
||||
}
|
||||
});
|
||||
|
||||
function verify(assertion) {
|
||||
request = new XMLHttpRequest();
|
||||
var parameters = 'assert=' + assertion;
|
||||
request.open('POST', browserid_verify);
|
||||
request.setRequestHeader('If-Modified-Since',
|
||||
'Wed, 05 Apr 2006 00:00:00 GMT');
|
||||
request.setRequestHeader('Content-type',
|
||||
'application/x-www-form-urlencoded');
|
||||
request.setRequestHeader('Content-length', parameters.length);
|
||||
request.setRequestHeader('Connection', 'close');
|
||||
request.send(encodeURI(parameters));
|
||||
|
||||
request.onreadystatechange = function() {
|
||||
if (request.readyState == 4) {
|
||||
if (request.status && (/200|304/).test(request.status)) {
|
||||
response = JSON.parse(request.responseText);
|
||||
if (response.status === 'okay') {
|
||||
self.location.href = "serendipity_admin.php"
|
||||
}
|
||||
else {if (response.status === 'errorhost' || response.status === 's9yunknown') {
|
||||
alert(response.message);
|
||||
}
|
||||
else {
|
||||
alert('Unknown error: ' . response.status);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
alert('Sorry, I could not log you in.');
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}, false);
|
||||
}());
|
200
serendipity_event_browserid/serendipity_event_browserid.php
Normal file
200
serendipity_event_browserid/serendipity_event_browserid.php
Normal file
|
@ -0,0 +1,200 @@
|
|||
<?php # $Id$
|
||||
|
||||
// Probe for a language include with constants. Still include defines later on, if some constants were missing
|
||||
$probelang = dirname(__FILE__) . '/' . $serendipity['charset'] . 'lang_' . $serendipity['lang'] . '.inc.php';
|
||||
if (file_exists($probelang)) {
|
||||
include $probelang;
|
||||
}
|
||||
include_once dirname(__FILE__) . '/lang_en.inc.php';
|
||||
|
||||
class serendipity_event_browserid extends serendipity_event
|
||||
{
|
||||
function introspect(&$propbag)
|
||||
{
|
||||
global $serendipity;
|
||||
|
||||
$propbag->add('name', PLUGIN_BROWSERID_NAME);
|
||||
$propbag->add('description', PLUGIN_BROWSERID_DESC);
|
||||
$propbag->add('stackable', false);
|
||||
$propbag->add('author', 'Grischa Brockhaus');
|
||||
$propbag->add('version', '1.0');
|
||||
$propbag->add('requirements', array(
|
||||
'serendipity' => '1.6',
|
||||
'smarty' => '2.6.7',
|
||||
'php' => '5.1.3'
|
||||
));
|
||||
$propbag->add('groups', array('BACKEND_USERMANAGEMENT'));
|
||||
$propbag->add('event_hooks', array(
|
||||
'backend_login' => true,
|
||||
'backend_login_page' => true,
|
||||
'backend_header' => true,
|
||||
'external_plugin' => true,
|
||||
));
|
||||
|
||||
$propbag->add('configuration', array(
|
||||
'plugin_desc',
|
||||
));
|
||||
}
|
||||
|
||||
function introspect_config_item($name, &$propbag)
|
||||
{
|
||||
switch($name) {
|
||||
case 'plugin_desc':
|
||||
$propbag->add('type', 'content');
|
||||
$propbag->add('default', PLUGIN_BROWSERID_DESCRIPTION);
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function generate_content(&$title) {
|
||||
$title = PLUGIN_OPENID_NAME;
|
||||
}
|
||||
|
||||
function event_hook($event, &$bag, &$eventData, $addData = null) {
|
||||
global $serendipity;
|
||||
static $login_url = null;
|
||||
|
||||
if ($login_url === null) {
|
||||
$login_url = $serendipity['baseURL'] . $serendipity['indexFile'] . '?/plugin/loginbox';
|
||||
}
|
||||
|
||||
$hooks = &$bag->get('event_hooks');
|
||||
|
||||
if (isset($hooks[$event])) {
|
||||
switch($event) {
|
||||
case 'external_plugin':
|
||||
if ($eventData=="serendipity_event_browserid.js") {
|
||||
header('Content-Type: text/javascript');
|
||||
echo file_get_contents(dirname(__FILE__). '/serendipity_event_browserid.js');
|
||||
}
|
||||
else if ($eventData=="browserid_signin.png") {
|
||||
header('Content-Type: image/png');
|
||||
echo file_get_contents(dirname(__FILE__). '/browserid_signin.png');
|
||||
}
|
||||
else if ($eventData=="serendipity_event_browserid_verify") {
|
||||
$this->verify();
|
||||
}
|
||||
break;
|
||||
|
||||
case 'backend_login_page':
|
||||
$this->print_loginpage($eventData);
|
||||
break;
|
||||
|
||||
case 'backend_login':
|
||||
if ($eventData) {
|
||||
return true;
|
||||
}
|
||||
return;
|
||||
case 'backend_header':
|
||||
$this->print_backend_header();
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function verify() {
|
||||
global $serendipity;
|
||||
|
||||
$url = 'https://browserid.org/verify';
|
||||
$assert = $_POST['assert'];
|
||||
$params = 'assertion='.$assert.'&audience=' .
|
||||
urlencode($serendipity['baseURL']);
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch,CURLOPT_URL,$url);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch,CURLOPT_POST,2);
|
||||
curl_setopt($ch,CURLOPT_POSTFIELDS, $params);
|
||||
$result = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
$response = json_decode($result);
|
||||
if (isset($response) && $response->status=='okay') {
|
||||
$email = $response->email;
|
||||
$audience = $response->audience;
|
||||
if ($audience!=$serendipity['baseURL']) { // The login has the wrong host!
|
||||
$response->status = 'errorhost';
|
||||
$response->message= "Internal error logging you in (wrong host: $audience)";
|
||||
$_SESSION['serendipityAuthedUser'] = false;
|
||||
@session_destroy();
|
||||
}
|
||||
else { // host ist correct, check what we have with this email
|
||||
$password = md5($email);
|
||||
$query = "SELECT DISTINCT a.email, a.authorid, a.userlevel, a.right_publish, a.realname
|
||||
FROM
|
||||
{$serendipity['dbPrefix']}authors AS a
|
||||
WHERE
|
||||
a.email = '{$email}'";
|
||||
$row = serendipity_db_query($query, true, 'assoc');
|
||||
if (is_array($row)) {
|
||||
serendipity_setCookie('old_session', session_id());
|
||||
serendipity_setAuthorToken();
|
||||
$_SESSION['serendipityUser'] = $serendipity['serendipityUser'] = $row['realname'];
|
||||
$_SESSION['serendipityPassword'] = $serendipity['serendipityPassword'] = $password;
|
||||
$_SESSION['serendipityEmail'] = $serendipity['serendipityEmail'] = $email;
|
||||
$_SESSION['serendipityAuthorid'] = $serendipity['authorid'] = $row['authorid'];
|
||||
$_SESSION['serendipityUserlevel'] = $serendipity['serendipityUserlevel'] = $row['userlevel'];
|
||||
$_SESSION['serendipityAuthedUser'] = $serendipity['serendipityAuthedUser'] = true;
|
||||
$_SESSION['serendipityRightPublish']= $serendipity['serendipityRightPublish'] = $row['right_publish'];
|
||||
$_SESSION['serendipityOpenID'] = true;
|
||||
serendipity_load_configuration($serendipity['authorid']);
|
||||
}
|
||||
else { // No user found for that email!
|
||||
$response->status = 's9yunknown';
|
||||
$response->message= "Sorry, we don't have a user for $email";
|
||||
$_SESSION['serendipityAuthedUser'] = false;
|
||||
@session_destroy();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
$result = json_encode($response);
|
||||
}
|
||||
echo $result;
|
||||
}
|
||||
|
||||
function print_backend_header() {
|
||||
echo '
|
||||
<script src="https://browserid.org/include.js" type="text/javascript"></script>
|
||||
';
|
||||
}
|
||||
|
||||
function print_loginpage(&$eventData) {
|
||||
global $serendipity;
|
||||
|
||||
$hidden = array('action'=>'admin');
|
||||
$bid_title = "Sign-in with BrowserID";
|
||||
$local_signin_img = $serendipity['baseURL'] . 'index.php?/plugin/browserid_signin.png';
|
||||
$local_js = $serendipity['baseURL'] . 'index.php?/plugin/serendipity_event_browserid.js';
|
||||
$verify_url = $serendipity['baseURL'] . 'index.php?/plugin/serendipity_event_browserid_verify';
|
||||
|
||||
$eventData['header'] .= '
|
||||
<!-- browserid start -->
|
||||
<script type="text/javascript">var browserid_verify="'. $verify_url . '";</script>
|
||||
<div align="center">
|
||||
<section><button><img src="' . $local_signin_img . '" alt="' . $bid_title . '" title="' . $bid_title . '"></button></section>
|
||||
</div>
|
||||
<script src="' . $local_js . '" type="text/javascript"></script>
|
||||
<!-- browserid end -->
|
||||
';
|
||||
|
||||
}
|
||||
|
||||
function print_backend_footer() {
|
||||
global $serendipity;
|
||||
$local_js = $serendipity['baseURL'] . 'index.php?/plugin/serendipity_event_browserid.js';
|
||||
echo '
|
||||
<!-- browserid start -->
|
||||
<script src="' . $local_js . '" type="text/javascript"></script>
|
||||
<!-- browserid end -->
|
||||
';
|
||||
}
|
||||
}
|
||||
|
||||
/* vim: set sts=4 ts=4 expandtab : */
|
|
@ -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.6');
|
||||
$propbag->add('version', '0.5');
|
||||
$propbag->add('requirements', array(
|
||||
'serendipity' => '1.2',
|
||||
'smarty' => '2.6.7',
|
||||
|
@ -139,6 +139,7 @@ class serendipity_event_openid extends serendipity_event
|
|||
}
|
||||
} else if (! empty($serendipity['GET']['openidflag']) && ($serendipity['GET']['openidflag']==1)) {
|
||||
$eventData = serendipity_common_openid::authenticate_openid($_GET, $this->get_consumertest_path());
|
||||
print_r($eventData);
|
||||
} else if (! empty($serendipity['POST']['openid_url']) && ! empty($serendipity['POST']['action'])) {
|
||||
$eventData = serendipity_common_openid::redir_openidserver($serendipity['POST']['openid_url'], $this->get_consumertest_path(), 1);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue