/**
  * @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');
     }
 }
 /**
  * @param \Exception $exception
  * @param JwtContext $context
  * @return void
  */
 public function handle(\Exception $exception, JwtContext $context)
 {
     $requestJwt = $context->getRequestJwt();
     if (!$requestJwt || $requestJwt->getDirection() == Directions::RESPONSE) {
         return;
     }
     $responseJwt = MethodJwt::create(Directions::RESPONSE, $context->getMyIssuerId(), $requestJwt->getMethod(), $requestJwt->getInstance(), null, $requestJwt->getJwtId());
     $responseJwt->setException($exception->getMessage());
     $context->setResponseJwt($responseJwt);
 }
 /**
  * @param JwtContext $context
  * @throws \BWC\Component\JwtApiBundle\Error\JwtException
  */
 public function handleContext(JwtContext $context)
 {
     if (!$context->getRequestJwt()) {
         throw new JwtException('Missing request jwt to filter by');
     }
     foreach ($this->filter as $claim => $value) {
         if ($context->getRequestJwt()->get($claim) != $value) {
             return;
         }
     }
     parent::handleContext($context);
 }
 /**
  * @param JwtContext $context
  * @throws \BWC\Component\JwtApiBundle\Error\JwtException
  */
 public function handleContext(JwtContext $context)
 {
     $token = $context->getRequestJwtToken();
     if ($this->logger) {
         $this->logger->debug('DecoderHandler.token', array('token' => $token));
     }
     /** @var MethodJwt $jwt */
     $jwt = $this->encoder->decode($token, $this->class);
     if ($this->logger) {
         $this->logger->debug('DecoderHandler.jwt', array('jwt' => $jwt));
     }
     if (false == $jwt instanceof MethodJwt) {
         throw new JwtException(sprintf("Expected MethodJwt but got '%s'", get_class($jwt)));
     }
     $context->setRequestJwt($jwt);
 }
 /**
  * @param JwtContext $context
  */
 public function handleContext(JwtContext $context)
 {
     if ($context->getResponseJwt()) {
         $keys = $context->optionGet(ContextOptions::KEYS);
         if ($this->logger) {
             $this->logger->debug('EncoderHandler.keys', array('keys' => $keys));
         }
         if (is_array($keys)) {
             $token = $this->encoder->encode($context->getResponseJwt(), array_shift($keys));
             if ($this->logger) {
                 $this->logger->debug('EncoderHandler.token', array('token' => $token));
             }
             $context->setResponseToken($token);
         }
     } else {
         if ($this->logger) {
             $this->logger->debug('EncoderHandler.noResponseJwt');
         }
     }
 }
 /**
  * @param JwtContext $context
  * @throws \BWC\Component\JwtApiBundle\Error\JwtException
  */
 public function handleContext(JwtContext $context)
 {
     if ($context->getResponseJwt() || $context->optionGet(ContextOptions::HANDLED)) {
         return;
     }
     if ($this->logger) {
         $this->logger->debug('UnhandledContextHandler', array('context' => $context));
     }
     $message = sprintf("Unhandled request for direction '%s' method '%s' of issuer '%s'", $context->getRequestJwt()->getDirection(), $context->getRequestJwt()->getMethod(), $context->getRequestJwt()->getIssuer());
     $requestJwt = $context->getRequestJwt();
     if ($requestJwt->getDirection() == Directions::RESPONSE) {
         throw new JwtException($message);
     }
     $responseJwt = MethodJwt::create(Directions::RESPONSE, $context->getMyIssuerId(), $requestJwt->getMethod(), $requestJwt->getInstance(), null, $requestJwt->getJwtId());
     $responseJwt->setException($message);
     $context->setResponseJwt($responseJwt);
 }
 /**
  * @param \BWC\Component\JwtApiBundle\Context\JwtContext $context
  * @throws \Exception
  */
 public function validate(JwtContext $context)
 {
     $jwt = $context->getRequestJwt();
     if (false == $jwt instanceof Jose) {
         throw new JwtException('Expected jose to validate signature');
     }
     $keys = $context->optionGet(ContextOptions::KEYS);
     if (false == is_array($keys)) {
         throw new JwtException('Expected array of keys');
     }
     $exception = null;
     foreach ($keys as $key) {
         try {
             $this->encoder->verify($jwt, $key);
             $exception = null;
             break;
         } catch (\Exception $ex) {
             $exception = $ex;
         }
     }
     if ($exception) {
         throw $exception;
     }
 }
Exemple #8
0
 /**
  * @param JwtContext $context
  * @return string
  * @throws JwtException
  */
 protected function getReplyUrl(JwtContext $context)
 {
     $url = $context->getDestinationUrl();
     if (!$url && ($methodJwt = $context->getRequestJwt())) {
         $url = $methodJwt->getReplyTo();
     }
     if (!$url) {
         throw new JwtException('Missing destination url');
     }
     return $url;
 }
 /**
  * @test
  */
 public function shouldGetSubject()
 {
     $context = new JwtContext(new Request(), JwtBindingTypes::HTTP_REDIRECT, null);
     $context->setSubject($expectedSubject = 'subject');
     $this->assertEquals($expectedSubject, $context->getSubject());
 }
 /**
  * @param JwtContext $context
  * @return mixed|null
  */
 public function getSubject(JwtContext $context)
 {
     return $context->getBearer();
 }
Exemple #11
0
 /**
  * @param \Exception $exception
  * @param JwtContext $context
  * @return void
  */
 public function handle(\Exception $exception, JwtContext $context)
 {
     $this->logger->error('BWC.JwtApi', array('exception' => (string) $exception, 'jwtContext' => $context->jsonSerialize()));
 }