aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--actions/openid_client/login.php2
-rw-r--r--classes/ElggOpenIDConsumer.php48
-rw-r--r--languages/en.php9
-rw-r--r--lib/helpers.php2
-rw-r--r--return.php5
-rw-r--r--start.php12
6 files changed, 59 insertions, 19 deletions
diff --git a/actions/openid_client/login.php b/actions/openid_client/login.php
index 305ea3110..762f37f06 100644
--- a/actions/openid_client/login.php
+++ b/actions/openid_client/login.php
@@ -8,7 +8,7 @@ elgg_load_library('openid_consumer');
$store = new Auth_OpenID_FileStore('/tmp');
$consumer = new ElggOpenIDConsumer($store);
-$consumer->setProvider('google');
+$consumer->setProvider(get_input('provider'));
$consumer->setReturnURL(elgg_get_site_url() . 'mod/openid_client/return.php');
$html = $consumer->requestAuthentication();
diff --git a/classes/ElggOpenIDConsumer.php b/classes/ElggOpenIDConsumer.php
index 6e6828e1c..864e47d41 100644
--- a/classes/ElggOpenIDConsumer.php
+++ b/classes/ElggOpenIDConsumer.php
@@ -6,6 +6,7 @@
class ElggOpenIDConsumer {
protected $provider;
+ protected $username;
protected $returnURL;
protected $store;
@@ -36,6 +37,15 @@ class ElggOpenIDConsumer {
}
/**
+ * Set the OpenID username
+ *
+ * @param string $username
+ */
+ public function setUsername($username) {
+ $this->username = $username;
+ }
+
+ /**
* Set the return URL
*
* @param string $url The URL the OpenID provider returns the user to
@@ -119,11 +129,39 @@ class ElggOpenIDConsumer {
*/
protected function getProviderURL() {
$url = null;
- switch ($this->provider) {
+ $provider = $this->provider;
+ $username = $this->username;
+ switch ($provider) {
case 'google':
$url = 'https://www.google.com/accounts/o8/id';
break;
+ case 'yahoo':
+ $url = 'https://me.yahoo.com/';
+ break;
+ case 'blogger':
+ $url = "http://$username.blogspot.com/";
+ break;
+ case 'wordpress':
+ $url = "";
+ break;
+ case 'aol':
+ $url = "http://openid.aol.com/$username";
+ break;
+ case 'verisign':
+ $url = "http://username.pip.verisignlabs.com/";
+ break;
+ case 'myopenid':
+ $url = 'https://myopenid.com/';
+ break;
+ case 'myspace':
+ $url = 'https://api.myspace.com/openid';
+ break;
default:
+ $params = array(
+ 'provider' => $provider,
+ 'username' => $username,
+ );
+ $url = elgg_trigger_plugin_hook('set', 'openid_client:url', $params);
break;
}
@@ -199,7 +237,7 @@ class ElggOpenIDConsumer {
$data = $this->extractUserData($sreg, $ax);
$data['openid_identifier'] = $response->getDisplayIdentifier();
- return data;
+ return $data;
}
/**
@@ -217,7 +255,7 @@ class ElggOpenIDConsumer {
$data['email'] = $sreg['email'];
}
if (isset($ax['http://axschema.org/contact/email'])) {
- $data['email'] = $ax['http://axschema.org/contact/email'];
+ $data['email'] = $ax['http://axschema.org/contact/email'][0];
}
// display name
@@ -225,10 +263,10 @@ class ElggOpenIDConsumer {
$data['name'] = $sreg['fullname'];
}
if (isset($ax['http://axschema.org/namePerson/first'])) {
- $data['name'] = $ax['http://axschema.org/namePerson/first'];
+ $data['name'] = $ax['http://axschema.org/namePerson/first'][0];
}
if (isset($ax['http://axschema.org/namePerson/last'])) {
- $data['name'] .= ' ' . $ax['http://axschema.org/namePerson/last'];
+ $data['name'] .= ' ' . $ax['http://axschema.org/namePerson/last'][0];
$data['name'] = trim($data['name']);
}
diff --git a/languages/en.php b/languages/en.php
index df20c95f9..d68517b01 100644
--- a/languages/en.php
+++ b/languages/en.php
@@ -8,13 +8,14 @@ $english = array(
'openid_client:login:header' => 'Log in with',
'openid_client:or:header' => 'or',
'openid_client:login:instructs' => 'Login in with %s',
- 'openid_client:server:google' => 'Google',
- 'openid_client:server:yahoo' => 'Yahoo',
- 'openid_client:server:blogger' => 'Blogger',
- 'openid_client:server:wordpress' => 'Wordpress',
+ 'openid_client:provider:google' => 'Google',
+ 'openid_client:provider:yahoo' => 'Yahoo',
+ 'openid_client:provider:blogger' => 'Blogger',
+ 'openid_client:provider:wordpress' => 'Wordpress',
'openid_client:success:register' => 'Your account has been created.',
'openid_client:error:bad_register' => 'Unable to create an account. Please contact a site administrator.',
+ 'openid_client:error:bad_response' => 'Bad response from the OpenID server',
);
add_translation('en', $english);
diff --git a/lib/helpers.php b/lib/helpers.php
index c7158235a..765fc0a61 100644
--- a/lib/helpers.php
+++ b/lib/helpers.php
@@ -43,7 +43,7 @@ function openid_client_prepare_registration_vars(array $data) {
if (isset($data['username'])) {
$vars['username'] = $data['username'];
} else if (isset($data['email'])) {
- $vars['username'] = array_pop(explode('@', $data['email']));
+ $vars['username'] = array_shift(explode('@', $data['email']));
} else {
$vars['username'] = null;
}
diff --git a/return.php b/return.php
index 2ae21e21f..e53d17d7e 100644
--- a/return.php
+++ b/return.php
@@ -21,7 +21,8 @@ $url = elgg_get_site_url() . 'mod/openid_client/return.php';
$consumer->setReturnURL($url);
$data = $consumer->completeAuthentication();
if (!$data || !$data['openid_identifier']) {
- // @todo handle error
+ register_error(elgg_echo('openid_client:error:bad_response'));
+ forward();
}
// does this user exist
@@ -48,7 +49,7 @@ if ($users) {
// register the new user
$result = openid_client_registration_page_handler($data);
if (!$result) {
- register_error('openid_client:error:bad_register');
+ register_error(elgg_echo('openid_client:error:bad_register'));
forward();
}
}
diff --git a/start.php b/start.php
index bd80dde48..afe12ae92 100644
--- a/start.php
+++ b/start.php
@@ -63,14 +63,14 @@ function openid_client_setup_menu($hook, $type, $menu, $params) {
$items = elgg_trigger_plugin_hook('register', 'openid_login', null, $items);
$priority = 100;
- foreach ($items as $type => $servers) {
- foreach ($servers as $server) {
- $server_name = elgg_echo("openid_client:server:$server");
+ foreach ($items as $type => $providers) {
+ foreach ($providers as $provider) {
+ $provider_name = elgg_echo("openid_client:provider:$provider");
$menu[] = ElggMenuItem::factory(array(
- 'name' => $server,
+ 'name' => $provider,
'text' => '<span></span>',
- 'title' => elgg_echo('openid_client:login:instructs', array($server_name)),
- 'href' => "action/openid_client/login?server=$server",
+ 'title' => elgg_echo('openid_client:login:instructs', array($provider_name)),
+ 'href' => "action/openid_client/login?provider=$provider",
'is_action' => true,
'section' => $type,
'priority' => $priority,