Emarref\Jwt\Verification\NotBeforeVerifier::verify PHP Метод

verify() публичный Метод

public verify ( Token $token )
$token Emarref\Jwt\Token
    public function verify(Token $token)
    {
        /** @var Claim\NotBefore $notBeforeClaim */
        $notBeforeClaim = $token->getPayload()->findClaimByName(Claim\NotBefore::NAME);
        if (null === $notBeforeClaim) {
            return null;
        }
        $now = new \DateTime('now', new \DateTimeZone('UTC'));
        if (!is_long($notBeforeClaim->getValue())) {
            throw new \InvalidArgumentException(sprintf('Invalid not before timestamp "%s"', $notBeforeClaim->getValue()));
        }
        if ($now->getTimestamp() < $notBeforeClaim->getValue()) {
            $notBefore = new \DateTime();
            $notBefore->setTimestamp($notBeforeClaim->getValue());
            throw new TooEarlyException($notBefore);
        }
    }

Usage Example

 public function testValid()
 {
     $past = new \DateTime('5 minutes ago', new \DateTimeZone('UTC'));
     $notBeforeClaim = $this->getMockBuilder('Emarref\\Jwt\\Claim\\NotBefore')->getMock();
     $notBeforeClaim->expects($this->exactly(2))->method('getValue')->will($this->returnValue($past->getTimestamp()));
     $this->payload->expects($this->once())->method('findClaimByName')->with(NotBefore::NAME)->will($this->returnValue($notBeforeClaim));
     $this->verifier->verify($this->token);
 }
NotBeforeVerifier