j256 / two-factor-auth

Two Factor Authentication Java code implementing the Time-based One-time Password Algorithm
ISC License
310 stars 110 forks source link

Google's QR API is dead #34

Open echometerain opened 3 months ago

echometerain commented 3 months ago

Use https://api.qrserver.com/v1/create-qr-code/?size=200x200&data= + generateOtpAuthUrl() instead of qrImageUrl()

javaDev1214 commented 2 months ago

For generating QR code is not such a problem.

How to get: String generatedCode = TimeBasedOneTimePasswordUtil.generateCurrentNumberString(key) from URL above?

Thanks

echometerain commented 2 months ago

Assuming url is in the form of https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=otpauth://totp/LoginSystem%3Fsecret%3DQYX6DXSBCNHGE5RV%26digits%3D6 then do something like generateCurrentNumberString(url.substring(100, 117))

note: the first D after secret is actually a part of %3D which is the url encoding for =

javaDev1214 commented 2 months ago

Assuming url is in the form of https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=otpauth://totp/LoginSystem%3Fsecret%3DQYX6DXSBCNHGE5RV%26digits%3D6 then do something like generateCurrentNumberString(url.substring(100, 117))

note: the first D after secret is actually a part of %3D which is the url encoding for =

Thank you! :)

dpastov commented 2 months ago

@echometerain can't we also generate image without using external service?

echometerain commented 2 months ago

yeah you definitely could

dpastov commented 2 months ago

@echometerain Can it be done with any QR java library? like https://github.com/nayuki/QR-Code-generator or it requires something more?

echometerain commented 2 months ago

probably, never tried it though

dpastov commented 2 months ago

I have used: https://github.com/nayuki/QR-Code-generator to generate QR code (based on value from generateOtpAuthUrl).

You will however need to update the method little bit and replace %3F and %26 on ? and & respectively.