You are here

function feeds_oauth_callback in Feeds OAuth 7

Same name and namespace in other branches
  1. 6 feeds_oauth.module \feeds_oauth_callback()

Menu callback to complete authenticating OAuth 1.

1 string reference to 'feeds_oauth_callback'
feeds_oauth_menu in ./feeds_oauth.module
Implements hook_menu().

File

./feeds_oauth.module, line 167
The module file.

Code

function feeds_oauth_callback($site_id) {
  $path = variable_get('feeds_oauth_library_path', FEEDS_OAUTH_LIBRARY_PATH_DEFAULT);
  require_once $path . '/lib/oauth/OAuthClient.php';
  $fetcher = feeds_importer($_SESSION['feeds']['id'])->fetcher;
  $config = $fetcher
    ->getConfig();
  $request_token = unserialize($_SESSION['feeds']['request_token']);
  $destination = $_SESSION['feeds']['destination'];
  unset($_SESSION['feeds']);
  $oauth = new proauth\OAuthCurlClient(new proauth\OAuthConsumer($config['consumer_key'], $config['consumer_secret']), new proauth\OAuthSignatureHMACSHA1(), $request_token);
  if (empty($_GET['oauth_token']) || empty($_GET['oauth_verifier']) || $_GET['oauth_token'] != $request_token
    ->getToken()) {
    drupal_set_message(t('Invalid OAuth token.'), 'error');
    drupal_goto($destination);
  }
  try {
    $access_token = $oauth
      ->_getAccessToken($config['access_token_url'], array(
      'oauth_verifier' => $_GET['oauth_verifier'],
    ), NULL, TRUE);
  } catch (Exception $e) {
    drupal_set_message($e
      ->getMessage(), 'error');
    drupal_goto($destination);
  }
  global $user;
  _feeds_oauth_store_token(array(
    'access_token' => $access_token
      ->getToken(),
    'access_token_secret' => $access_token
      ->getSecret(),
  ), $user->uid, $site_id);
  drupal_goto($destination);
}