/**
  * @param \BWC\Component\JwtApiBundle\Context\JwtContext $context
  * @throws \BWC\Component\JwtApiBundle\Error\JwtException
  */
 public function validate(JwtContext $context)
 {
     $delta = abs(DateTime::now() - $context->getRequestJwt()->getIssuedAt());
     if ($delta > $this->maxIssuedTimeDifference) {
         throw new JwtException('Token too old');
     }
 }
示例#2
0
 /**
  * @param string $direction
  * @param string $issuer
  * @param string $method
  * @param string|null $instance
  * @param mixed $data
  * @param string|null $inResponseTo
  * @throws \InvalidArgumentException
  * @return MethodJwt
  */
 public static function create($direction, $issuer, $method, $instance = null, $data = null, $inResponseTo = null)
 {
     if (!Directions::isValid($direction)) {
         throw new \InvalidArgumentException(sprintf("Invalid direction value '%s'", $direction));
     }
     $payload = array(JwtClaim::ISSUER => $issuer, JwtClaim::ISSUED_AT => DateTime::now(), JwtClaim::TYPE => self::PAYLOAD_TYPE, MethodClaims::DIRECTION => $direction, MethodClaims::METHOD => $method);
     if ($instance) {
         $payload[MethodClaims::INSTANCE] = $instance;
     }
     if ($data) {
         $payload[MethodClaims::DATA] = $data;
     }
     if ($inResponseTo) {
         $payload[MethodClaims::IN_RESPONSE_TO] = $inResponseTo;
     }
     $result = new MethodJwt(array(), $payload);
     return $result;
 }
示例#3
0
 /**
  * @param int|null $limit
  * @return int
  */
 public function deleteExpired($limit = null)
 {
     return $this->configManager->deleteExpired(DateTime::now(), $limit);
 }