diff options
author | Christoph Wurst <christoph@winzerhof-wurst.at> | 2016-06-04 14:16:18 +0300 |
---|---|---|
committer | Christoph Wurst <christoph@winzerhof-wurst.at> | 2016-06-04 14:16:18 +0300 |
commit | ed7d8759dbc637e121c732bfeb3cfc2042d818ff (patch) | |
tree | b1c7fc438a4464f85b6cdb1f4e7026556dfbf5e9 /lib/Provider | |
parent | b6943ad9d26b7e70b47ed644114a6a4e0b2fa30b (diff) |
first working version
Diffstat (limited to 'lib/Provider')
-rw-r--r-- | lib/Provider/TotpProvider.php (renamed from lib/Provider/SmsProvider.php) | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/lib/Provider/SmsProvider.php b/lib/Provider/TotpProvider.php index 68d4760..4cb8eec 100644 --- a/lib/Provider/SmsProvider.php +++ b/lib/Provider/TotpProvider.php @@ -21,15 +21,21 @@ namespace OCA\TwoFactorTotp\Provider; -use Base32\Base32; +use OCA\TwoFactorTotp\Exception\NoTotpSecretFoundException; +use OCA\TwoFactorTotp\Service\Totp; use OCP\Authentication\TwoFactorAuth\IProvider; use OCP\IUser; use OCP\Template; -use Otp\GoogleAuthenticator; -use Otp\Otp; class TotpProvider implements IProvider { + /** @var Totp */ + private $totp; + + public function __construct(Totp $totp) { + $this->totp = $totp; + } + /** * Get unique identifier of this 2FA provider * @@ -76,13 +82,14 @@ class TotpProvider implements IProvider { * @return Template */ public function getTemplate(IUser $user) { - $otp = new Otp(); - //$secret = $this->random->generate(16); - $secret = GoogleAuthenticator::generateRandom(); - $totp = $otp->totp(Base32::decode($secret)); + try { + $this->totp->getSecret($user); + } catch (NoTotpSecretFoundException $ex) { + $qr = $this->totp->createSecret($user); + } $tmpl = new Template('twofactor_totp', 'challenge'); - $tmpl->assign('secret', $totp); + $tmpl->assign('qr', $qr); return $tmpl; } @@ -95,8 +102,7 @@ class TotpProvider implements IProvider { * @param string $challenge */ public function verifyChallenge(IUser $user, $challenge) { - $otp = new Otp(); - return $otp->checkTotp(Base32::decode($secret), $challenge); + return $this->totp->validateSecret($user, $challenge); } /** |