Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What data do I have to use to generate a QR code for Google Authenticator?

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?

like image 508
Oliver Salzburg Avatar asked Feb 21 '14 20:02

Oliver Salzburg


People also ask

How to add a QR code to Google Authenticator?

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.

What is Google Authenticator and how does it work?

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:

How do I transfer my Google Authenticator account to a new phone?

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.

What can you do with a QR code generator?

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.


2 Answers

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.

like image 180
Oliver Salzburg Avatar answered Sep 28 '22 21:09

Oliver Salzburg


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.

like image 21
jww Avatar answered Sep 28 '22 19:09

jww