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.
91 lines
2.0 KiB
91 lines
2.0 KiB
<?php declare(strict_types=1);
|
|
|
|
namespace BradyMcD\TAATPExample;
|
|
|
|
require __DIR__ . "/../vendor/autoload.php";
|
|
|
|
use BradyMcD\TAATP\Factory;
|
|
use BradyMcD\TAATP\Required\PersistenceInterface;
|
|
use BradyMcD\TAATP\Request\Base as RequestRouter;
|
|
use BradyMcD\TAATP\Session\Base as Session;
|
|
use BradyMcD\TAATP\Workflow\UserManagement;
|
|
|
|
|
|
class SessionPersistence implements PersistenceInterface
|
|
{
|
|
private Session $session;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->session = new Session();
|
|
}
|
|
|
|
public function userString(mixed $index): string
|
|
{
|
|
assert(is_string($index));
|
|
return $index;
|
|
}
|
|
|
|
public function storeSecret(mixed $index, string $secret)
|
|
{
|
|
$userID = $this->userString($index) . "_URI";
|
|
$this->session->store($userID, $secret);
|
|
}
|
|
|
|
public function stripSecret(mixed $index)
|
|
{
|
|
$userID = $this->userString($index) . "_URI";
|
|
$this->session->store($userID, null);
|
|
}
|
|
|
|
public function storeLastTime(mixed $index, int $timestamp)
|
|
{
|
|
$userID = $this->userString($index) . "_timestamp";
|
|
$this->session->store($userID, $timestamp);
|
|
}
|
|
|
|
public function getSecret(mixed $index): ?string
|
|
{
|
|
$userID = $this->userString($index) . "_URI";
|
|
return $this->session->get($userID);
|
|
}
|
|
|
|
public function getLastTime(mixed $index): int
|
|
{
|
|
$userID = $this->userString($index) . "_timestamp";
|
|
return $this->session->get($userID);
|
|
}
|
|
}
|
|
|
|
class HttpEnroll
|
|
{
|
|
private $totpFactory;
|
|
|
|
public function __construct()
|
|
{
|
|
|
|
$this->totpFactory = new Factory(
|
|
new SessionPersistence(),
|
|
new RequestRouter("HttpFullFlow.php"),
|
|
);
|
|
$this->userManagement = $this->totpFactory->userManagement("Testman@example.co");
|
|
}
|
|
|
|
public function view()
|
|
{
|
|
$this->userManagement->view();
|
|
}
|
|
|
|
public function response()
|
|
{
|
|
$this->userManagement->response();
|
|
}
|
|
}
|
|
|
|
$page = new HttpEnroll();
|
|
|
|
$page->response();
|
|
$page->view();
|
|
|
|
?>
|