From 95a36b00c1e5fbc3af84bee4a6a81182d0d07453 Mon Sep 17 00:00:00 2001 From: Alexander Corn Date: Thu, 8 Dec 2016 17:57:01 -0500 Subject: [PATCH] Remember time offset for purposes of acceptConfirmationForObject Closes #147 --- components/confirmations.js | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/components/confirmations.js b/components/confirmations.js index 2ede8ed..e355719 100644 --- a/components/confirmations.js +++ b/components/confirmations.js @@ -156,12 +156,28 @@ SteamCommunity.prototype.acceptConfirmationForObject = function(identitySecret, var self = this; this._usedConfTimes = this._usedConfTimes || []; - SteamTotp.getTimeOffset(function(err, offset) { - if (err) { - callback(err); - return; - } + if (typeof this._timeOffset !== 'undefined') { + // time offset is already known and saved + doConfirmation(); + } else { + SteamTotp.getTimeOffset(function(err, offset) { + if (err) { + callback(err); + return; + } + self._timeOffset = offset; + doConfirmation(); + + setTimeout(function() { + // Delete the saved time offset after 12 hours because why not + delete self._timeOffset; + }, 1000 * 60 * 60 * 12); + }); + } + + function doConfirmation() { + var offset = self._timeOffset; var time = SteamTotp.time(offset); self.getConfirmations(time, SteamTotp.getConfirmationKey(identitySecret, time, "conf"), function(err, confs) { if (err) { @@ -190,7 +206,7 @@ SteamCommunity.prototype.acceptConfirmationForObject = function(identitySecret, conf.respond(time, SteamTotp.getConfirmationKey(identitySecret, time, "allow"), true, callback); }); - }); + } }; /**