Skip to content

Commit

Permalink
FIX TOTP issuer and label are now extensible (#38)
Browse files Browse the repository at this point in the history
FIX TOTP issuer and label are now extensible
  • Loading branch information
ScopeyNZ authored Aug 20, 2019
2 parents 60165d9 + 34107df commit 3ada1bb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions src/RegisterHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -21,6 +22,7 @@
class RegisterHandler implements RegisterHandlerInterface
{
use Configurable;
use Extensible;
use TOTPAware;

/**
Expand Down Expand Up @@ -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(),
Expand Down

0 comments on commit 3ada1bb

Please sign in to comment.