Пример #1
0
 /**
  * @covers ::expireFactor
  * @dataProvider factors
  */
 public function testExpireFactor(Factors\Factor $f)
 {
     $u = $this->getUser(['i' => true, 'k' => true, 'p' => true]);
     $u->getRequiredAuthenticationFactors()->willReturn([$f->getType()]);
     $a = new Auth();
     $a->setUser($u->reveal())->validateFactor($f)->getUser();
     // Watch for an exception as a sanity check
     $this->setExpectedException('Firehed\\Auth\\Exceptions\\AuthenticationRequiredException');
     $a->expireFactor($f->getType());
     $a->getUser();
 }
Пример #2
0
 public function validateFactor(Factor $factor) : self
 {
     $success = false;
     $ct = clone $this->time;
     $et = $factor->getExpiration();
     $this->loadUser();
     if (!$this->user) {
         throw new BadMethodCallException('Trying to validate a factor with no user to validate aagainst. ' . 'Provide a user with setUser() or setToken() first');
     }
     switch ($factor->getType()->getValue()) {
         case FactorType::INHERENCE:
             $success = $this->user->validateInherenceFactor($factor->getSecret());
             break;
         case FactorType::KNOWLEDGE:
             $success = $this->user->validateKnowledgeFactor($factor->getSecret());
             break;
         case FactorType::POSSESSION:
             $success = $this->user->validatePossessionFactor($factor->getSecret());
             break;
     }
     if (!$success) {
         throw new Exceptions\AuthenticationFailedException();
     }
     switch ($factor->getType()->getValue()) {
         case FactorType::INHERENCE:
             $this->ifct = $ct;
             $this->ifet = $et;
             break;
         case FactorType::KNOWLEDGE:
             $this->kfct = $ct;
             $this->kfet = $et;
             break;
         case FactorType::POSSESSION:
             $this->pfct = $ct;
             $this->pfet = $et;
             break;
     }
     return $this;
 }