getProvisioningUri() публичный Метод

public getProvisioningUri ( )
 /**
  * Get the QR Code URL for the otp instance
  * @param TOTP|null $totp
  * @return string
  */
 public function getQRCodeGoogleUrl(TOTP $totp = null)
 {
     $base_url = 'https://chart.googleapis.com/chart?chs=200x200&chld=M|0&cht=qr&chl=';
     if ($totp !== null) {
         return $base_url . urlencode($totp->getProvisioningUri());
     } else {
         return $base_url . urlencode($this->totp->getProvisioningUri());
     }
 }
 /**
  * @dataProvider testProvisioningURIData
  */
 public function testProvisioningURI($secret, $label, $issuer, $expectedResult)
 {
     $totp = new TOTP($secret);
     $totp->setLabel($label);
     $totp->setIssuer($issuer);
     $this->assertEquals($expectedResult, $totp->getProvisioningUri());
 }
Пример #3
0
 public function renderQrCodeAction()
 {
     /** @var AccountInterface $account */
     $account = $this->zourceAccount();
     $oneTimePassword = new TOTP($account->getContact()->getFullName(), $this->tfaService->getSecret());
     $oneTimePassword->setIssuer('Zource');
     $oneTimePassword->setIssuerIncludedAsParameter(true);
     $oneTimePassword->setParameter('image', $this->url()->fromRoute('settings/security/tfa-image', [], ['force_canonical' => true]));
     $filePath = tempnam('data/tmp/', '2fa-qr-');
     $renderer = new Png();
     $renderer->setHeight(256);
     $renderer->setWidth(256);
     $writer = new Writer($renderer);
     $writer->writeFile($oneTimePassword->getProvisioningUri(true), $filePath);
     $response = new Stream();
     $response->setCleanup(true);
     $response->setStream(fopen($filePath, 'rb'));
     $response->setStreamName($filePath);
     $headers = $response->getHeaders();
     $headers->addHeaderLine('Content-Length', filesize($filePath));
     $headers->addHeaderLine('Content-Type', 'image/png');
     return $response;
 }
Пример #4
0
 public function testCustomParameter()
 {
     $otp = new TOTP();
     $otp->setLabel('*****@*****.**')->setIssuer('My Project')->setDigest('sha512')->setDigits(8)->setIssuerIncludedAsParameter(true)->setSecret('JDDK4U6G3BJLEZ7Y')->setInterval(20)->setParameter('foo', 'bar.baz');
     $this->assertEquals('otpauth://totp/My%20Project%3Aalice%40foo.bar?algorithm=sha512&digits=8&foo=bar.baz&issuer=My%20Project&period=20&secret=JDDK4U6G3BJLEZ7Y', $otp->getProvisioningUri());
 }