/**
  * Helper function to perform necessary checks on timestamp and nonce.
  *
  * @param $nonce
  * @param $timestamp
  * @param ConsumerInterface $consumer
  * @return bool
  */
 public function checkNonceAndTimestampUnicity($nonce, $timestamp, ConsumerInterface $consumer)
 {
     // Check timestamp: The timestamp value MUST be a positive integer
     // and MUST be equal or greater than the timestamp used in previous requests.
     // @see http://oauth.net/core/1.0/#nonce
     if (!ctype_digit($timestamp)) {
         throw new \InvalidArgumentException('Timestamp should be a positive integer, got ' . $this->checkPlain($timestamp));
     }
     $timestampsKey = $this->timestampsKey($consumer);
     $sortedSet = $this->client->zrevrange($timestampsKey, 0, -1);
     if (is_array($sortedSet) && !empty($sortedSet)) {
         $maxTimestamp = $sortedSet[0];
         if ($timestamp < $maxTimestamp) {
             throw new \InvalidArgumentException('Timestamp must be bigger than your last timestamp we have recorded');
         }
     }
     $noncesRedisKey = $this->noncesRedisKey($consumer, $timestamp);
     $exists = $this->client->sismember($noncesRedisKey, $nonce);
     return !$exists;
 }
Ejemplo n.º 2
0
 /**
  * {@inheritDoc}
  */
 public function sismember($key, $member)
 {
     return $this->predis->sismember($key, $member);
 }