/**
  * Test invalidate Token by criteria
  *
  * @depends testValidTokenGenerationWithBasicFields
  *
  * @param Token $generatedToken Previously generated Token
  */
 public function testInvalidatePass(Token $generatedToken)
 {
     $this->assertTrue($generatedToken->isActive(), 'Expected active Token was inactive');
     $this->tokenService->invalidate($generatedToken->getHash(), $generatedToken->getScope(), $generatedToken->getOwnerType(), $generatedToken->getOwnerId());
     $retrievedToken = $this->tokenService->get($generatedToken->getHash(), $generatedToken->getScope(), $generatedToken->getOwnerType(), $generatedToken->getOwnerId());
     $this->assertFalse($retrievedToken->isActive(), 'Token was not invalidated');
 }
Beispiel #2
0
 /**
  * Check if the token can be used
  *
  * @param Token|null $token
  *
  * @return boolean
  */
 public function isValid(Token $token = null)
 {
     if (!$token instanceof Token) {
         return false;
     }
     $currentTime = new \DateTime();
     $expiryTime = $token->getExpiresAt();
     return $token->isActive() && $token->getUsesCount() < $token->getUsesMax() && (!$expiryTime instanceof \DateTime || $expiryTime->getTimestamp() >= $currentTime->getTimestamp());
 }