wstrange / GoogleAuth

Google Authenticator Server side code

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Allow regeneration of QR code

jasonab opened this issue · comments

My apologies if I missed something in the API.

Right now, you can only generate a QR code with a GoogleAuthenticatorKey object. This object can only be created by a call to createCredentials(). My use case is that I need to recreate the QR code with a preexisting secret (that has been persisted to the database), but there doesn't seem to be any way to do that with the existing API, as I cannot create a GoogleAuthenticatorKey object, or call the QR code methods with just the key. It would be sufficient to overload getOtpAuthURL() to take 3 strings (including the key).

If a PR would be accepted for this, I'd be happy to submit one.

Hi @jasonab, thanks for the suggestion. I'll have a look at it ASAP. If you wish to send a PR, please do.

Hi @jasonab, I've quickly checked the PR #61. The problem is not that simple. Actually, there currently is a bug. The URL generation works only if the current configuration is the default. If you customise the GoogleAuthenticatorConfig, then you'll get a wrong URL. That's because you need the following information to build the URL:

  • key
  • number of digis (default: 6)
  • algorithm (default: SHA1)
  • period (default: 30)

Hence I will refactor the library in order to:

  • Deprecate the current method, and specify that it will only work for the default TOTP configuration.
  • Add a method that takes all that information (presumably in the form of a key and a GoogleAuthenticatorConfig instance).

If you are using the default settings and do not need to store the configuration, you will just build a default configuration object.

Very good, thanks for your feedback.

Released in 1.1.3.

Thanks very much for taking care of this, I really appreciate the responsiveness. We'll be integrating with the new version over the next couple of weeks, and I'll file new issues if we have any problems.

@emcrisostomo Thanks again for the change, but I think I'm a little confused. My original need here was to take a persisted secret and recreate the URL. The new methods take a GoogleAuthenticatorKey with an embedded config, but I still have no way to construct a GoogleAuthenticatorKey other than calling createCredentials().

In one of your earlier replies, you mentioned adding a method that takes the raw key with a config object, which would work fine for me, but I do not see that method in the latest version.

Hi @jasonab, you're right. Haste makes waste. Sort of...

Released in 1.1.4