From 76b39dacaeff99d6e82cc53caf36b74f84b6d5e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Robles?= Date: Fri, 19 Jul 2024 14:26:59 -0500 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Separation=20of=20voting=20session?= =?UTF-8?q?=20time=20and=20bearer=20token=20lifetime=20(#455)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Parent issue: https://github.com/sequentech/meta/issues/762 --- avBooth/booth-directive/booth-directive.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/avBooth/booth-directive/booth-directive.js b/avBooth/booth-directive/booth-directive.js index a370946c..fbee912e 100644 --- a/avBooth/booth-directive/booth-directive.js +++ b/avBooth/booth-directive/booth-directive.js @@ -695,10 +695,13 @@ angular.module('avBooth') function isStateCompatibleWithCountdown() { return scope.state !== stateEnum.errorScreen && scope.state !== stateEnum.successScreen; } + var demoStartTime = Date.now(); // Try to read and process voting credentials function readVoteCredentials() { if (scope.isDemo || scope.isPreview) { + scope.startTimeMs = demoStartTime; + scope.sessionEndsAtMs = scope.startTimeMs + ConfigService.authTokenExpirationSeconds * 1000; return; } var credentialsStr = $window.sessionStorage.getItem("vote_permission_tokens"); @@ -792,7 +795,6 @@ angular.module('avBooth') var objectType = splitMessage[1]; var objectId = splitMessage[2]; var action = splitMessage[3]; - var startTimeSecsStr = splitMessage[4]; // timestamp has already been validated so we don't validate it again if ( isNaN(parseInt(objectId, 10)) || @@ -814,7 +816,7 @@ angular.module('avBooth') scope.authorizationHeader = currentElectionCredentials.token; scope.currentElectionCredentials = currentElectionCredentials; scope.isDemo = false; - scope.startTimeMs = Number(startTimeSecsStr) * 1000; + scope.startTimeMs = decodedToken.create_timestamp * 1000; scope.sessionEndsAtMs = decodedToken.expiry_timestamp * 1000; } @@ -823,8 +825,8 @@ angular.module('avBooth') return scope.sessionEndsAtMs || scope.currentElectionCredentials && scope.currentElectionCredentials.sessionEndsAtMs || (scope.startTimeMs + ConfigService.authTokenExpirationSeconds * 1000); } - function getSessionStartTime() { - if (!scope.startTimeMs) { + function getSessionStartTime(readCredentials) { + if (readCredentials) { readVoteCredentials(); } return scope.startTimeMs || (scope.currentElectionCredentials && scope.currentElectionCredentials.sessionStartedAtMs);