for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php declare(strict_types=1);
namespace SilverStripe\TOTP;
use OTPHP\TOTP;
use OTPHP\TOTPInterface;
use RuntimeException;
use SilverStripe\Core\Environment;
use SilverStripe\MFA\Store\StoreInterface;
trait TOTPAware
{
/**
* Gets the encryption key to use from environment variables. This is generated by default on the Common Web
* Platform, but can be defined as a custom value if required.
*
* @return string
*/
protected function getEncryptionKey(): string
return (string) Environment::getEnv('SS_MFA_SECRET_KEY');
}
* Get an instance of the TOTP handler service. The secret must already be defined and set to the StoreInterface.
* @param StoreInterface $store
* @return TOTPInterface
* @throws RuntimeException
protected function getTotp(StoreInterface $store): TOTPInterface
$state = $store->getState();
if (!isset($state['secret'])) {
throw new RuntimeException('TOTP secret is not available in the StoreInterface');
return TOTP::create($state['secret']);