Skip to content

Commit

Permalink
Merge pull request #4 from ONSdigital/master
Browse files Browse the repository at this point in the history
Adds launcher parameters for adding JWT claim `response_expires_at`
  • Loading branch information
pricem14pc authored Nov 22, 2021
2 parents 077cff3 + ad6dca0 commit f2eabde
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 2 additions & 0 deletions launch.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main // import "github.com/ONSdigital/eq-questionnaire-launcher"

import (
"fmt"
"time"

"html/template"
"log"
Expand Down Expand Up @@ -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 != "" {
Expand Down
29 changes: 28 additions & 1 deletion templates/launch.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<h1>Launch a survey</h1>
<div class="field-wrap">

<form action="" method="POST" xmlns="http://www.w3.org/1999/html">
<form action="" method="POST" xmlns="http://www.w3.org/1999/html" onsubmit="validateForm()">

<div class="field-container">
<label for="schema_name">Schemas</label>
Expand Down Expand Up @@ -75,6 +75,15 @@ <h3>Required Data</h3>
</span>
</div>

<div class="field-container">
<label for="response_expires_at">Response Expiry Time</label>
<span>
<input id="response_expires_at" name="response_expires_at" type="text" class="qa-response-expires-at">
<img onclick="setResponseExpiry()" src="data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/PjwhRE9DVFlQRSBzdmcgIFBVQkxJQyAnLS8vVzNDLy9EVEQgU1ZHIDEuMS8vRU4nICAnaHR0cDovL3d3dy53My5vcmcvR3JhcGhpY3MvU1ZHLzEuMS9EVEQvc3ZnMTEuZHRkJz48c3ZnIGhlaWdodD0iNTEycHgiIGlkPSJMYXllcl8xIiBzdHlsZT0iZW5hYmxlLWJhY2tncm91bmQ6bmV3IDAgMCA1MTIgNTEyOyIgdmVyc2lvbj0iMS4xIiB2aWV3Qm94PSIwIDAgNTEyIDUxMiIgd2lkdGg9IjUxMnB4IiB4bWw6c3BhY2U9InByZXNlcnZlIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIj48Zz48cGF0aCBkPSJNMjU2LDM4NC4xYy03MC43LDAtMTI4LTU3LjMtMTI4LTEyOC4xYzAtNzAuOCw1Ny4zLTEyOC4xLDEyOC0xMjguMVY4NGw5Niw2NGwtOTYsNTUuN3YtNTUuOCAgIGMtNTkuNiwwLTEwOC4xLDQ4LjUtMTA4LjEsMTA4LjFjMCw1OS42LDQ4LjUsMTA4LjEsMTA4LjEsMTA4LjFTMzY0LjEsMzE2LDM2NC4xLDI1NkgzODRDMzg0LDMyNywzMjYuNywzODQuMSwyNTYsMzg0LjF6Ii8+PC9nPjwvc3ZnPg==">
</span>
</div>


<h3>Runner Data</h3>
<div class="field-container">
<label for="exp">Token Expiry (seconds)</label>
Expand Down Expand Up @@ -243,10 +252,28 @@ <h3>Business Survey Metadata</h3>
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();

</script>

Expand Down

0 comments on commit f2eabde

Please sign in to comment.