From 8b2d419cbb7aee76eaa5690c1a5044a9ebf1d45f Mon Sep 17 00:00:00 2001 From: Brady McDonough Date: Tue, 20 Feb 2024 17:52:04 -0700 Subject: [PATCH] Adding integration examples --- examples/HttpEnroll.php | 95 +++++++++++++++++++++++++++++++++ src/URI/Otpauth.php | 4 +- src/Workflow/UserManagement.php | 8 +-- 3 files changed, 102 insertions(+), 5 deletions(-) create mode 100644 examples/HttpEnroll.php diff --git a/examples/HttpEnroll.php b/examples/HttpEnroll.php new file mode 100644 index 0000000..5715868 --- /dev/null +++ b/examples/HttpEnroll.php @@ -0,0 +1,95 @@ +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(); + +?> diff --git a/src/URI/Otpauth.php b/src/URI/Otpauth.php index a9921c3..fa52b1a 100644 --- a/src/URI/Otpauth.php +++ b/src/URI/Otpauth.php @@ -134,8 +134,8 @@ class Otpauth 'issuer' => $this->issuer, 'secret' => $this->secret, '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, + 'period' => ($this->period == self::DEFAULTS['period']) ? null : $this->period, ]; return $this->buildUri($queryValues); } @@ -146,8 +146,8 @@ class Otpauth 'issuer' => $this->issuer, 'secret' => $this->secret, 'algorithm' => $this->algorithm, - 'period' => $this->period, 'digits' => $this->digits, + 'period' => $this->period, ]; return $this->buildUri($queryValues); } diff --git a/src/Workflow/UserManagement.php b/src/Workflow/UserManagement.php index 8dd45e7..5bfa905 100644 --- a/src/Workflow/UserManagement.php +++ b/src/Workflow/UserManagement.php @@ -49,8 +49,8 @@ class UserManagement implements WorkflowInterface "taatp", $this->hash->keygen(), $this->hash->hashType(), - 30, - 6 + 6, + 30 ); $provisioningUri = $otpauthURI->uriString(); $persistentUri = $otpauthURI->uriStringExplicit(); @@ -97,7 +97,9 @@ class UserManagement implements WorkflowInterface $pUri = $this->db->getSecret($this->userIndex); $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( $pUri->getSecret(),