You are here

function _hybridauth_window_auth in HybridAuth Social Login 7.2

Same name and namespace in other branches
  1. 6.2 hybridauth.pages.inc \_hybridauth_window_auth()
1 call to _hybridauth_window_auth()
hybridauth_window_start in ./hybridauth.pages.inc

File

./hybridauth.pages.inc, line 145
HybridAuth module pages.

Code

function _hybridauth_window_auth($hybridauth, $provider_id) {
  $error_code = NULL;
  if (is_object($hybridauth)) {
    $params = array(
      'hauth_return_to' => url('hybridauth/window/' . $provider_id, array(
        'absolute' => TRUE,
        'query' => drupal_get_query_parameters(),
      )),
    );
    if (isset($_GET['openid_identifier'])) {
      $params['openid_identifier'] = $_GET['openid_identifier'];
    }
    try {
      $adapter = $hybridauth
        ->authenticate($provider_id, $params);
      $profile = (array) $adapter
        ->getUserProfile();
    } catch (Exception $e) {
      watchdog_exception('hybridauth', $e);
      $error_code = $e
        ->getCode();
    }
  }
  else {
    $error_code = $hybridauth;
  }
  if (!is_null($error_code)) {

    // Destroy the session started in hybridauth_window_start() if user is not
    // logged in.
    if (!user_is_logged_in()) {

      // Delete session only if it contains just HybridAuth data.
      $delete_session = TRUE;
      foreach ($_SESSION as $key => $value) {
        if (substr($key, 0, 4) != 'HA::') {
          $delete_session = FALSE;
        }
      }
      if ($delete_session) {
        session_destroy();
      }
    }
    switch ($error_code) {
      case 5:

        // Authentication failed. The user has canceled the authentication or
        // the provider refused the connection.
        break;
      case 0:

      // Unspecified error.
      case 1:

      // Hybridauth configuration error.
      case 2:

      // Provider not properly configured.
      case 3:

      // Unknown or disabled provider.
      case 4:

      // Missing provider application credentials (your application id, key
      // or secret).
      case 6:

      // User profile request failed.
      case 7:

      // User not connected to the provider.
      case 8:

      // Provider does not support this feature.
      default:

        // Report the error - this message is not shown to anonymous users as
        // we destroy the session - see below.
        drupal_set_message(t('There was an error processing your request.'), 'error');
    }
    _hybridauth_window_close(FALSE);
  }
  $profile['provider'] = $provider_id;

  // Invoke hook_hybridauth_profile_alter().
  drupal_alter('hybridauth_profile', $profile);

  // Process Drupal authentication.
  return _hybridauth_window_process_auth($profile);
}