You are here

function gauth_access_token in Google Auth 6

Exchange the authorized request token for an access token.

1 string reference to 'gauth_access_token'
gauth_menu in ./gauth.module
Implementation of hook_menu().

File

./gauth.module, line 150

Code

function gauth_access_token() {
  $consumer_key = variable_get('gauth_consumer_key', '');
  $consumer_secret = variable_get('gauth_consumer_secret', '');
  $server = variable_get('gauth_oauth_server', 'https://www.google.com/accounts');
  $oauth_verifier = urldecode($_GET['oauth_verifier']);
  $oauth_token = urldecode($_GET['oauth_token']);
  if (empty($oauth_verifier) || empty($oauth_token)) {
    drupal_goto('/');
    return;
  }

  // Setup consumer and oauth client.
  $consumer = new DrupalOAuthConsumer($consumer_key, $consumer_secret, NULL);
  $token = $_SESSION['gauth_request_token'];
  $request_token = new OAuthToken($token->key, $token->secret);
  $client = new DrupalOAuthClient($server, $consumer, $request_token);

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

  // Exchange the authorized request token for an access token.
  $params = array();
  $params['oauth_verifier'] = $oauth_verifier;
  $params['oauth_token'] = $oauth_token;
  $access = $client
    ->getAccessToken('/OAuthGetAccessToken', $params);
  drupal_goto();
}