You are here

function _gauth_gapps_authenticate in Google Auth 6

Login the user into their Google Apps account.

1 call to _gauth_gapps_authenticate()
gauth_user in ./gauth.module
Implementation of hook_user().

File

./gauth.module, line 83

Code

function _gauth_gapps_authenticate($account) {
  module_load_include('inc', 'oauth_common');
  $server = variable_get('gauth_oauth_server', 'https://www.google.com/accounts');
  $hd = variable_get('gauth_hd', '');
  $scopes = variable_get('gauth_scopes', '');

  // Get the configured consumer key and secret.
  $consumer_key = variable_get('gauth_consumer_key', '');
  $consumer_secret = variable_get('gauth_consumer_secret', '');
  if (empty($consumer_key) || empty($consumer_secret)) {
    watchdog('gauth', t('Missing Google Auth consumer key or secret.'));
    return;
  }
  if (variable_get('gauth_two_legged_oauth', FALSE)) {
    if (empty($account->gapps_account_mail)) {
      return;
    }

    // @TODO: remove hard-coding, see how we implement provisioning api first.
    $server = 'http://www.google.com';
    $path = '/m8/feeds/contacts/default/full/';

    // Setup consumer and oauth client.
    $consumer = new DrupalOAuthConsumer($consumer_key, $consumer_secret, NULL);
    $client = new DrupalOAuthClient($server, $consumer, NULL);

    // Get signature method.
    $signature_method = $client
      ->signatureMethod('sha1');
    $params = array(
      'max-results' => 10,
      'xoauth_requestor_id' => $account->gapps_account_mail,
    );
    $response = $client
      ->get($path, FALSE, $params);
    watchdog('gauth', 'response: ' . $response);
  }
  else {

    // Setup consumer and oauth client.
    $consumer = new DrupalOAuthConsumer($consumer_key, $consumer_secret, NULL);
    $client = new DrupalOAuthClient($server, $consumer, NULL);

    // Get signature method.
    $signature_method = $client
      ->signatureMethod('sha1');

    // Get request token.
    $request_params = array();
    $request_params['scope'] = $scopes;
    $request_params['xoauth_displayname'] = variable_get('gauth_app_display_name', '');
    $request_params['oauth_callback'] = base_path() . 'gauth-token';
    $request_token = $client
      ->getRequestToken('/OAuthGetRequestToken', $request_params);
    $token = new stdClass();
    $token->key = $request_token->key;
    $token->secret = $request_token->secret;
    $_SESSION['gauth_request_token'] = $token;

    // Get request token authorized.
    $auth_params = array();
    $auth_params['hd'] = $hd;
    $auth_url = $client
      ->getAuthorizationUrl(NULL, '/OAuthAuthorizeToken', $auth_params);
    drupal_goto($auth_url);
    return;
  }
}