aboutsummaryrefslogtreecommitdiff
path: root/mod/openid_client/return.php
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2013-12-29 20:45:58 -0200
committerSilvio Rhatto <rhatto@riseup.net>2013-12-29 20:45:58 -0200
commit97e689213ff4e829f251af526ed4e796a3cc2b71 (patch)
treeb04d03ec56305041216b72328fc9b5afde27bc76 /mod/openid_client/return.php
parent0ab6351abb7a602d96c62b0ad35413c88113a6cf (diff)
parent69e2d8c5d8732042c9319aef1fdea45a82b63e42 (diff)
downloadelgg-97e689213ff4e829f251af526ed4e796a3cc2b71.tar.gz
elgg-97e689213ff4e829f251af526ed4e796a3cc2b71.tar.bz2
Merge branch 'master' into saravea
Conflicts: .gitmodules mod/admins mod/assemblies mod/audio_html5 mod/beechat mod/crud mod/elgg-activitystreams mod/elggman mod/elggpg mod/favorites mod/federated-objects mod/friendly_time mod/group_alias mod/group_operators mod/languages mod/lightpics mod/openid_client mod/spotlight mod/suicide mod/tasks mod/videolist
Diffstat (limited to 'mod/openid_client/return.php')
-rw-r--r--mod/openid_client/return.php69
1 files changed, 69 insertions, 0 deletions
diff --git a/mod/openid_client/return.php b/mod/openid_client/return.php
new file mode 100644
index 000000000..3aa728ea6
--- /dev/null
+++ b/mod/openid_client/return.php
@@ -0,0 +1,69 @@
+<?php
+/**
+ * Callback for return_to url redirection.
+ *
+ * The identity server will redirect back to this handler with the results of
+ * the authentication attempt.
+ *
+ * Note: the Janrain OpenID library is incompatible with Elgg's routing so
+ * this script needs to be directly accessed.
+ */
+
+require_once dirname(dirname(dirname(__FILE__))).'/engine/start.php';
+
+elgg_load_library('openid_consumer');
+elgg_load_library('openid_client');
+
+$persistent = get_input('persistent', false);
+
+// get user data from the response
+$consumer = new ElggOpenIDConsumer($store);
+$url = elgg_get_site_url() . "mod/openid_client/return.php?persistent=$persistent";
+$consumer->setReturnURL($url);
+$data = $consumer->completeAuthentication();
+if (!$data || !$data['openid_identifier']) {
+ register_error(elgg_echo('openid_client:error:bad_response'));
+ forward();
+}
+
+// is there an account already associated with this openid
+$user = null;
+$users = elgg_get_entities_from_annotations(array(
+ 'type' => 'user',
+ 'annotation_name' => 'openid_identifier',
+ 'annotation_value' => $data['openid_identifier'],
+));
+if ($users) {
+ // there should only be one account
+ $user = $users[0];
+} else {
+ $email = elgg_extract('email', $data);
+ if ($email) {
+ $users = get_user_by_email($email);
+ if (count($users)) {
+ register_error(elgg_echo('openid_client:email_register'));
+ forward();
+
+ }
+ }
+}
+
+if ($user) {
+ // log in user and maybe update account (admin setting, user prompt?)
+ try {
+ login($user, $persistent);
+ } catch (LoginException $e) {
+ register_error($e->getMessage());
+ forward();
+ }
+
+ system_message(elgg_echo('loginok'));
+ forward();
+} else {
+ // register the new user
+ $result = openid_client_registration_page_handler($data);
+ if (!$result) {
+ register_error(elgg_echo('openid_client:error:bad_register'));
+ forward();
+ }
+}