You are here

function feeds_oauth2_callback in Feeds OAuth 6

1 string reference to 'feeds_oauth2_callback'
feeds_oauth_menu in ./feeds_oauth.module
Implementation of hook_menu().

File

./feeds_oauth.module, line 109

Code

function feeds_oauth2_callback($site_id, $id) {
  require_once drupal_get_path('module', 'feeds_oauth') . '/php-proauth-read-only/lib/oauth/OAuth2Client.php';
  $fetcher = feeds_importer($id)->fetcher;
  $config = $fetcher
    ->getConfig();
  $oauth = new OAuth2CurlClient();
  $oauth
    ->setEndpoints($config['authorize_url'], $config['access_token_url']);
  $oauth
    ->setClientId($config['consumer_key'], $config['consumer_secret']);
  $obt = $oauth
    ->getAccessTokenObtainer('web_server');
  $obt
    ->setRedirectUrl(url("feeds/oauth2/callback/{$config['site_id']}/{$id}", array(
    'absolute' => TRUE,
  )));
  if ($obt
    ->webServerDidUserAuthorize()) {
    global $user;
    db_query("DELETE FROM {feeds_oauth_access_tokens} WHERE uid = %d AND site_id = '%s'", $user->uid, db_escape_string($site_id));
    db_query("INSERT INTO {feeds_oauth_access_tokens} (uid, site_id, oauth_token, oauth_token_secret) VALUES(%d, '%s', '%s', '%s')", $user->uid, db_escape_string($site_id), $oauth
      ->getAccessToken()
      ->getToken(), 'dummy');
  }
  else {

    // TODO:  Handle failure.
  }
  drupal_goto('import/' . $id);
}