From cdfd2a52aea66d5230be2cefea2daa64e9406b4d Mon Sep 17 00:00:00 2001 From: frikky Date: Fri, 17 Jul 2020 08:35:48 +0200 Subject: [PATCH] #26: Fixed frontend app authentication issues --- backend/go-app/codegen.go | 135 ++++++++++++++++++++------------ backend/go-app/main.go | 2 +- backend/go-app/walkoff.go | 5 +- frontend/src/Admin.js | 12 +-- frontend/src/AngularWorkflow.js | 75 +++++++++--------- 5 files changed, 138 insertions(+), 91 deletions(-) diff --git a/backend/go-app/codegen.go b/backend/go-app/codegen.go index 57576fd5..90d5c6b3 100644 --- a/backend/go-app/codegen.go +++ b/backend/go-app/codegen.go @@ -398,8 +398,6 @@ func makePythoncode(swagger *openapi3.Swagger, name, url, method string, paramet verifyAddin, ) - //log.Println(data) - //log.Println(functionname) return functionname, data } @@ -459,76 +457,105 @@ func generateYaml(swagger *openapi3.Swagger, newmd5 string) (*openapi3.Swagger, //log.Printf("%#v", securitySchemes) api.Authentication = Authentication{ - Required: true, - Parameters: []AuthenticationParams{ - AuthenticationParams{ - Multiline: false, - Required: true, - }, - }, + Required: true, + Parameters: []AuthenticationParams{}, } // Used for python code generation lol // Not sure how this should work with oauth if securitySchemes["BearerAuth"] != nil { - api.Authentication.Parameters[0].Value = "BearerAuth" - api.Authentication.Parameters[0].Description = securitySchemes["BearerAuth"].Value.Description - api.Authentication.Parameters[0].Name = securitySchemes["BearerAuth"].Value.Name - api.Authentication.Parameters[0].In = securitySchemes["BearerAuth"].Value.In - api.Authentication.Parameters[0].Schema.Type = securitySchemes["BearerAuth"].Value.Scheme - api.Authentication.Parameters[0].Scheme = securitySchemes["BearerAuth"].Value.Scheme + api.Authentication.Parameters = append(api.Authentication.Parameters, AuthenticationParams{ + Name: "apikey", + Value: "", + Example: "******", + Description: securitySchemes["BearerAuth"].Value.Description, + In: securitySchemes["BearerAuth"].Value.In, + Scheme: securitySchemes["BearerAuth"].Value.Scheme, + Schema: SchemaDefinition{ + Type: securitySchemes["BearerAuth"].Value.Scheme, + }, + }) + //log.Printf("HANDLE BEARER AUTH") extraParameters = append(extraParameters, WorkflowAppActionParameter{ - Name: "apikey", - Description: "The apikey to use", - Multiline: false, - Required: true, - Example: "The API key to use. Space = skip", + Name: "apikey", + Description: "The apikey to use", + Multiline: false, + Required: true, + Example: "The API key to use. Space = skip", + Configuration: true, Schema: SchemaDefinition{ Type: "string", }, }) } else if securitySchemes["ApiKeyAuth"] != nil { - api.Authentication.Parameters[0].Value = "ApiKeyAuth" - api.Authentication.Parameters[0].Description = securitySchemes["ApiKeyAuth"].Value.Description - api.Authentication.Parameters[0].Name = securitySchemes["ApiKeyAuth"].Value.Name - api.Authentication.Parameters[0].In = securitySchemes["ApiKeyAuth"].Value.In - api.Authentication.Parameters[0].Schema.Type = securitySchemes["ApiKeyAuth"].Value.Scheme - api.Authentication.Parameters[0].Scheme = securitySchemes["ApiKeyAuth"].Value.Scheme + api.Authentication.Parameters = append(api.Authentication.Parameters, AuthenticationParams{ + Name: "apikey", + Value: "", + Example: "******", + Description: securitySchemes["ApiKeyAuth"].Value.Description, + In: securitySchemes["ApiKeyAuth"].Value.In, + Scheme: securitySchemes["ApiKeyAuth"].Value.Scheme, + Schema: SchemaDefinition{ + Type: securitySchemes["ApiKeyAuth"].Value.Scheme, + }, + }) + //log.Printf("HANDLE APIKEY AUTH") extraParameters = append(extraParameters, WorkflowAppActionParameter{ - Name: "apikey", - Description: "The apikey to use", - Multiline: false, - Required: true, - Example: "**********", + Name: "apikey", + Description: "The apikey to use", + Multiline: false, + Required: true, + Example: "**********", + Configuration: true, Schema: SchemaDefinition{ Type: "string", }, }) } else if securitySchemes["BasicAuth"] != nil { - api.Authentication.Parameters[0].Value = "BasicAuth" - api.Authentication.Parameters[0].Description = securitySchemes["BasicAuth"].Value.Description - api.Authentication.Parameters[0].Name = securitySchemes["BasicAuth"].Value.Name - api.Authentication.Parameters[0].In = securitySchemes["BasicAuth"].Value.In - api.Authentication.Parameters[0].Schema.Type = securitySchemes["BasicAuth"].Value.Scheme - api.Authentication.Parameters[0].Scheme = securitySchemes["BasicAuth"].Value.Scheme - extraParameters = append(extraParameters, WorkflowAppActionParameter{ + api.Authentication.Parameters = append(api.Authentication.Parameters, AuthenticationParams{ Name: "username", - Description: "The username to use", - Multiline: false, - Required: true, - Example: "The username to use", + Value: "", + Example: "username", + Description: securitySchemes["BasicAuth"].Value.Description, + In: securitySchemes["BasicAuth"].Value.In, + Scheme: securitySchemes["BasicAuth"].Value.Scheme, + Schema: SchemaDefinition{ + Type: securitySchemes["BasicAuth"].Value.Scheme, + }, + }) + + api.Authentication.Parameters = append(api.Authentication.Parameters, AuthenticationParams{ + Name: "password", + Value: "", + Example: "*****", + Description: securitySchemes["BasicAuth"].Value.Description, + In: securitySchemes["BasicAuth"].Value.In, + Scheme: securitySchemes["BasicAuth"].Value.Scheme, + Schema: SchemaDefinition{ + Type: securitySchemes["BasicAuth"].Value.Scheme, + }, + }) + + extraParameters = append(extraParameters, WorkflowAppActionParameter{ + Name: "username", + Description: "The username to use", + Multiline: false, + Required: true, + Example: "The username to use", + Configuration: true, Schema: SchemaDefinition{ Type: "string", }, }) extraParameters = append(extraParameters, WorkflowAppActionParameter{ - Name: "password", - Description: "The password to use", - Multiline: false, - Required: true, - Example: "***********", + Name: "password", + Description: "The password to use", + Multiline: false, + Required: true, + Example: "***********", + Configuration: true, Schema: SchemaDefinition{ Type: "string", }, @@ -538,11 +565,23 @@ func generateYaml(swagger *openapi3.Swagger, newmd5 string) (*openapi3.Swagger, // Adds a link parameter if it's not already defined if len(api.Link) == 0 { - extraParameters = append(extraParameters, WorkflowAppActionParameter{ + api.Authentication.Parameters = append(api.Authentication.Parameters, AuthenticationParams{ Name: "url", Description: "The URL of the app", Multiline: false, Required: true, + Example: "https://shuffler.io", + Schema: SchemaDefinition{ + Type: "string", + }, + }) + + extraParameters = append(extraParameters, WorkflowAppActionParameter{ + Name: "url", + Description: "The URL of the app", + Multiline: false, + Required: true, + Configuration: true, Schema: SchemaDefinition{ Type: "string", }, diff --git a/backend/go-app/main.go b/backend/go-app/main.go index 2c114a84..0b58ae5d 100644 --- a/backend/go-app/main.go +++ b/backend/go-app/main.go @@ -5954,7 +5954,7 @@ func verifySwagger(resp http.ResponseWriter, request *http.Request) { return } - log.Printf("Successfully uploaded ZIPFILE for %s", identifier) + log.Printf("Successfully stitched ZIPFILE for %s", identifier) // 4. Upload as cloud function - this apikey is specifically for cloud functions rofl //environmentVariables := map[string]string{ diff --git a/backend/go-app/walkoff.go b/backend/go-app/walkoff.go index e8d8bdf7..a42524aa 100644 --- a/backend/go-app/walkoff.go +++ b/backend/go-app/walkoff.go @@ -3445,7 +3445,8 @@ func addAppAuthentication(resp http.ResponseWriter, request *http.Request) { return } - if len(appAuth.App.ID) != 36 { + // Super basic check + if len(appAuth.App.ID) != 36 && len(appAuth.App.ID) != 32 { log.Printf("Bad ID for app: %s", appAuth.App.ID) resp.WriteHeader(409) resp.Write([]byte(fmt.Sprintf(`{"success": false, "reason": "App has to be defined"}`))) @@ -3530,7 +3531,7 @@ func getAppAuthentication(resp http.ResponseWriter, request *http.Request) { for _, auth := range allAuths { newAuthField := auth for index, _ := range auth.Fields { - newAuthField.Fields[index].Value = "" + newAuthField.Fields[index].Value = "auth placeholder (replaced during execution)" } newAuth = append(newAuth, newAuthField) diff --git a/frontend/src/Admin.js b/frontend/src/Admin.js index 6fce60d1..e60d14e0 100644 --- a/frontend/src/Admin.js +++ b/frontend/src/Admin.js @@ -1016,11 +1016,13 @@ const Admin = (props) => { -
- {authenticationView} - {usersView} - {environmentView} - {schedulesView} + +
+ {authenticationView} + {usersView} + {environmentView} + {schedulesView} +
diff --git a/frontend/src/AngularWorkflow.js b/frontend/src/AngularWorkflow.js index 2e316983..559b23c5 100644 --- a/frontend/src/AngularWorkflow.js +++ b/frontend/src/AngularWorkflow.js @@ -218,7 +218,7 @@ const AngularWorkflow = (props) => { alert.error("Failed to set app auth: "+responseJson.reason) } else { setAuthenticationModalOpen(false) - alert.success("Successfully saved workflow") + alert.success("Successfully saved new app auth") } }) .catch(error => { @@ -915,35 +915,39 @@ const AngularWorkflow = (props) => { setSelectedActionName(curaction.name) setRequiresAuthentication(curapp.authentication.required) - // Setup auth here :) - const authenticationOptions = [] - var findAuthId = "" - if (curaction.authentication_id !== null && curaction.authentication_id !== undefined && curaction.authentication_id.length > 0) { - findAuthId = curaction.authentication_id - } + if (curapp.authentication.required) { + // Setup auth here :) + const authenticationOptions = [] + var findAuthId = "" + if (curaction.authentication_id !== null && curaction.authentication_id !== undefined && curaction.authentication_id.length > 0) { + findAuthId = curaction.authentication_id + } - for (var key in appAuthentication) { - var item = appAuthentication[key] + var tmpAuth = JSON.parse(JSON.stringify(appAuthentication)) + for (var key in tmpAuth) { + var item = tmpAuth[key] - const newfields = {} - for (var filterkey in item.fields) { - if (item.fields[filterkey] !== undefined) { + const newfields = {} + for (var filterkey in item.fields) { + console.log(item.fields) newfields[item.fields[filterkey].key] = item.fields[filterkey].value } - } - item.fields = newfields - if (item.app.name === curapp.name) { - authenticationOptions.push(item) - if (item.id === findAuthId) { - curaction.selectedAuthentication = item + item.fields = newfields + if (item.app.name === curapp.name) { + authenticationOptions.push(item) + if (item.id === findAuthId) { + console.log("ITEM: ", item) + // Missing fields here? + curaction.selectedAuthentication = item + } } } - } - - curaction.authentication = authenticationOptions - if (curaction.selectedAuthentication === null || curaction.selectedAuthentication === undefined || curaction.selectedAuthentication.length === "") { - curaction.selectedAuthentication = {} + + curaction.authentication = authenticationOptions + if (curaction.selectedAuthentication === null || curaction.selectedAuthentication === undefined || curaction.selectedAuthentication.length === "") { + curaction.selectedAuthentication = {} + } } setSelectedApp(curapp) @@ -2585,15 +2589,13 @@ const AngularWorkflow = (props) => { data.variant = "STATIC_VALUE" } - if (!selectedAction.auth_not_required && selectedAction.selectedAuthentication !== undefined && selectedAction.selectedAuthentication.fields !== undefined) { - if (selectedAction.selectedAuthentication.fields[data.name] !== undefined) { - // FIXME - this should be skipped in the frontend - //selectedActionParameters[count].value = selectedAction.selectedAuthentication.fields[data.name] - //selectedAction.parameters[count].value = selectedAction.selectedAuthentication.fields[data.name] - //setSelectedAction(selectedAction) + if (!selectedAction.auth_not_required && selectedAction.selectedAuthentication !== undefined && selectedAction.selectedAuthentication.fields !== undefined && selectedAction.selectedAuthentication.fields[data.name] !== undefined) { + // This sets the placeholder in the frontend. (Replaced in backend) + selectedActionParameters[count].value = selectedAction.selectedAuthentication.fields[data.name] + selectedAction.parameters[count].value = selectedAction.selectedAuthentication.fields[data.name] + setSelectedAction(selectedAction) - return null - } + return null } var staticcolor = "inherit" @@ -3063,6 +3065,7 @@ const AngularWorkflow = (props) => { Authentication