diff options
author | Christoph Wurst <christoph@winzerhof-wurst.at> | 2018-08-22 11:21:36 +0300 |
---|---|---|
committer | Christoph Wurst <christoph@winzerhof-wurst.at> | 2018-08-22 11:21:36 +0300 |
commit | 743c69e9a9dad819445020c96c1b8fc0102a3d6e (patch) | |
tree | 9259008ea7cbe3ea28d0e0d724277f9e2971f308 /lib/Provider | |
parent | c15e1e879e9854c5feaae71a8681878a099ed408 (diff) |
Split settings to work with all three gateway types independently
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'lib/Provider')
-rw-r--r-- | lib/Provider/AProvider.php | 11 | ||||
-rw-r--r-- | lib/Provider/State.php | 13 |
2 files changed, 13 insertions, 11 deletions
diff --git a/lib/Provider/AProvider.php b/lib/Provider/AProvider.php index a69cb75..628e63e 100644 --- a/lib/Provider/AProvider.php +++ b/lib/Provider/AProvider.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace OCA\TwoFactorGateway\Provider; +use OCA\TwoFactorGateway\PhoneNumberMask; use OCA\TwoFactorGateway\Service\Gateway\IGateway; use OCA\TwoFactorGateway\Service\StateStorage; use OCP\Authentication\TwoFactorAuth\IProvider; @@ -40,7 +41,7 @@ abstract class AProvider implements IProvider { const STATE_ENABLED = 3; /** @var string */ - protected $gatewayId; + protected $gatewayName; /** @var IGateway */ protected $gateway; @@ -68,7 +69,7 @@ abstract class AProvider implements IProvider { ISecureRandom $secureRandom, IL10N $l10n) { $this->gateway = $gateway; - $this->gatewayId = $gatewayId; + $this->gatewayName = $gatewayId; $this->stateStorage = $stateStorage; $this->session = $session; $this->secureRandom = $secureRandom; @@ -79,7 +80,7 @@ abstract class AProvider implements IProvider { * Get unique identifier of this 2FA provider */ public function getId(): string { - return "gateway_$this->gatewayId"; + return "gateway_$this->gatewayName"; } private function getSecret(): string { @@ -100,7 +101,7 @@ abstract class AProvider implements IProvider { $secret = $this->getSecret(); try { - $identifier = $this->stateStorage->get($user)->getIdentifier(); + $identifier = $this->stateStorage->get($user, $this->gatewayName)->getIdentifier(); $this->gateway->send( $user, $identifier, @@ -135,7 +136,7 @@ abstract class AProvider implements IProvider { * Decides whether 2FA is enabled for the given user */ public function isTwoFactorAuthEnabledForUser(IUser $user): bool { - return $this->stateStorage->get($user)->getState() === self::STATE_ENABLED; + return $this->stateStorage->get($user, $this->gatewayName)->getState() === self::STATE_ENABLED; } } diff --git a/lib/Provider/State.php b/lib/Provider/State.php index 58023a4..2b4ae0b 100644 --- a/lib/Provider/State.php +++ b/lib/Provider/State.php @@ -36,7 +36,7 @@ class State implements JsonSerializable { /** @var int */ private $state; - /** @var string|null */ + /** @var string */ private $gatewayName; /** @var string|null */ @@ -47,7 +47,7 @@ class State implements JsonSerializable { public function __construct(IUser $user, int $state, - string $gatewayName = null, + string $gatewayName, string $identifier = null, string $verificationCode = null) { $this->user = $user; @@ -70,10 +70,11 @@ class State implements JsonSerializable { ); } - public static function disabled(IUser $user): State { + public static function disabled(IUser $user, string $gatewayName): State { return new State( $user, - SmsProvider::STATE_DISABLED + SmsProvider::STATE_DISABLED, + $gatewayName ); } @@ -102,9 +103,9 @@ class State implements JsonSerializable { } /** - * @return string|null + * @return string */ - public function getGatewayName() { + public function getGatewayName(): string { return $this->gatewayName; } |