Replace the equal signs in base32 string

This commit is contained in:
Alex Williams 2014-08-11 10:23:28 +00:00
parent 3c9391bc36
commit 1662edf203

View File

@ -45,8 +45,11 @@ var key = 'secret key for the user';
// encoded will be the secret key, base32 encoded // encoded will be the secret key, base32 encoded
var encoded = base32.encode(key); var encoded = base32.encode(key);
// Google authenticator doesn't like equal signs
var encodedForGoogle = encoded.toString().replace(/=/g,'');
// to create a URI for a qr code (change totp to hotp is using hotp) // to create a URI for a qr code (change totp to hotp is using hotp)
var uri = 'otpauth://totp/somelabel?secret=' + encoded; var uri = 'otpauth://totp/somelabel?secret=' + encodedForGoogle;
``` ```
Note: If your label has spaces or other invalid uri characters you will need to encode it accordingly using `encodeURIComponent` More details about the uri key format can be found on the [google auth wiki](https://code.google.com/p/google-authenticator/wiki/KeyUriFormat) Note: If your label has spaces or other invalid uri characters you will need to encode it accordingly using `encodeURIComponent` More details about the uri key format can be found on the [google auth wiki](https://code.google.com/p/google-authenticator/wiki/KeyUriFormat)