File manager - Edit - /home/opticamezl/www/newok/Validation.tar
Back
Constraint.php 0000644 00000000256 15173637421 0007415 0 ustar 00 <?php namespace Lcobucci\JWT\Validation; use Lcobucci\JWT\Token; interface Constraint { /** @throws ConstraintViolation */ public function assert(Token $token); } RequiredConstraintsViolated.php 0000644 00000002366 15173637421 0012775 0 ustar 00 <?php namespace Lcobucci\JWT\Validation; use Lcobucci\JWT\Exception; use RuntimeException; use function array_map; use function implode; final class RequiredConstraintsViolated extends RuntimeException implements Exception { /** @var ConstraintViolation[] */ private $violations = []; /** * @param ConstraintViolation ...$violations * @return self */ public static function fromViolations(ConstraintViolation ...$violations) { $exception = new self(self::buildMessage($violations)); $exception->violations = $violations; return $exception; } /** * @param ConstraintViolation[] $violations * * @return string */ private static function buildMessage(array $violations) { $violations = array_map( static function (ConstraintViolation $violation) { return '- ' . $violation->getMessage(); }, $violations ); $message = "The token violates some mandatory constraints, details:\n"; $message .= implode("\n", $violations); return $message; } /** @return ConstraintViolation[] */ public function violations() { return $this->violations; } } Constraint/ValidAt.php 0000644 00000003620 15173637421 0010737 0 ustar 00 <?php namespace Lcobucci\JWT\Validation\Constraint; use DateInterval; use DateTimeInterface; use Lcobucci\Clock\Clock; use Lcobucci\JWT\Token; use Lcobucci\JWT\Validation\Constraint; use Lcobucci\JWT\Validation\ConstraintViolation; final class ValidAt implements Constraint { /** @var Clock */ private $clock; /** @var DateInterval */ private $leeway; public function __construct(Clock $clock, DateInterval $leeway = null) { $this->clock = $clock; $this->leeway = $this->guardLeeway($leeway); } /** @return DateInterval */ private function guardLeeway(DateInterval $leeway = null) { if ($leeway === null) { return new DateInterval('PT0S'); } if ($leeway->invert === 1) { throw LeewayCannotBeNegative::create(); } return $leeway; } public function assert(Token $token) { $now = $this->clock->now(); $this->assertIssueTime($token, $now->add($this->leeway)); $this->assertMinimumTime($token, $now->add($this->leeway)); $this->assertExpiration($token, $now->sub($this->leeway)); } /** @throws ConstraintViolation */ private function assertExpiration(Token $token, DateTimeInterface $now) { if ($token->isExpired($now)) { throw new ConstraintViolation('The token is expired'); } } /** @throws ConstraintViolation */ private function assertMinimumTime(Token $token, DateTimeInterface $now) { if (! $token->isMinimumTimeBefore($now)) { throw new ConstraintViolation('The token cannot be used yet'); } } /** @throws ConstraintViolation */ private function assertIssueTime(Token $token, DateTimeInterface $now) { if (! $token->hasBeenIssuedBefore($now)) { throw new ConstraintViolation('The token was issued in the future'); } } } Constraint/RelatedTo.php 0000644 00000001121 15173637421 0011270 0 ustar 00 <?php namespace Lcobucci\JWT\Validation\Constraint; use Lcobucci\JWT\Token; use Lcobucci\JWT\Validation\Constraint; use Lcobucci\JWT\Validation\ConstraintViolation; final class RelatedTo implements Constraint { /** @var string */ private $subject; public function __construct($subject) { $this->subject = $subject; } public function assert(Token $token) { if (! $token->isRelatedTo($this->subject)) { throw new ConstraintViolation( 'The token is not related to the expected subject' ); } } } Constraint/SignedWith.php 0000644 00000001547 15173637421 0011466 0 ustar 00 <?php namespace Lcobucci\JWT\Validation\Constraint; use Lcobucci\JWT\Signer; use Lcobucci\JWT\Token; use Lcobucci\JWT\Validation\Constraint; use Lcobucci\JWT\Validation\ConstraintViolation; final class SignedWith implements Constraint { /** @var Signer */ private $signer; /** @var Signer\Key */ private $key; public function __construct(Signer $signer, Signer\Key $key) { $this->signer = $signer; $this->key = $key; } public function assert(Token $token) { if ($token->headers()->get('alg') !== $this->signer->getAlgorithmId()) { throw new ConstraintViolation('Token signer mismatch'); } if (! $this->signer->verify((string) $token->signature(), $token->getPayload(), $this->key)) { throw new ConstraintViolation('Token signature mismatch'); } } } Constraint/PermittedFor.php 0000644 00000001141 15173637421 0012013 0 ustar 00 <?php namespace Lcobucci\JWT\Validation\Constraint; use Lcobucci\JWT\Token; use Lcobucci\JWT\Validation\Constraint; use Lcobucci\JWT\Validation\ConstraintViolation; final class PermittedFor implements Constraint { /** @var string */ private $audience; public function __construct($audience) { $this->audience = $audience; } public function assert(Token $token) { if (! $token->isPermittedFor($this->audience)) { throw new ConstraintViolation( 'The token is not allowed to be used by this audience' ); } } } Constraint/IssuedBy.php 0000644 00000001201 15173637421 0011133 0 ustar 00 <?php namespace Lcobucci\JWT\Validation\Constraint; use Lcobucci\JWT\Token; use Lcobucci\JWT\Validation\Constraint; use Lcobucci\JWT\Validation\ConstraintViolation; final class IssuedBy implements Constraint { /** @var string[] */ private $issuers; /** @param list<string> $issuers */ public function __construct(...$issuers) { $this->issuers = $issuers; } public function assert(Token $token) { if (! $token->hasBeenIssuedBy(...$this->issuers)) { throw new ConstraintViolation( 'The token was not issued by the given issuers' ); } } } Constraint/LeewayCannotBeNegative.php 0000644 00000000514 15173637421 0013735 0 ustar 00 <?php namespace Lcobucci\JWT\Validation\Constraint; use InvalidArgumentException; use Lcobucci\JWT\Exception; final class LeewayCannotBeNegative extends InvalidArgumentException implements Exception { /** @return self */ public static function create() { return new self('Leeway cannot be negative'); } } Constraint/IdentifiedBy.php 0000644 00000001133 15173637421 0011747 0 ustar 00 <?php namespace Lcobucci\JWT\Validation\Constraint; use Lcobucci\JWT\Token; use Lcobucci\JWT\Validation\Constraint; use Lcobucci\JWT\Validation\ConstraintViolation; final class IdentifiedBy implements Constraint { /** @var string */ private $id; /** @param string $id */ public function __construct($id) { $this->id = $id; } public function assert(Token $token) { if (! $token->isIdentifiedBy($this->id)) { throw new ConstraintViolation( 'The token is not identified with the expected ID' ); } } } ConstraintViolation.php 0000644 00000000260 15173637421 0011275 0 ustar 00 <?php namespace Lcobucci\JWT\Validation; use Lcobucci\JWT\Exception; use RuntimeException; final class ConstraintViolation extends RuntimeException implements Exception { } Validator.php 0000644 00000002502 15173637421 0007212 0 ustar 00 <?php namespace Lcobucci\JWT\Validation; use Lcobucci\JWT\Token; final class Validator implements \Lcobucci\JWT\Validator { public function assert(Token $token, Constraint ...$constraints) { if ($constraints === []) { throw new NoConstraintsGiven('No constraint given.'); } $violations = []; foreach ($constraints as $constraint) { $this->checkConstraint($constraint, $token, $violations); } if ($violations) { throw RequiredConstraintsViolated::fromViolations(...$violations); } } /** @param ConstraintViolation[] $violations */ private function checkConstraint( Constraint $constraint, Token $token, array &$violations ) { try { $constraint->assert($token); } catch (ConstraintViolation $e) { $violations[] = $e; } } public function validate(Token $token, Constraint ...$constraints) { if ($constraints === []) { throw new NoConstraintsGiven('No constraint given.'); } try { foreach ($constraints as $constraint) { $constraint->assert($token); } return true; } catch (ConstraintViolation $e) { return false; } } } NoConstraintsGiven.php 0000644 00000000257 15173637421 0011067 0 ustar 00 <?php namespace Lcobucci\JWT\Validation; use Lcobucci\JWT\Exception; use RuntimeException; final class NoConstraintsGiven extends RuntimeException implements Exception { }
| ver. 1.4 |
Github
|
.
| PHP 8.3.23 | Generation time: 0 |
proxy
|
phpinfo
|
Settings