wstrange / GoogleAuth

Google Authenticator Server side code
BSD 3-Clause "New" or "Revised" License
1.05k stars 330 forks source link

Allow regeneration of QR code #60

Closed jasonab closed 7 years ago

jasonab commented 7 years ago

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).

wstrange commented 7 years ago

@emcrisostomo Thoughts?

jasonab commented 7 years ago

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

emcrisostomo commented 7 years ago

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

emcrisostomo commented 7 years ago

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:

Hence I will refactor the library in order to:

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

jasonab commented 7 years ago

Very good, thanks for your feedback.

emcrisostomo commented 7 years ago

Released in 1.1.3.

jasonab commented 7 years ago

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.

jasonab commented 7 years ago

@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.

emcrisostomo commented 7 years ago

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

emcrisostomo commented 7 years ago

Released in 1.1.4