Lcobucci\JWT\Token::isExpired PHP Method

isExpired() public method

Determine if the token is expired.
public isExpired ( DateTimeInterfac\DateTimeInterface $now = null ) : boolean
$now DateTimeInterfac\DateTimeInterface Defaults to the current time.
return boolean
    public function isExpired(DateTimeInterface $now = null)
    {
        if (!$this->hasClaim('exp')) {
            return false;
        }
        $now = $now ?: new DateTime();
        return $now->getTimestamp() > $this->getClaim('exp');
    }

Usage Example

Example #1
0
 /**
  * @test
  *
  * @covers Lcobucci\JWT\Token::isExpired
  *
  * @uses Lcobucci\JWT\Token::__construct
  * @uses Lcobucci\JWT\Token::getClaim
  * @uses Lcobucci\JWT\Token::hasClaim
  * @uses Lcobucci\JWT\Claim\Basic
  * @uses Lcobucci\JWT\Claim\GreaterOrEqualsTo
  */
 public function isExpiredShouldReturnTrueAfterTokenExpires()
 {
     $token = new Token(['alg' => 'none'], ['exp' => new GreaterOrEqualsTo('exp', time())]);
     $this->assertTrue($token->isExpired(new DateTime('+10 days')));
 }