Example #1
0
 /**
  * @return Prophecy\Prophecy\ObjectProphecy
  */
 private function getFactor(Type $type, DateTime $exp = null)
 {
     switch ($type->getValue()) {
         case Type::INHERENCE:
             $name = 'InherenceFactor';
             break;
         case Type::KNOWLEDGE:
             $name = 'KnowledgeFactor';
             break;
         case Type::POSSESSION:
             $name = 'PossessionFactor';
             break;
     }
     $factor = $this->prophesize('Firehed\\Auth\\Factors\\' . $name);
     $factor->getType()->willReturn($type);
     $factor->getExpiration()->willReturn($exp);
     $factor->getSecret()->willReturn(new Secret(''));
     return $factor;
 }
Example #2
0
 private function assertFactorTimestamps() : self
 {
     $data = [[FactorType::KNOWLEDGE(), $this->kfct, $this->kfet], [FactorType::POSSESSION(), $this->pfct, $this->pfet], [FactorType::INHERENCE(), $this->ifct, $this->ifet]];
     foreach ($data as $types) {
         list($type, $create, $exp) = $types;
         $validation = $this->validateType($type, $create, $exp);
         switch ($validation) {
             case self::RET_OK:
                 break;
             case self::RET_UNAUTH:
                 throw new AE\AuthenticationRequiredException([]);
             case self::RET_EXP:
                 throw new AE\FactorExpiredException([]);
         }
     }
     return $this;
 }
Example #3
0
 /**
  * @covers ::getPartiallyAuthenticatedUser
  */
 public function testGetPartiallyAuthenticatedUserWorksWhenInPartialMode()
 {
     $a = new Auth();
     $u = $this->getUser();
     $u->getRequiredAuthenticationFactors()->willReturn([Factors\FactorType::KNOWLEDGE()]);
     $u = $u->reveal();
     $a->setUser($u);
     $a->setRequiredLevel(Level::PARTIAL());
     // Sanity checks
     $this->assertTrue($a->isMissingKnowledgeFactor());
     $this->assertNull($a->getUser());
     // Actual test
     $this->assertSame($u, $a->getPartiallyAuthenticatedUser(), 'getPartiallyAuthenticatedUser did not return the user');
 }
Example #4
0
 /**
  * By default, assume knowledge factors (e.g. passwords) are exclusively
  * supported. Override this to support MFA.
  * @return array<Factors\FactorType>
  */
 public function getRequiredAuthenticationFactors() : array
 {
     return [Factors\FactorType::KNOWLEDGE()];
 }