Adding integration examples

master
Brady McDonough 2 years ago
parent 9d7ff6c5f3
commit 8b2d419cbb

@ -0,0 +1,95 @@
<?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"),
null,
null,
null,
null,
null,
);
$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();
?>

@ -134,8 +134,8 @@ class Otpauth
'issuer' => $this->issuer, 'issuer' => $this->issuer,
'secret' => $this->secret, 'secret' => $this->secret,
'algorithm' => ($this->algorithm == self::DEFAULTS['algorithm']) ? null : $this->algorithm, 'algorithm' => ($this->algorithm == self::DEFAULTS['algorithm']) ? null : $this->algorithm,
'period' => ($this->period == self::DEFAULTS['period']) ? null : $this->period,
'digits' => ($this->digits == self::DEFAULTS['digits']) ? null : $this->digits, 'digits' => ($this->digits == self::DEFAULTS['digits']) ? null : $this->digits,
'period' => ($this->period == self::DEFAULTS['period']) ? null : $this->period,
]; ];
return $this->buildUri($queryValues); return $this->buildUri($queryValues);
} }
@ -146,8 +146,8 @@ class Otpauth
'issuer' => $this->issuer, 'issuer' => $this->issuer,
'secret' => $this->secret, 'secret' => $this->secret,
'algorithm' => $this->algorithm, 'algorithm' => $this->algorithm,
'period' => $this->period,
'digits' => $this->digits, 'digits' => $this->digits,
'period' => $this->period,
]; ];
return $this->buildUri($queryValues); return $this->buildUri($queryValues);
} }

@ -49,8 +49,8 @@ class UserManagement implements WorkflowInterface
"taatp", "taatp",
$this->hash->keygen(), $this->hash->keygen(),
$this->hash->hashType(), $this->hash->hashType(),
30, 6,
6 30
); );
$provisioningUri = $otpauthURI->uriString(); $provisioningUri = $otpauthURI->uriString();
$persistentUri = $otpauthURI->uriStringExplicit(); $persistentUri = $otpauthURI->uriStringExplicit();
@ -97,7 +97,9 @@ class UserManagement implements WorkflowInterface
$pUri = $this->db->getSecret($this->userIndex); $pUri = $this->db->getSecret($this->userIndex);
$enrollFlag = \is_null($pUri); $enrollFlag = \is_null($pUri);
$enrollFlag && $enrollFlag = $this->session->get('secret'); $enrollFlag && $pUri = $this->session->get('secret');
echo "Recovered pURI for a " . ($enrollFlag)?"new user":"returning user";
$totp = _6238( $totp = _6238(
$pUri->getSecret(), $pUri->getSecret(),

Loading…
Cancel
Save