You are here

public function OAuthStoreSQL::addConsumerRequestToken in Lingotek Translation 7.6

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

* Add an unautorized request token to our server. * *

Parameters

string consumer_key: * @param array options (eg. token_ttl) * @return array (token, token_secret)

Overrides OAuthStoreAbstract::addConsumerRequestToken

File

lib/oauth-php/library/store/OAuthStoreSQL.php, line 1192

Class

OAuthStoreSQL

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
				SET ost_osr_id_ref		= %d,
					ost_usa_id_ref		= 1,
					ost_token			= \'%s\',
					ost_token_secret	= \'%s\',
					ost_token_type		= \'request\',
					ost_token_ttl       = DATE_ADD(NOW(), INTERVAL %d SECOND),
					ost_callback_url    = \'%s\'
				ON DUPLICATE KEY UPDATE
					ost_osr_id_ref		= VALUES(ost_osr_id_ref),
					ost_usa_id_ref		= VALUES(ost_usa_id_ref),
					ost_token			= VALUES(ost_token),
					ost_token_secret	= VALUES(ost_token_secret),
					ost_token_type		= VALUES(ost_token_type),
					ost_token_ttl       = VALUES(ost_token_ttl),
					ost_callback_url    = VALUES(ost_callback_url),
					ost_timestamp		= NOW()
				', $osr_id, $token, $secret, $ttl, $options['oauth_callback']);
  return array(
    'token' => $token,
    'token_secret' => $secret,
    'token_ttl' => $ttl,
  );
}