/**
  * Create a TOTP URI for use with Google Authenticator.
  *
  * Note that this is not a URI for the QR code used by Google Authenticator.
  * The URI produced by this method is used as the actual content of the QR
  * code, and follows a special set of conventions understood by Google
  * Authenticator, and other OTP apps.
  *
  * @param TotpConfigurationInterface            $configuration The TOTP configuration.
  * @param TimeBasedOtpSharedParametersInterface $shared        The shared parameters.
  * @param string                                $label         The label for the account.
  * @param string|null                           $issuer        The issuer name.
  * @param boolean|null                          $issuerInLabel True if legacy issuer support should be enabled by prefixing the label with the issuer name.
  *
  * @return string The TOTP URI.
  */
 public function createTotp(TotpConfigurationInterface $configuration, TimeBasedOtpSharedParametersInterface $shared, $label, $issuer = null, $issuerInLabel = null)
 {
     if (30 === $configuration->window()) {
         $parameters = '';
     } else {
         $parameters = '&period=' . rawurlencode($configuration->window());
     }
     return $this->buildUri('totp', $parameters, $configuration, $shared, $label, $issuer, $issuerInLabel);
 }
Example #2
0
 /**
  * Generate a TOTP value.
  *
  * @link http://tools.ietf.org/html/rfc6238#section-4
  *
  * @param TotpConfigurationInterface            $configuration The configuration to use for generation.
  * @param TimeBasedOtpSharedParametersInterface $shared        The shared parameters to use for generation.
  *
  * @return HotpValueInterface The generated TOTP value.
  */
 public function generateTotp(TotpConfigurationInterface $configuration, TimeBasedOtpSharedParametersInterface $shared)
 {
     return $this->generator()->generateHotp(new HotpConfiguration($configuration->digits(), null, null, $configuration->secretLength(), $configuration->algorithm()), new CounterBasedOtpSharedParameters($shared->secret(), intval(floor($shared->time() / $configuration->window()))));
 }