/** * Generate the URL of a QR code, which can be scanned by Google Authenticator app * * @param \Scheb\TwoFactorBundle\Model\Google\TwoFactorInterface $user * @return string */ public function getUrl(TwoFactorInterface $user) { $encoder = "https://chart.googleapis.com/chart?chs=200x200&chld=M|0&cht=qr&chl="; if ($this->issuer) { $encoderURL = sprintf("otpauth://totp/%s:%s@%s?secret=%s&issuer=%s", rawurlencode($this->issuer), rawurlencode($user->getUsername()), rawurlencode($this->server), $user->getGoogleAuthenticatorSecret(), rawurlencode($this->issuer)); } else { $encoderURL = sprintf("otpauth://totp/%s@%s?secret=%s", rawurlencode($user->getUsername()), rawurlencode($this->server), $user->getGoogleAuthenticatorSecret()); } return $encoder . urlencode($encoderURL); }
/** * Generate the content for a QR-Code to be scanned by Google Authenticator * Use this method if you don't want to use google charts to display the qr-code * * @param TwoFactorInterface $user * * @return string */ public function getQRContent(TwoFactorInterface $user) { $userAndHost = rawurlencode($user->getUsername()) . ($this->server ? '@' . rawurlencode($this->server) : ''); if ($this->issuer) { $qrContent = sprintf('otpauth://totp/%s:%s?secret=%s&issuer=%s', rawurlencode($this->issuer), $userAndHost, $user->getGoogleAuthenticatorSecret(), rawurlencode($this->issuer)); } else { $qrContent = sprintf('otpauth://totp/%s?secret=%s', $userAndHost, $user->getGoogleAuthenticatorSecret()); } return $qrContent; }
/** * Generate the URL of a QR code, which can be scanned by Google Authenticator app * * @param \Scheb\TwoFactorBundle\Model\Google\TwoFactorInterface $user * @return string */ public function getUrl(TwoFactorInterface $user) { $encoder = "https://chart.googleapis.com/chart?chs=200x200&chld=M|0&cht=qr&chl="; if ($this->issuer) { // In the event that server is null or empty, we don't want to add the "@", // this stops Google Authenticator showing "username@" when the server_name is not provided. if ($this->server !== null) { $urlBeforeAddition = "otpauth://totp/%s:%s@%s?secret=%s&issuer=%s"; } else { $urlBeforeAddition = "otpauth://totp/%s:%s%s?secret=%s&issuer=%s"; } $encoderURL = sprintf($urlBeforeAddition, rawurlencode($this->issuer), rawurlencode($user->getUsername()), rawurlencode($this->server), $user->getGoogleAuthenticatorSecret(), rawurlencode($this->issuer)); } else { // In the event that server is null or empty, we don't want to add the "@", // this stops Google Authenticator showing "username@" when the server_name is not provided. if ($this->server !== null) { $urlBeforeAddition = "otpauth://totp/%s@%s?secret=%s"; } else { $urlBeforeAddition = "otpauth://totp/%s@%s?secret=%s"; } $encoderURL = sprintf($urlBeforeAddition, rawurlencode($user->getUsername()), rawurlencode($this->server), $user->getGoogleAuthenticatorSecret()); } return $encoder . urlencode($encoderURL); }