I want to utilize the Google Authenticator app for login purposes in our application.
I'm using speakeasy to generate the base data for the authentication. It can also spit out a URL to a Google website that generates a QR code which I can scan with Google Authenticator to set up the scheme.
I want to generate the QR code myself, mainly because I want to display it in the console using qrcode-terminal.
What data do I have to encode in the QR code to make it work?
It's made for developers by developers! ‘Google Authenticator’ is a useful and popular two-factor authentication tool. In order to “….add a QR code to the Google Authenticator…” that appears on your PC, you install the app on your phone and then use the plus symbol (“+”) in the lower-right of the screen to add a new entry.
Google Authenticator eliminates the risk of an SMS-based attack that uses algorithms to generate the codes on your phone. If you’re looking forward to generating your Google Authenticator QR Code, here’s a step-by-step guide:
If you transfer multiple accounts, your old phone may create more than one QR code. On your new phone, tap Scan QR code. After you scan your QR codes, you get a confirmation that your Google Authenticator accounts have been transferred. Tip: If your camera can’t scan the QR code, it may be that there’s too much info.
With a QR code generator, you can create unique codes that can be integrated into your packaging and print promo designs. A quick scan will lead people to your other creative executions, such as articles, portfolios, photo collections, audio files, and videos. Create QR codes that fit right in with your business branding with our QR code maker.
The string you have to encode is:
otpauth://totp/ApplicationName?secret= + key.base32
ApplicationName
is the name of your application that you want to have displayed in Google Authenticator.Your implementation would look something like this:
var key = speakeasy.generate_key( {length : 20} );
qrcode.generate( "otpauth://totp/foo?secret=" + key.base32, function( qrcode ) {
console.log( qrcode );
} );
There's also official documentation available on the format.
What data do I have to encode in the QR code to make it work?
Google Authenticator has a wiki. The KeyUriFormat has the following example:
Provision a TOTP key for user "[email protected]", to use with a service provided by Example, Inc:
otpauth://totp/Example:[email protected]?secret=JBSWY3DPEHPK3PXP&issuer=Example
This Base32 encoded key "JBSWY3DPEHPK3PXP" has the value:
byte[] key = { 'H', 'e', 'l', 'l', 'o', '!', (byte) 0xDE, (byte) 0xAD, (byte) 0xBE, (byte) 0xEF };
Its important to use the company name ("Example") in both the beginning and the end (with the issuer). See ConflictingAccounts for details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With