1

I want to implement Google 2FA Authentication in node js How can i do this?

I used speakeasy js library like below :

const qrcode = require('qrcode');
const secret = speakeasy.generateSecret({
    name: 'test'//constants.SPEAK_SECRET_CODE
});
 var qr_data = '';
  await qrcode.toDataURL(secret.otpauth_url).then(qr => {
                                qr_data = qr;
                            });
 return { qr_data };

After this i created html file with this code <img src="qr_data"> and with google authenticator app i scanned barcode it worked succesfully.

Then i tried to this in order to verify google otp :

  var verified = speakeasy.totp.verify({
            secret: secret.ascii,
            encoding: 'ascci',
            token: otp,
        });

        console.log(verified);

But verified variable is always false,although I entered the correct code

ilyasg
  • 11
  • 2

0 Answers0