TOTP Token expires earlier
Hi, im currently having a hard time understanding the basics of TOTP. Below is my testing which I dont full undestand why the token is expiring (false) before the correct time it should expire.
generation code
const speakeasy = require("@levminer/speakeasy")
let SECRET = 'test'
let token = speakeasy.totp({
secret: SECRET.base32,
encoding: "base32",
window: 2
})
verification code
let tokenValidates = speakeasy.totp.verify({
secret: SECRET.base32,
encoding: "base32",
token: otp,
window: 2,
})
settings
window = 2 step = 30 secs (default) toekn is created 07:49:23 PM , it will be valid until 07:50:52 PM base on the window which is 2 (+30 and +60 seconds from the token generation time)
results
958614 crea 07:49:23 PM --> token created 958614 true 07:49:28 PM 958614 true 07:49:43 PM (results truncated as they are "true") 958614 true 07:50:26 PM 958614 true 07:50:29 PM 958614 false 07:50:31 PM
Facing the same issue, tokenValidates returns false before the 30 secs span
I added { step: 600, window: 5 } // equiv to 5 mins
let tokenValidates = speakeasy.totp.verify({
secret: SECRET.base32,
encoding: "base32",
token: otp,
window: 5,
step: 600
})
Check out: https://time.is/ Make sure your clock is in sync