[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/vendor/lcobucci/jwt/src/Validation/Constraint/ -> SignedWith.php (source)

   1  <?php
   2  
   3  namespace Lcobucci\JWT\Validation\Constraint;
   4  
   5  use Lcobucci\JWT\Signer;
   6  use Lcobucci\JWT\Token;
   7  use Lcobucci\JWT\Validation\Constraint;
   8  use Lcobucci\JWT\Validation\ConstraintViolation;
   9  
  10  final class SignedWith implements Constraint
  11  {
  12      /** @var Signer */
  13      private $signer;
  14  
  15      /** @var Signer\Key */
  16      private $key;
  17  
  18      public function __construct(Signer $signer, Signer\Key $key)
  19      {
  20          $this->signer = $signer;
  21          $this->key    = $key;
  22      }
  23  
  24      public function assert(Token $token)
  25      {
  26          if ($token->headers()->get('alg') !== $this->signer->getAlgorithmId()) {
  27              throw new ConstraintViolation('Token signer mismatch');
  28          }
  29  
  30          if (! $this->signer->verify((string) $token->signature(), $token->getPayload(), $this->key)) {
  31              throw new ConstraintViolation('Token signature mismatch');
  32          }
  33      }
  34  }


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer