Is there a way to increase the token expiration time of Speakeasy

684 Views Asked by At

Currently i am using speakeasy to generate a OTP for two factor authentication.

speakeasy.totp({
      secret,
      encoding: 'base32'
});

I am generating the token using this. Its expiration time is 30s.

Can anyone know how to increase it?

I tried this. But it always return true when verifying the token.

speakeasy.totp({
      secret,
      encoding: 'base32',
      time: 60,
});

speakeasy.totp.verify({
      secret: secretKey,
      encoding: 'base32',
      token: code,
      time : 60
});
2

There are 2 best solutions below

0
On

The time option actually will not change the expiration time of the token .

What you need is the step option to modify the expire time like this :

speakeasy.totp({
      secret,
      encoding: 'base32',
      step : 300 // Expire token in 5 minutes
});

speakeasy.totp.verify({
      secret: secretKey,
      encoding: 'base32',
      token: code,
      step : 300 // Expire token in 5 minutes
});
0
On

try { step: 60,//in minute(30sec defaultx2) window:5,//expiry set to 5 minute }