/** * @param Jwt $jwt * @return bool */ public function validateRequiredClaims(Jwt $jwt) { foreach ($this->requiredClaims as $claim) { if (!$jwt->hasClaim($claim)) { return false; } } return true; }
/** * Get the number of minutes until the token expiry. * * @param \Lcobucci\JWT\Token $token * * @return int */ protected function getMinutesUntilExpired(Token $token) { $exp = Carbon::createFromTimestamp($token->getClaim('exp')); $iat = Carbon::createFromTimestamp($token->hasClaim('iat') ? $token->getClaim('iat') : 0); // get the latter of the two expiration dates and find // the number of minutes until the expiration date, // plus 1 minute to avoid overlap return $exp->max($iat->addMinutes($this->refreshTTL))->addMinute()->diffInMinutes(); }
/** * @test * * @uses Lcobucci\JWT\Token::__construct * @uses Lcobucci\JWT\Claim\Basic * * @covers Lcobucci\JWT\Token::hasClaim */ public function hasClaimMustReturnFalseWhenItIsNotConfigured() { $token = new Token([], ['test' => new Basic('test', 'testing')]); $this->assertFalse($token->hasClaim('testing')); }
/** * {@inheritDoc} */ private function shouldTokenBeRefreshed(Token $token) : bool { if (!$token->hasClaim(self::ISSUED_AT_CLAIM)) { return false; } return $this->timestamp() >= $token->getClaim(self::ISSUED_AT_CLAIM) + $this->refreshTime; }