Skip to content

Commit

Permalink
✨ Separation of voting session time and bearer token lifetime (#455)
Browse files Browse the repository at this point in the history
Parent issue: sequentech/meta#762
  • Loading branch information
Findeton authored Jul 19, 2024
1 parent 8b81d74 commit 76b39da
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions avBooth/booth-directive/booth-directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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)) ||
Expand All @@ -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;
}

Expand All @@ -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);
Expand Down

0 comments on commit 76b39da

Please sign in to comment.