From 34107df4c54ceca8471601d8fe1918d8d5f3c1dd Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Tue, 20 Aug 2019 13:34:59 +1200 Subject: [PATCH] FIX TOTP issuer and label are now extensible --- README.md | 17 +++++++++++++++++ src/RegisterHandler.php | 4 ++++ 2 files changed, 21 insertions(+) diff --git a/README.md b/README.md index e6198ef..d574608 100644 --- a/README.md +++ b/README.md @@ -74,6 +74,23 @@ SilverStripe\TOTP\RegisterHandler: user_help_link: 'https://intranet.mycompany.com/help-docs/using-totp' ``` +### TOTP issuer and label + +The TOTP "issuer" is the SilverStripe site name (set in SiteConfig) by default, and the "label" is the member's email +address by default. These are the values that show up in your authenticator app. You can change these if you need +to use something else, by writing an extension on `RegisterHandler`: + +```php +class MyTOTPRegisterHandlerExtension extends Extension +{ + public function updateTotp(\OTPHP\TOTPInterface $totp, \SilverStripe\Security\Member $member) + { + $totp->setLabel($member->getCustomTOTPLabel()); + $totp->setIssuer('My web project'); + } +} +``` + ## License See [License](LICENSE.md) diff --git a/src/RegisterHandler.php b/src/RegisterHandler.php index 31e2336..8e378ab 100644 --- a/src/RegisterHandler.php +++ b/src/RegisterHandler.php @@ -6,6 +6,7 @@ use SilverStripe\Control\HTTPRequest; use SilverStripe\Core\Config\Configurable; use SilverStripe\Core\Environment; +use SilverStripe\Core\Extensible; use SilverStripe\Core\Injector\Injector; use SilverStripe\MFA\Exception\AuthenticationFailedException; use SilverStripe\MFA\Method\Handler\RegisterHandlerInterface; @@ -21,6 +22,7 @@ class RegisterHandler implements RegisterHandlerInterface { use Configurable; + use Extensible; use TOTPAware; /** @@ -54,6 +56,8 @@ public function start(StoreInterface $store): array } $totp->setIssuer(SiteConfig::current_site_config()->Title); + $this->extend('updateTotp', $totp, $member); + return [ 'enabled' => !empty(Environment::getEnv('SS_MFA_SECRET_KEY')), 'uri' => $totp->getProvisioningUri(),