From ad6dca0b94335f44bc551a580c6aa1de7ab2992b Mon Sep 17 00:00:00 2001 From: James Nunn <2095017+jamesnunn@users.noreply.github.com> Date: Fri, 19 Nov 2021 10:22:51 +0000 Subject: [PATCH] Adds launcher parameters for adding JWT claim `response_expires_at` (#34) --- launch.go | 2 ++ templates/launch.html | 29 ++++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/launch.go b/launch.go index df6eef7d..dceb00af 100644 --- a/launch.go +++ b/launch.go @@ -2,6 +2,7 @@ package main // import "github.com/ONSdigital/eq-questionnaire-launcher" import ( "fmt" + "time" "html/template" "log" @@ -155,6 +156,7 @@ func quickLauncherHandler(w http.ResponseWriter, r *http.Request) { urlValues.Add("case_id", caseID.String()) urlValues.Add("response_id", randomNumericString(16)) urlValues.Add("language_code", defaultValues["language_code"]) + urlValues.Add("response_expires_at", time.Now().AddDate(0, 0, 7).Format("2006-01-02T15:04:05+00:00")) token, err := authentication.GenerateTokenFromDefaults(surveyURL, accountServiceURL, AccountServiceLogOutURL, urlValues) if err != "" { diff --git a/templates/launch.html b/templates/launch.html index b294ba1c..0f235636 100644 --- a/templates/launch.html +++ b/templates/launch.html @@ -4,7 +4,7 @@

Launch a survey

-
+
@@ -75,6 +75,15 @@

Required Data

+
+ + + + + +
+ +

Runner Data

@@ -243,10 +252,28 @@

Business Survey Metadata

document.getElementById(el_id).value = result; } + function setResponseExpiry(days_offset=7) { + var dt = new Date(); + dt.setDate(dt.getDate()+days_offset) + document.getElementById('response_expires_at').value=dt.toISOString().replace(/(\.\d*)/, '').replace(/Z/, '+00:00'); + } + + function validateForm() { + validateResponseExpiresAt(); + } + + function validateResponseExpiresAt() { + response_expires_at = Date.parse(document.getElementById('response_expires_at').value) + if (isNaN(response_expires_at)) { + document.getElementById('response_expires_at').remove() + } + } + uuid('collection_exercise_sid'); uuid('case_id'); ruref('ru_ref'); numericId('response_id'); + setResponseExpiry();