简体   繁体   中英

Increase the timeout of one time OTP in node js

I am using speakeasy library to generate one time OTP https://www.npmjs.com/package/speakeasy

var token = speakeasy.totp({
            secret: secret.base32,
            encoding: 'base32',
            step:300
        });

        console.log(token);

        var verified = speakeasy.totp.verify({
            secret: secret.base32,
            encoding: 'base32',
            token: token
        });
        console.log(verified);

But when i add the step parameter value to 300 (expire token after 5 minutes)i will get false on console.log(verified)

So whats the correct way to increase the token expiration time?

Please try with the time option. With the time option, you can get a time-based token for a custom time.

var token = speakeasy.totp({
  secret: secret.base32,
  encoding: 'base32',
  time: 1453667708 // specified in seconds 
});

Hope it will help you!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM