#26: Fixed frontend app authentication issues
This commit is contained in:
+87
-48
@@ -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",
|
||||
},
|
||||
|
||||
@@ -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{
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -1016,11 +1016,13 @@ const Admin = (props) => {
|
||||
<Tab label="Environments"/>
|
||||
<Tab label="Schedules"/>
|
||||
</Tabs>
|
||||
<div style={{marginBottom: 10}}/>
|
||||
{authenticationView}
|
||||
{usersView}
|
||||
{environmentView}
|
||||
{schedulesView}
|
||||
<Divider style={{marginTop: 0, marginBottom: 10, backgroundColor: "rgb(91, 96, 100)"}} />
|
||||
<div style={{padding: 15}}>
|
||||
{authenticationView}
|
||||
{usersView}
|
||||
{environmentView}
|
||||
{schedulesView}
|
||||
</div>
|
||||
</Paper>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -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
|
||||
<div style={{display: "flex"}}>
|
||||
<Select
|
||||
labelId="select-app-auth"
|
||||
value={selectedAction.selectedAuthentication}
|
||||
SelectDisplayProps={{
|
||||
style: {
|
||||
@@ -5464,6 +5467,7 @@ const AngularWorkflow = (props) => {
|
||||
})
|
||||
}
|
||||
|
||||
console.log("FIELDS: ", newFields)
|
||||
newAuthOption.fields = newFields
|
||||
setNewAppAuth(newAuthOption)
|
||||
}
|
||||
@@ -5472,10 +5476,10 @@ const AngularWorkflow = (props) => {
|
||||
<div>
|
||||
<DialogContent>
|
||||
<a href="https://shuffler.io/docs/apps#authentication" style={{textDecoration: "none", color: "#f85a3e"}}>What is this?</a>
|
||||
These are required fields for authenticating with {selectedApp.name}
|
||||
- These are required fields for authenticating with {selectedApp.name}
|
||||
<div style={{marginTop: 15}}/>
|
||||
{selectedApp.link.length > 0 ? <EndpointData /> : null}
|
||||
Label (to remember it)
|
||||
<b>Label (to remember it)</b>
|
||||
<TextField
|
||||
style={{backgroundColor: inputColor}}
|
||||
InputProps={{
|
||||
@@ -5494,12 +5498,13 @@ const AngularWorkflow = (props) => {
|
||||
authenticationOption.label = event.target.value
|
||||
}}
|
||||
/>
|
||||
<Divider style={{marginTop: 15, marginBottom: 15}}/>
|
||||
<Divider style={{marginTop: 15, marginBottom: 15, backgroundColor: "rgb(91, 96, 100)"}}/>
|
||||
<div style={{}}/>
|
||||
{selectedApp.authentication.parameters.map((data, index) => {
|
||||
return (
|
||||
<div key={index} style={{marginTop: 10}}>
|
||||
{data.name}
|
||||
<LockOpenIcon style={{marginRight: 10}}/>
|
||||
<b>{data.name}</b>
|
||||
<TextField
|
||||
style={{backgroundColor: inputColor}}
|
||||
InputProps={{
|
||||
|
||||
Reference in New Issue
Block a user