You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.6 KiB
52 lines
1.6 KiB
<?php declare(strict_types=1);
|
|
|
|
namespace BradyMcD\TAATP;
|
|
use BradyMcD\TAATP\Required\PersistenceInterface;
|
|
use BradyMcD\TAATP\SessionInterface;
|
|
use BradyMcD\TAATP\AntiCSRFInterface;
|
|
use BradyMcD\TAATP\Workflow\UserManagement;
|
|
use BradyMcD\TAATP\Workflow\Authenticate;
|
|
|
|
|
|
/**
|
|
* The primary entrypoint of the module.
|
|
* @SuppressWarnings(PHPMD.ShortVariable)
|
|
*/
|
|
class Factory
|
|
{
|
|
public function __construct(
|
|
private PersistenceInterface $db,
|
|
private RequestInterface $request,
|
|
private null|SessionInterface $session,
|
|
private null|\PSR\Clock\ClockInterface $csrfClock,
|
|
private null|AntiCSRFInterface $csrf,
|
|
private null|\PSR\Clock\ClockInterface $totpClock,
|
|
private null|HashInterface $hash,
|
|
)
|
|
{
|
|
$this->session ? : $this->session = new Session\Base();
|
|
$this->csrf_clock ? : $this->csrfClock = new Clock\Request();
|
|
$this->csrf ? : $this->csrf = new AntiCSRF\Base(
|
|
$this->session,
|
|
$this->csrf_clock
|
|
);
|
|
$this->totp_clock ? : $this->totpClock = new Clock\Base();
|
|
$this->$hash ? : $this->hash = new Hash\HMAC_SHA1();
|
|
}
|
|
|
|
public function userManagement(mixed $userIndex): UserManagement
|
|
{
|
|
return new UserManagement($this->db, $this->request, $this->csrf, $this->session, $userIndex);
|
|
}
|
|
|
|
public function authenticate(mixed $userIndex): ?Authenticate
|
|
{
|
|
if(\is_null($this->db->getSecret($userIndex)))
|
|
return null;
|
|
else
|
|
return new Authenticate($this->db, $this->request, $this->csrf, $this->session, $userIndex);
|
|
}
|
|
}
|
|
|
|
?>
|