You are here

public function OAuthStorePostgreSQL::addConsumerRequestToken in Lingotek Translation 7.7

Same name and namespace in other branches
  1. 7.2 lib/oauth-php/library/store/OAuthStorePostgreSQL.php \OAuthStorePostgreSQL::addConsumerRequestToken()
  2. 7.3 lib/oauth-php/library/store/OAuthStorePostgreSQL.php \OAuthStorePostgreSQL::addConsumerRequestToken()
  3. 7.4 lib/oauth-php/library/store/OAuthStorePostgreSQL.php \OAuthStorePostgreSQL::addConsumerRequestToken()
  4. 7.5 lib/oauth-php/library/store/OAuthStorePostgreSQL.php \OAuthStorePostgreSQL::addConsumerRequestToken()
  5. 7.6 lib/oauth-php/library/store/OAuthStorePostgreSQL.php \OAuthStorePostgreSQL::addConsumerRequestToken()

Add an unautorized request token to our server.

Parameters

string consumer_key:

array options (eg. token_ttl):

Return value

array (token, token_secret)

Overrides OAuthStoreAbstract::addConsumerRequestToken

File

lib/oauth-php/library/store/OAuthStorePostgreSQL.php, line 1202

Class

OAuthStorePostgreSQL

Code

public function addConsumerRequestToken($consumer_key, $options = array()) {
  $token = $this
    ->generateKey(true);
  $secret = $this
    ->generateKey();
  $osr_id = $this
    ->query_one('
                        SELECT osr_id
                        FROM oauth_server_registry
                        WHERE osr_consumer_key = \'%s\'
                          AND osr_enabled      = \'1\'
                        ', $consumer_key);
  if (!$osr_id) {
    throw new OAuthException2('No server with consumer_key "' . $consumer_key . '" or consumer_key is disabled');
  }
  if (isset($options['token_ttl']) && is_numeric($options['token_ttl'])) {
    $ttl = intval($options['token_ttl']);
  }
  else {
    $ttl = $this->max_request_token_ttl;
  }
  if (!isset($options['oauth_callback'])) {

    // 1.0a Compatibility : store callback url associated with request token
    $options['oauth_callback'] = 'oob';
  }
  $this
    ->query('
            INSERT INTO oauth_server_token (
                ost_osr_id_ref,
                ost_usa_id_ref,
                ost_token,
                ost_token_secret,
                ost_token_type,
                ost_token_ttl,
                ost_callback_url
            )
            VALUES (%d, \'1\', \'%s\', \'%s\', \'request\', NOW() + INTERVAL \'%d SECOND\', \'%s\')', $osr_id, $token, $secret, $ttl, $options['oauth_callback']);
  return array(
    'token' => $token,
    'token_secret' => $secret,
    'token_ttl' => $ttl,
  );
}