Open CassMidnight opened 8 years ago
You can also use %20 instead of a space. I agree that it should be consistent however.
I'm not sure if the generated QR code is the problem or the Google Authenticator application that parses the QR code. The given QR code link already contains %20 for the whitespaces. Using the + sign for the whitespaces results in an "Invalide barcode" as well :-(
So where did this barcode come from? It didn't come from the "google-authenticator" binary in this package, did it? Because I can't seem to generate anything with it that doesn't escape spaces.
What gives? Totally lame that I can't have a space in the name on iOS but I can have it in Android.
I found a fix....it seems you must double encode the label/issuer if it has spaces This is the PHP code I use to generate the URL. It works even if $issuer contains a space.....
public function getUrl($issuer, $user, $secret, $width = 200, $height = 200) {
$url = sprintf("otpauth://totp/%s:%s?secret=%s&issuer=%s", rawurlencode($issuer), $user, $secret, rawurlencode($issuer));
$encoder = sprintf("https://www.google.com/chart?chs=%dx%d&chld=M|0&cht=qr&chl=",$width,$height);
$encoderURL = sprintf( "%s%s",$encoder, rawurlencode($url));
return $encoderURL;
}
Filed internally as b/117751715
You don't have to double encode it. Just replace a space in de issuer by "+" and a space in user by "%20"
`public function getAuthenticatorQRUrl($issuer, $user, $secret, $width = 200, $height = 200) { // To avoid problems with URL containing spaces on Apple devices, replace them
$issuer = str_replace(" ", "+" , $issuer); // in ISSUER: replace space by "+"
$user = str_replace(" ", "%20", $user); // in USER : replace space by "%20"
// don't use: "otpauth://totp/%s:%s?secret=%s&issuer=%s", $issuer, $user, $secret, $issuer);
// but : "otpauth://totp/%s?secret=%s&issuer=%s" , $user, $secret, $issuer);
$otpauth = sprintf("otpauth://totp/%s?secret=%s&issuer=%s", $user, $secret, $issuer);
$encoder = sprintf("https://chart.googleapis.com/chart?chs=%dx%d&chld=M|0&cht=qr&chl=", $width, $height);
$encoderURL = sprintf("%s%s", $encoder, rawurlencode($otpauth));
return $encoderURL;
}`
Do we have a fix on this? The provided answers do not work for me.
@MincDev if it doesn't work for you but works for others then I suspect you have another problem.
Supposedly this is fixed in the source of the App Store version, but I don't know if there's been a release since then.
@MincDev if it doesn't work for you but works for others then I suspect you have another problem.
Supposedly this is fixed in the source of the App Store version, but I don't know if there's been a release since then.
Apologies, Thomas I just found the solution. It seems after I started looking at each parameter one by one to see which one is breaking the code, my problem ended up with the secret code being too long. After following another example, it is working now.
The text:
otpauth://totp/fred@myapplication.com - ServerName?secret=1111111111111111
Which generates the below QR code is not parsed correctly on iOS and results in an "Invaild Barcode" I believe this is due to the spaces in the string, since if they are replaced with underscores the barcode will scan fine. I should note that this barcode will scan fine on Android so it is likely that the parsing between the two platforms is inconsistent.
Link to the QR code the problem occurs on:
QR code