You are here

function feeds_oauth_get_tokens in Feeds OAuth 7

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

Get tokens from database.

1 string reference to 'feeds_oauth_get_tokens'
OAuthHTTPFetcher::configDefaults in ./OAuthHTTPFetcher.inc
Declare defaults.

File

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

Code

function feeds_oauth_get_tokens($uid, $site_id, $id) {
  $token = db_query("SELECT * FROM {feeds_oauth_access_tokens} WHERE uid = :uid AND site_id = :site_id", array(
    ':uid' => $uid,
    ':site_id' => $site_id,
  ))
    ->fetchAssoc();
  if ($token['expires'] && time() > $token['expires']) {

    // Remove the expired key.
    db_delete('feeds_oauth_access_tokens')
      ->condition('uid', $uid)
      ->condition('site_id', $site_id)
      ->execute();
    if (!empty($token['oauth_refresh_token'])) {

      // This is OAuth 2.0 and we have a refresh token!
      $token = feeds_oauth_refresh2($token['oauth_refresh_token'], $uid, $id);
    }
    else {

      // Just clear it out -- the user will have to authenticate again.
      $token = NULL;
    }
  }
  return $token;
}