示例#1
0
 /**
  * @test
  */
 public function checkReturnsFalseWhenKeyIsExpired()
 {
     $key = new ApiKey();
     $key->setExpirationDate((new \DateTime())->sub(new \DateInterval('P1D')));
     $repo = $this->prophesize(EntityRepository::class);
     $repo->findOneBy(['key' => '12345'])->willReturn($key)->shouldBeCalledTimes(1);
     $this->em->getRepository(ApiKey::class)->willReturn($repo->reveal());
     $this->assertFalse($this->service->check('12345'));
 }
示例#2
0
 /**
  * Creates a new ApiKey with provided expiration date
  *
  * @param \DateTime $expirationDate
  * @return ApiKey
  */
 public function create(\DateTime $expirationDate = null)
 {
     $key = new ApiKey();
     if (isset($expirationDate)) {
         $key->setExpirationDate($expirationDate);
     }
     $this->em->persist($key);
     $this->em->flush();
     return $key;
 }
示例#3
0
 /**
  * @param ApiKey $apiKey
  * @return string
  */
 protected function getEnabledSymbol(ApiKey $apiKey)
 {
     return !$apiKey->isEnabled() || $apiKey->isExpired() ? '---' : '+++';
 }
示例#4
0
 /**
  * Creates a new JSON web token por provided API key
  *
  * @param ApiKey $apiKey
  * @param int $lifetime
  * @return string
  */
 public function create(ApiKey $apiKey, $lifetime = self::DEFAULT_LIFETIME)
 {
     $currentTimestamp = time();
     return $this->encode(['iss' => $this->appOptions->__toString(), 'iat' => $currentTimestamp, 'exp' => $currentTimestamp + $lifetime, 'sub' => 'auth', 'key' => $apiKey->getId()]);
 }