diff --git a/authentication/auth.go b/authentication/auth.go index 518c28a8..6b648543 100644 --- a/authentication/auth.go +++ b/authentication/auth.go @@ -157,45 +157,6 @@ func getSurveyMetadataFromClaims(claimValues map[string][]string, data map[strin claims["survey_metadata"] = surveyMetadata } -func generateClaims(claimValues map[string][]string, launcherSchema surveys.LauncherSchema) (claims map[string]interface{}) { - - var roles []string - if rolesValues, ok := claimValues["roles"]; ok { - roles = rolesValues - } else { - roles = []string{"dumper"} - } - - claims = make(map[string]interface{}) - - claims["roles"] = roles - TxID, _ := uuid.NewV4() - claims["tx_id"] = TxID.String() - - for key, value := range claimValues { - if key != "roles" { - if value[0] != "" { - claims[key] = value[0] - } - } else { - claims[key] = value - } - } - if len(claimValues["form_type"]) > 0 && len(claimValues["eq_id"]) > 0 { - log.Println("Deleting schema name from claims") - delete(claims, "schema_name") - } else { - // When quicklaunching, schema_name will not be set, but launcherSchema will have the schema_name. - if len(claimValues["schema_name"]) == 0 && launcherSchema.Name != "" { - claims["schema_name"] = launcherSchema.Name - } - } - - log.Printf("Using claims: %s", claims) - - return claims -} - func generateClaimsV2(claimValues map[string][]string, schema QuestionnaireSchema) (claims map[string]interface{}) { var roles []string @@ -415,48 +376,6 @@ func getStringOrDefault(key string, values map[string][]string, defaultValue str return defaultValue } -// GenerateTokenFromDefaults coverts a set of DEFAULT values into a JWT -func GenerateTokenFromDefaults(schemaURL string, accountServiceURL string, accountServiceLogOutURL string, urlValues url.Values) (token string, error string) { - launcherSchema, validationError := launcherSchemaFromURL(schemaURL) - if validationError != "" { - return "", validationError - } - - urlValues["account_service_url"] = []string{accountServiceURL} - urlValues["account_service_log_out_url"] = []string{accountServiceLogOutURL} - claims := generateClaims(urlValues, launcherSchema) - - requiredMetadata, error := getRequiredSchemaMetadata(launcherSchema) - if error != "" { - return "", fmt.Sprintf("getRequiredSchemaMetadata failed err: %v", error) - } - - for _, metadata := range requiredMetadata { - if metadata.Validator == "boolean" { - claims[metadata.Name] = getBooleanOrDefault(metadata.Name, urlValues, false) - continue - } - claims[metadata.Name] = getStringOrDefault(metadata.Name, urlValues, metadata.Default) - } - - jwtClaims := GenerateJwtClaims() - for key, v := range jwtClaims { - claims[key] = v - } - - schemaClaims := getSchemaClaims(launcherSchema) - for key, v := range schemaClaims { - claims[key] = v - } - - token, tokenError := generateTokenFromClaims(claims) - if tokenError != nil { - return token, fmt.Sprintf("GenerateTokenFromDefaults failed err: %v", tokenError) - } - - return token, "" -} - // GenerateTokenFromDefaultsV2 coverts a set of DEFAULT values into a JWT func GenerateTokenFromDefaultsV2(schemaURL string, accountServiceURL string, urlValues url.Values) (token string, error string) { launcherSchema, validationError := launcherSchemaFromURL(schemaURL) @@ -551,7 +470,7 @@ func TransformSchemaParamsToName(postValues url.Values) string { } // GenerateTokenFromPost converts a set of POST values into a JWT -func GenerateTokenFromPost(postValues url.Values, launchVersion2 bool) (string, string) { +func GenerateTokenFromPost(postValues url.Values) (string, string) { log.Println("POST received: ", postValues) schemaName := TransformSchemaParamsToName(postValues) @@ -565,13 +484,7 @@ func GenerateTokenFromPost(postValues url.Values, launchVersion2 bool) (string, return "", fmt.Sprintf("getSchema failed err: %v", error) } - var claims map[string]interface{} - - if launchVersion2 { - claims = generateClaimsV2(postValues, schema) - } else { - claims = generateClaims(postValues, launcherSchema) - } + var claims = generateClaimsV2(postValues, schema) jwtClaims := GenerateJwtClaims() for key, v := range jwtClaims { diff --git a/launch.go b/launch.go index 824b3016..e4eb2476 100644 --- a/launch.go +++ b/launch.go @@ -153,11 +153,7 @@ func redirectURL(w http.ResponseWriter, r *http.Request) { token := "" err := "" - if launchVersion == "v2" { - token, err = authentication.GenerateTokenFromPost(r.PostForm, true) - } else { - token, err = authentication.GenerateTokenFromPost(r.PostForm, false) - } + token, err = authentication.GenerateTokenFromPost(r.PostForm) if err != "" { http.Error(w, err, 500) @@ -179,20 +175,11 @@ func redirectURL(w http.ResponseWriter, r *http.Request) { func quickLauncherHandler(w http.ResponseWriter, r *http.Request) { hostURL := settings.Get("SURVEY_RUNNER_URL") accountServiceURL := getAccountServiceURL(r) - AccountServiceLogOutURL := getAccountServiceURL(r) urlValues := r.URL.Query() schemaURL := urlValues.Get("schema_url") - version := urlValues.Get("version") - launchVersion2 := true defaultValues := authentication.GetDefaultValues() - if version == "" { - urlValues.Add("version", defaultValues["version"]) - } else if version == "v1" { - launchVersion2 = false - } else { - urlValues.Add("version", version) - } + urlValues.Add("version", defaultValues["version"]) log.Println("Quick launch request received", schemaURL) @@ -207,11 +194,7 @@ func quickLauncherHandler(w http.ResponseWriter, r *http.Request) { token := "" err := "" - if launchVersion2 { - token, err = authentication.GenerateTokenFromDefaultsV2(schemaURL, accountServiceURL, urlValues) - } else { - token, err = authentication.GenerateTokenFromDefaults(schemaURL, accountServiceURL, AccountServiceLogOutURL, urlValues) - } + token, err = authentication.GenerateTokenFromDefaultsV2(schemaURL, accountServiceURL, urlValues) if err != "" { http.Error(w, err, 400) diff --git a/static/javascript/launch.js b/static/javascript/launch.js index bdabf01a..501c711d 100644 --- a/static/javascript/launch.js +++ b/static/javascript/launch.js @@ -234,29 +234,14 @@ function showSubmitFlushButtons(show, justSubmit = false) { } function includeSurveyMetadataFields(schema_name, survey_type) { - let launchPattern = document.querySelector("#launch_pattern").value; - let eqIdValue = schema_name.split("_")[0]; let formTypeValue = schema_name.split("_").slice(1).join("_"); - if (launchPattern === "v1") { - document.querySelector("#survey_metadata_fields").innerHTML = - `