You are here

public function OAuthStorePostgreSQL::checkServerNonce in Lingotek Translation 7.6

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

Check an nonce/timestamp combination. Clears any nonce combinations that are older than the one received.

@exception OAuthException2 thrown when the timestamp is not in sequence or nonce is not unique

Parameters

string consumer_key:

string token:

int timestamp:

string nonce:

Overrides OAuthStoreAbstract::checkServerNonce

File

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

Class

OAuthStorePostgreSQL

Code

public function checkServerNonce($consumer_key, $token, $timestamp, $nonce) {
  $r = $this
    ->query_row('
                            SELECT MAX(osn_timestamp), MAX(osn_timestamp) > %d + %d
                            FROM oauth_server_nonce
                            WHERE osn_consumer_key = \'%s\'
                              AND osn_token        = \'%s\'
                            ', $timestamp, $this->max_timestamp_skew, $consumer_key, $token);
  if (!empty($r) && $r[1] === 't') {
    throw new OAuthException2('Timestamp is out of sequence. Request rejected. Got ' . $timestamp . ' last max is ' . $r[0] . ' allowed skew is ' . $this->max_timestamp_skew);
  }

  // Insert the new combination
  $this
    ->query('
            INSERT INTO oauth_server_nonce (
                osn_consumer_key,
                osn_token,
                osn_timestamp,
                osn_nonce
            )
            VALUES (\'%s\', \'%s\', %d, \'%s\')', $consumer_key, $token, $timestamp, $nonce);
  if ($this
    ->query_affected_rows() == 0) {
    throw new OAuthException2('Duplicate timestamp/nonce combination, possible replay attack.  Request rejected.');
  }

  // Clean up all timestamps older than the one we just received
  $this
    ->query('
                DELETE FROM oauth_server_nonce
                WHERE osn_consumer_key    = \'%s\'
                  AND osn_token            = \'%s\'
                  AND osn_timestamp     < %d - %d
                ', $consumer_key, $token, $timestamp, $this->max_timestamp_skew);
}