j256 / two-factor-auth

Two Factor Authentication Java code implementing the Time-based One-time Password Algorithm

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

"Key not recognized" in Google Authenticator app

Testehan opened this issue · comments

commented

Hi,

Not sure what am i doing wrong or missing...could be that I don't fully understand what the value of the key should be..my code:
String base32Secret = TimeBasedOneTimePasswordUtil.generateBase32Secret();
String imageUrl = TimeBasedOneTimePasswordUtil.qrImageUrl("aUser@gmail.com",base32Secret);
System.out.println(imageUrl);

I click on the URL...and a QR is displayed, and when I scan it with GoogleAuthenticator, I get the error "Key not recognized"..
"aUser@gmail.com" is the email that i have in my google authenticator...

Thx!

commented

My issue was related to the QR that was generated...The QR contained my data that was wrong .. A format like the one from below is one that works
https://chart.googleapis.com/chart?chs=500x500&cht=qr&chl=otpauth://totp/testehanApp:userMax?secret=26QIYRQJZO4SBZOT&issuer=testehanApp&digits=6&period=60

commented

So as mentioned in their documentation: https://github.com/google/google-authenticator/wiki/Key-Uri-Format

Provision a TOTP key for user alice@google.com, to use with a service provided by Example, Inc:
otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&issuer=Example

I was providing a wrong key/Label. The @ is not mandatory. Once I've used this format it worked well:
testehanApp:userMax I also added the issuer=testehanApp which is strongly recommended