You are here

function feeds_oauth_authenticate in Feeds OAuth 7

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

Menu callback to start authenticating OAuth 1.

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

File

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

Code

function feeds_oauth_authenticate($id) {
  $path = variable_get('feeds_oauth_library_path', FEEDS_OAUTH_LIBRARY_PATH_DEFAULT);
  require_once $path . '/lib/oauth/OAuthClient.php';
  $fetcher = feeds_importer($id)->fetcher;
  $config = $fetcher
    ->getConfig();
  $oauth = new proauth\OAuthCurlClient(new proauth\OAuthConsumer($config['consumer_key'], $config['consumer_secret']), new proauth\OAuthSignatureHMACSHA1(), NULL);
  try {
    $request_token = $oauth
      ->_getTempToken($config['request_token_url'], array(), TRUE, strtoupper($config['method']));
  } catch (Exception $e) {
    drupal_set_message($e
      ->getMessage(), 'error');
    drupal_goto($_SERVER['HTTP_REFERER']);
  }
  $_SESSION['feeds'] = array(
    'request_token' => serialize($request_token),
    'id' => $id,
    'destination' => $_SERVER['HTTP_REFERER'],
  );
  drupal_goto(url($config['authorize_url'], array(
    'absolute' => TRUE,
    'query' => array(
      'oauth_token' => $request_token
        ->getToken(),
      'oauth_verifier' => md5(microtime() . mt_rand()),
    ),
  )));
}