diff --git a/openid_sso_relying.module b/openid_sso_relying.module
index 59a93d3..9d7fa09 100644
--- a/openid_sso_relying.module
+++ b/openid_sso_relying.module
@@ -44,6 +44,98 @@ function openid_sso_relying_menu_alter(&$items) {
   $items['user/password']['page callback'] = 'openid_sso_relying_user_password_page';
   $items['user']['page callback'] = 'openid_sso_relying_user_page';
   $items['logout']['page callback'] = 'openid_sso_relying_logout_page';
+  $items['openid/authenticate']['page callback'] = '_openid_sso_relying_openid_authentication_page';
+}
+
+/**
+ * Rewrite of openid_authentication_page to send the user to the 'user' page
+ */
+function _openid_sso_relying_openid_authentication_page() {
+  $result = openid_complete();
+  switch ($result['status']) {
+    case 'success':
+      return _openid_sso_relying_openid_authentication($result);
+    case 'failed':
+      drupal_set_message(t('OpenID login failed.'), 'error');
+      break;
+    case 'cancel':
+      drupal_set_message(t('OpenID login cancelled.'));
+      break;
+  }
+  drupal_goto();
+}
+
+/**
+ * Copy of openid_authentication
+ */
+function _openid_sso_relying_openid_authentication($response) {
+  module_load_include('inc', 'openid');
+
+  $identity = $response['openid.claimed_id'];
+
+  $account = user_external_load($identity);
+  if (isset($account->uid)) {
+    if (!variable_get('user_email_verification', TRUE) || $account->login) {
+      user_external_login($account, $_SESSION['openid']['user_login_values']);
+    }
+    else {
+      drupal_set_message(t('You must validate your email address for this account before logging in via OpenID'));
+    }
+  }
+  elseif (variable_get('user_register', 1)) {
+    // Register new user
+    $form_state['redirect'] = NULL;
+    $form_state['values']['name'] = (empty($response['openid.sreg.nickname'])) ? '' : $response['openid.sreg.nickname'];
+    $form_state['values']['mail'] = (empty($response['openid.sreg.email'])) ? '' : $response['openid.sreg.email'];
+    $form_state['values']['pass']  = user_password();
+    $form_state['values']['status'] = variable_get('user_register', 1) == 1;
+    $form_state['values']['response'] = $response;
+    $form_state['values']['auth_openid'] = $identity;
+
+    if (empty($response['openid.sreg.email']) && empty($response['openid.sreg.nickname'])) {
+      drupal_set_message(t('Please complete the registration by filling out the form below. If you already have an account, you can <a href="@login">log in</a> now and add your OpenID under "My account".', array('@login' => url('user/login'))), 'warning');
+      $success = FALSE;
+    }
+    else {
+      $form = drupal_retrieve_form('user_register', $form_state);
+      drupal_prepare_form('user_register', $form, $form_state);
+      drupal_validate_form('user_register', $form, $form_state);
+      $success = !form_get_errors();
+      if (!$success) {
+        drupal_set_message(t('Account registration using the information provided by your OpenID provider failed due to the reasons listed below. Please complete the registration by filling out the form below. If you already have an account, you can <a href="@login">log in</a> now and add your OpenID under "My account".', array('@login' => url('user/login'))), 'warning');
+        // Append form validation errors below the above warning.
+        $messages = drupal_get_messages('error');
+        foreach ($messages['error'] as $message) {
+          drupal_set_message( $message, 'error');
+        }
+      }
+    }
+    if (!$success) {
+      // We were unable to register a valid new user, redirect to standard
+      // user/register and prefill with the values we received.
+      $_SESSION['openid']['values'] = $form_state['values'];
+      // We'll want to redirect back to the same place.
+      $destination = drupal_get_destination();
+      unset($_REQUEST['destination']);
+      drupal_goto('user/register', $destination);
+    }
+    else {
+      unset($form_state['values']['response']);
+      $account = user_save('', $form_state['values']);
+      // Terminate if an error occured during user_save().
+      if (!$account) {
+        drupal_set_message(t("Error saving user account."), 'error');
+        drupal_goto();
+      }
+      user_external_login($account);
+    }
+    // Redirect the form to the 'user' path
+    drupal_redirect_form($form, "user");
+  }
+  else {
+    drupal_set_message(t('Only site administrators can create new user accounts.'), 'error');
+  }
+  drupal_goto();
 }
 
 /**
