Fixed suborg zIndex, execution debugging, Oauth2 view and SDK updates

This commit is contained in:
frikky
2021-10-13 02:28:46 +02:00
parent 7159bf207c
commit 1632a03753
15 changed files with 307 additions and 196 deletions
+6 -3
View File
@@ -350,7 +350,7 @@ const Header = props => {
handleClose()
handleClickLogout()
}}>
<MeetingRoomIcon /> Logout
<MeetingRoomIcon /> &nbsp;Logout
</MenuItem>
</Menu>
</span>
@@ -455,7 +455,10 @@ const Header = props => {
}}
value={userdata.active_org.id}
fullWidth
style={{marginTop: 5, backgroundColor: theme.palette.surfaceColor, marginRight: 15, color: "white", height: 50, width: 200}}
style={{zIndex: 10012, marginTop: 5, backgroundColor: theme.palette.surfaceColor, marginRight: 15, color: "white", height: 50, width: 200}}
MenuProps={{
style: {zIndex: 10012}
}}
onChange={(e) => {
handleClickChangeOrg(e.target.value)
}}
@@ -473,7 +476,7 @@ const Header = props => {
<img alt={data.name} src={data.image} style={imageStyle} />
return (
<MenuItem key={index} disabled={data.id === userdata.active_org.id} style={{backgroundColor: theme.palette.inputColor, color: "white"}} value={data.id}>
<MenuItem key={index} disabled={data.id === userdata.active_org.id} style={{backgroundColor: theme.palette.inputColor, color: "white", zIndex: 10013,}} value={data.id}>
<Tooltip color="primary" title={`Suborg of ${data.creator_org}`} placement="left">
<div style={{display: "flex"}}>
+94 -16
View File
@@ -13,9 +13,10 @@ const AuthenticationOauth2 = (props) => {
const [defaultConfigSet, setDefaultConfigSet] = React.useState(authenticationType.client_id !== undefined && authenticationType.client_id !== null && authenticationType.client_id.length > 0 && authenticationType.client_secret !== undefined && authenticationType.client_secret !== null && authenticationType.client_secret.length > 0)
const [clientId, setClientId] = React.useState(defaultConfigSet ? authenticationType.client_id : "")
const [clientSecret, setClientSecret] = React.useState(defaultConfigSet ? authenticationType.client_secret : "")
const [oauthUrl, setOauthUrl] = React.useState("")
const [buttonClicked, setButtonClicked] = React.useState(false)
const [manuallyConfigure, setManuallyConfigure] = React.useState(false)
const [manuallyConfigure, setManuallyConfigure] = React.useState(defaultConfigSet ? false : true)
const [authenticationOption, setAuthenticationOptions] = React.useState({
app: JSON.parse(JSON.stringify(selectedApp)),
fields: {},
@@ -31,7 +32,7 @@ const AuthenticationOauth2 = (props) => {
return null
}
const handleOauth2Request = (client_id, client_secret) => {
const handleOauth2Request = (client_id, client_secret, oauth_url) => {
setButtonClicked(true)
//if (authenticationType.type === "oauth2" && authenticationType.redirect_uri !== undefined && authenticationType.redirect_uri !== null) {
// These are test credentials
@@ -40,17 +41,26 @@ const AuthenticationOauth2 = (props) => {
const authentication_url = authenticationType.token_uri
const resources = "UserAuthenticationMethod.ReadWrite.All"
var resources = ""
console.log("SCOPES: ", resources)
if (authenticationType.scope !== undefined && authenticationType.scope !== null) {
console.log("EDIT SCOPE!")
resources = authenticationType.scope.join(",")
}
console.log(window.location)
//const isCloud = window.location.host === "localhost:3002" || window.location.host === "shuffler.io"
const redirectUri = `${window.location.protocol}//${window.location.host}/set_authentication`
const state = `workflow_id%3D${workflow.id}%26reference_action_id%3d${selectedAction.app_id}%26app_name%3d${selectedAction.app_name}%26app_id%3d${selectedAction.app_id}%26app_version%3d${selectedAction.app_version}%26authentication_url%3d${authentication_url}%26scope%3d${resources}%26client_id%3d${client_id}%26client_secret%3d${client_secret}`
resources = ["AaaServer.profile.READ"]
const url = `${authenticationType.redirect_uri}?client_id=${client_id}&redirect_uri=${redirectUri}&response_type=code&scope=${resources}&state=${state}`
console.log("SCOPES2: ", resources)
const redirectUri = `${window.location.protocol}//${window.location.host}/set_authentication`
var state = `workflow_id%3D${workflow.id}%26reference_action_id%3d${selectedAction.app_id}%26app_name%3d${selectedAction.app_name}%26app_id%3d${selectedAction.app_id}%26app_version%3d${selectedAction.app_version}%26authentication_url%3d${authentication_url}%26scope%3d${resources}%26client_id%3d${client_id}%26client_secret%3d${client_secret}`
if (oauth_url !== undefined && oauth_url !== null && oauth_url.length > 0) {
state += `%26oauth_url%3d${oauth_url}`
console.log("ADDING OAUTH2 URL: ", state)
}
const url = `${authenticationType.redirect_uri}?client_id=${client_id}&redirect_uri=${redirectUri}&response_type=code&scope=${resources}&prompt=consent&state=${state}`
//const url = `https://accounts.zoho.com/oauth/v2/auth?response_type=code&client_id=${client_id}&scope=AaaServer.profile.Read&redirect_uri=${redirectUri}&prompt=consent`
console.log("Full URI: ", url)
console.log("Redirect Uri: ", redirectUri)
// &resource=https%3A%2F%2Fgraph.microsoft.com&
// FIXME: Awful, but works for prototyping
@@ -64,14 +74,11 @@ const AuthenticationOauth2 = (props) => {
var open = true
const timer = setInterval(() => {
if (newwin.closed) {
setButtonClicked(false)
clearInterval(timer);
//alert('"Secure Payment" window closed!');
getAppAuthentication(true, true)
setTimeout(() => {
console.log("APPAUTH: ", appAuthentication)
setAuthenticationModalOpen(false)
}, 1500)
}
}, 1000);
//do {
@@ -206,6 +213,75 @@ const AuthenticationOauth2 = (props) => {
{!manuallyConfigure ? null :
<span>
{selectedApp.authentication.parameters.map((data, index) => {
//console.log(data, index)
if (data.name === "client_id" || data.name === "client_secret") {
return null
}
if (data.name !== "url") {
return null
}
if (oauthUrl.length === 0) {
setOauthUrl(data.value)
}
return (
<div key={index} style={{marginTop: 10}}>
<LockOpenIcon style={{marginRight: 10}}/>
<b>{data.name}</b>
{data.schema !== undefined && data.schema !== null && data.schema.type === "bool" ?
<Select
SelectDisplayProps={{
style: {
marginLeft: 10,
}
}}
defaultValue={"false"}
fullWidth
onChange={(e) => {
console.log("Value: ", e.target.value)
authenticationOption.fields[data.name] = e.target.value
}}
style={{backgroundColor: theme.palette.surfaceColor, color: "white", height: 50}}
>
<MenuItem key={"false"} style={{backgroundColor: theme.palette.inputColor, color: "white"}} value={"false"}>
false
</MenuItem>
<MenuItem key={"true"} style={{backgroundColor: theme.palette.inputColor, color: "white"}} value={"true"}>
true
</MenuItem>
</Select>
:
<TextField
style={{backgroundColor: theme.palette.inputColor, borderRadius: theme.palette.borderRadius,}}
InputProps={{
style:{
color: "white",
marginLeft: "5px",
maxWidth: "95%",
height: 50,
fontSize: "1em",
},
}}
fullWidth
type={data.example !== undefined && data.example.includes("***") ? "password" : "text"}
color="primary"
defaultValue={data.value !== undefined && data.value !== null ? data.value : ""}
placeholder={data.example}
onChange={(event) => {
authenticationOption.fields[data.name] = event.target.value
console.log("Setting oauth url")
setOauthUrl(event.target.value)
//const [oauthUrl, setOauthUrl] = React.useState("")
}}
/>
}
</div>
)
})}
<TextField
style={{marginTop: 20, backgroundColor: theme.palette.inputColor, borderRadius: theme.palette.borderRadius,}}
InputProps={{
@@ -248,12 +324,12 @@ const AuthenticationOauth2 = (props) => {
}
<Button
style={{marginBottom: 40, marginTop: 20, borderRadius: theme.palette.borderRadius}}
disabled={clientSecret.length === 0 || clientId.length === 0}
disabled={clientSecret.length === 0 || clientId.length === 0 || buttonClicked}
variant="contained"
fullWidth
onClick={() => {
//setAuthenticationModalOpen(false)
handleOauth2Request(clientId, clientSecret)
handleOauth2Request(clientId, clientSecret, oauthUrl)
}}
color="primary"
>
@@ -287,7 +363,9 @@ const AuthenticationOauth2 = (props) => {
{manuallyConfigure ? "Use auto-config" : "Manually configure Oauth2"}
</Button>
</span>
: null}
:
null
}
</DialogContent>
</div>
)
+14 -7
View File
@@ -1227,6 +1227,7 @@ const AngularWorkflow = (props) => {
if (selectedApp.authentication.required) {
//console.log("App requires auth!!")
// Setup auth here :)
var appUpdates = false
const authenticationOptions = []
var findAuthId = ""
if (selectedAction.authentication_id !== null && selectedAction.authentication_id !== undefined && selectedAction.authentication_id.length > 0) {
@@ -1261,6 +1262,7 @@ const AngularWorkflow = (props) => {
console.log("Setting auth at: ", workflow.actions[key], item.id)
workflow.actions[key].selectedAuthentication = item
workflow.actions[key].authentication_id = item.id
appUpdates = true
//if (workflow.actions[key].selectedAuthentication === undefined || workflow.actions[key].selectedAuthentication === null || workflow.actions[key].selectedAuthentication.length === 0) {
// console.log("Setting inner auth: ", workflow.actions[key])
//}
@@ -1282,12 +1284,16 @@ const AngularWorkflow = (props) => {
selectedAction.selectedAuthentication = {}
}
setSelectedAction(selectedAction)
setWorkflow(workflow)
saveWorkflow(workflow)
//for (var key in
alert.info("Added and updated authentication!")
if (appUpdates === true) {
setAuthenticationModalOpen(false)
setSelectedAction(selectedAction)
setWorkflow(workflow)
saveWorkflow(workflow)
alert.info("Added and updated authentication!")
} else {
alert.error("Failed to find new authentication - did it work?")
}
} else {
alert.info("No authentication to update")
}
@@ -2098,6 +2104,7 @@ const AngularWorkflow = (props) => {
{
"type": "oauth2",
"redirect_uri": curapp.authentication.redirect_uri,
"refresh_uri": curapp.authentication.refresh_uri,
"token_uri": curapp.authentication.token_uri,
"scope": curapp.authentication.scope,
"client_id": curapp.authentication.client_id,
@@ -2946,7 +2953,7 @@ const AngularWorkflow = (props) => {
//console.log(event.keyCode)
switch( event.keyCode ) {
case 27:
console.log("ESCAPE")
//console.log("ESCAPE")
if (configureWorkflowModalOpen === true) {
setConfigureWorkflowModalOpen(false)
}
@@ -9271,7 +9278,7 @@ const AngularWorkflow = (props) => {
// This whole part is redundant. Made it part of Arguments instead.
console.log(selectedApp)
//console.log(selectedApp)
const authenticationModal = authenticationModalOpen ?
<Dialog
open={authenticationModalOpen}
+70 -19
View File
@@ -202,7 +202,7 @@ const AppCreator = (props) => {
const actionNonBodyRequest = ["GET", "HEAD", "DELETE", "CONNECT"]
const actionBodyRequest = ["POST", "PUT", "PATCH",]
//const authenticationOptions = ["No authentication", "API key", "Bearer auth", "Basic auth", "JWT", "Oauth2"]
const authenticationOptions = ["No authentication", "API key", "Bearer auth", "Basic auth"]//, "Oauth2"]
const authenticationOptions = ["No authentication", "API key", "Bearer auth", "Basic auth", "Oauth2"]
const apikeySelection = ["Header", "Query",]
const [name, setName] = useState("");
@@ -222,7 +222,7 @@ const AppCreator = (props) => {
const [parameterName, setParameterName] = useState("");
const [parameterLocation, setParameterLocation] = useState(apikeySelection.length > 0 ? apikeySelection[0] : "");
const [refreshUrl, setRefreshUrl] = useState("");
const [oauth2Scopes, setOauth2Scopes] = useState(["google.com"]);
const [oauth2Scopes, setOauth2Scopes] = useState(["OAUTH2.SCOPE.HERE"]);
const [projectCategories, setProjectCategories] = useState([]);
const [selectedCategory, setSelectedCategory] = useState("");
@@ -949,6 +949,10 @@ const AppCreator = (props) => {
if (value.flow.authorizationCode.refreshUrl !== undefined) {
setRefreshUrl(value.flow.authorizationCode.refreshUrl)
}
if (value.flow.authorizationCode.scopes !== undefined && value.flow.authorizationCode.scopes !== null && value.flow.authorizationCode.scopes.length > 0) {
setOauth2Scopes(value.flow.authorizationCode.scopes)
}
} else if (key === "ApiKeyAuth") {
setAuthenticationOption("API key")
@@ -1316,7 +1320,7 @@ const AppCreator = (props) => {
data.paths[item.url][item.method.toLowerCase()].parameters.push(newitem)
} else {
console.log("Nothing to append?")
//console.log("Nothing to append?")
}
// https://swagger.io/docs/specification/describing-request-body/file-upload/
@@ -1438,17 +1442,19 @@ const AppCreator = (props) => {
"authorizationUrl": newparamName,
"tokenUrl": parameterLocation,
"refreshUrl": refreshUrl,
"scopes": [],
"scopes": oauth2Scopes === undefined || oauth2Scopes === null ? [] : oauth2Scopes,
},
},
}
if (oauth2Scopes.scopes > 0) {
for (var key in oauth2Scopes) {
const scope = oauth2Scopes[key]
data.components.securitySchemes["Oauth2"]["flow"]["authorizationCode"]["scopes"].push(scope)
}
}
console.log("SCOPES: ", oauth2Scopes)
//if (oauth2Scopes.scopes > 0) {
// for (var key in oauth2Scopes) {
// const scope = oauth2Scopes[key]
// data.components.securitySchemes["Oauth2"]["flow"]["authorizationCode"]["scopes"].push(scope)
// }
//}
}
if (setExtraAuth.length > 0) {
@@ -1747,12 +1753,12 @@ const AppCreator = (props) => {
const oauth2Auth = authenticationOption === "Oauth2" ?
<div style={{color: "white", marginTop: 20, }}>
<Typography variant="body1">Oauth2 authentication</Typography>
<Typography variant="body2" color="textSecondary">
<Typography variant="body2" color="textSecondary" style={{marginTop: 10,}}>
Base Authorization URL
</Typography>
<TextField
required
style={{flex: "1", backgroundColor: inputColor}}
style={{margin: 0, flex: "1", backgroundColor: inputColor}}
fullWidth={true}
placeholder="https://.../oauth2/authorize"
type="name"
@@ -1770,12 +1776,12 @@ const AppCreator = (props) => {
},
}}
/>
<Typography variant="body2" color="textSecondary">
<Typography variant="body2" color="textSecondary" style={{marginTop: 10,}}>
Token URL
</Typography>
<TextField
required
style={{flex: "1", backgroundColor: inputColor}}
style={{margin: 0, flex: "1", backgroundColor: inputColor}}
fullWidth={true}
placeholder="https://.../oauth2/token"
type="name"
@@ -1793,11 +1799,11 @@ const AppCreator = (props) => {
},
}}
/>
<Typography variant="body2" color="textSecondary">
<Typography variant="body2" color="textSecondary" style={{marginTop: 10,}}>
Refresh-token URL
</Typography>
<TextField
style={{flex: "1", backgroundColor: inputColor}}
style={{margin: 0, flex: "1", backgroundColor: inputColor}}
fullWidth={true}
placeholder="The URL to retrieve refresh-tokens at"
type="name"
@@ -1812,6 +1818,31 @@ const AppCreator = (props) => {
},
}}
/>
<Typography variant="body2" color="textSecondary" style={{marginTop: 10,}}>
Scopes
</Typography>
<ChipInput
style={{}}
InputProps={{
style:{
color: "white",
},
}}
placeholder="Scopes"
color="primary"
fullWidth
defaultValue={oauth2Scopes}
onAdd={(chip) => {
oauth2Scopes.push(chip)
console.log(oauth2Scopes)
setOauth2Scopes(oauth2Scopes)
}}
onDelete={(chip, index) => {
oauth2Scopes.splice(index, 1)
console.log(oauth2Scopes)
setOauth2Scopes(oauth2Scopes)
}}
/>
</div>
: null
@@ -2429,26 +2460,46 @@ const AppCreator = (props) => {
}}
onBlur={event => {
var parsedurl = event.target.value
console.log("URL: ", parsedurl)
//console.log("URL: ", parsedurl)
if (parsedurl.includes(" ")) {
parsedurl = parsedurl.replaceAll(" ", " ")
}
if (parsedurl.includes(" ")) {
parsedurl = parsedurl.replaceAll(" ", " ")
}
if (parsedurl.includes("[") && parsedurl.includes("]")) {
//console.log("REPLACE1")
parsedurl = parsedurl.replaceAll("[", "{")
parsedurl = parsedurl.replaceAll("]", "}")
}
if (parsedurl.includes("<") && parsedurl.includes(">")) {
console.log("REPLACE")
//console.log("REPLACE2")
parsedurl = parsedurl.replaceAll("<", "{")
parsedurl = parsedurl.replaceAll(">", "}")
}
//console.log("URL2: ", parsedurl)
if (parsedurl.startsWith("PUT ") || parsedurl.startsWith("GET ") ||parsedurl.startsWith("POST ") || parsedurl.startsWith("DELETE ") ||parsedurl.startsWith("PATCH ") || parsedurl.startsWith("CONNECT ")) {
const tmp = parsedurl.split(" ")
if (tmp.length > 1) {
parsedurl = tmp[1]
parsedurl = tmp[1].trim()
setActionField("url", parsedurl)
setCurrentActionMethod(tmp[0].toUpperCase())
setActionField("method", tmp[0].toUpperCase())
}
console.log("URL3: ", parsedurl)
setUpdate(Math.random())
} else if (parsedurl.startsWith("curl")) {
console.log("URL4: ", parsedurl)
const request = parseCurl(event.target.value)
if (request !== event.target.value && request.method !== undefined && request.method !== null) {
if (request.method.toUpperCase() !== currentAction.Method) {
+9 -5
View File
@@ -480,7 +480,7 @@ const Apps = (props) => {
color: "white",
borderRadius: 5,
backgroundColor: surfaceColor,
display: "flex",
//display: "flex",
marginBottom: 10,
overflow: "hidden",
}
@@ -522,7 +522,7 @@ const Apps = (props) => {
<Link to={editUrl} style={{textDecoration: "none"}}>
<Tooltip title={"Edit OpenAPI app"}>
<Button
variant="outlined"
variant="contained"
component="label"
color="primary"
style={{marginTop: 10, marginRight: 10,}}
@@ -700,8 +700,8 @@ const Apps = (props) => {
{activateButton}
{(props.userdata !== undefined && (props.userdata.role === "admin" || props.userdata.id === selectedApp.owner) || !selectedApp.generated) ?
<div>
{downloadButton}
{editButton}
{downloadButton}
{deleteButton}
</div>
: null}
@@ -977,31 +977,35 @@ const Apps = (props) => {
</div>
{isCloud ? null :
<span>
{isLoading ? null :
<Tooltip title={"Reload apps locally"} style={{marginTop: "28px", width: "100%"}} aria-label={"Upload"}>
<Button
variant="outlined"
component="label"
color="primary"
style={{margin: 5, maxHeight: 50, marginTop: 10}}
disabled={isLoading}
onClick={() => {
hotloadApps()
}}
>
<CachedIcon />
{isLoading ? <CircularProgress size={25} /> : <CachedIcon />}
</Button>
</Tooltip>
}
<Tooltip title={"Download from Github"} style={{marginTop: "28px", width: "100%"}} aria-label={"Upload"}>
<Button
variant="outlined"
component="label"
color="primary"
style={{margin: 5, maxHeight: 50, marginTop: 10}}
disabled={isLoading}
onClick={() => {
setOpenApi(baseRepository)
setLoadAppsModalOpen(true)
}}
>
<CloudDownloadIcon />
{isLoading ? <CircularProgress size={25} /> : <CloudDownloadIcon />}
</Button>
</Tooltip>
</span>
+14 -14
View File
@@ -139,7 +139,7 @@ const Docs = (props) => {
parsedline[1] = parsedline[1].replaceAll(")", "")
parsedline[1] = parsedline[1].replaceAll("(", "")
parsedline[1] = parsedline[1].trim()
console.log(parsedline[0], parsedline[1])
//console.log(parsedline[0], parsedline[1])
innerTocLines.push({
"text": parsedline[0],
@@ -205,12 +205,12 @@ const Docs = (props) => {
// Fix location..
if (element.innerHTML.toLowerCase() === name) {
console.log(element.offsetTop)
//element.scrollIntoView({behavior: "smooth"})
element.scrollTo({
top: element.offsetTop+offset,
behavior: "smooth"
})
//console.log(element.offsetTop)
element.scrollIntoView({behavior: "smooth"})
//element.scrollTo({
// top: element.offsetTop+offset,
// behavior: "smooth"
//})
found = true
//element.scrollTo({
// top: element.offsetTop-100,
@@ -222,7 +222,7 @@ const Docs = (props) => {
// H#
if (!found) {
elements = parent.getElementsByTagName('h3')
console.log(name)
//console.log("NAMe: ", name)
found = false
for (key in elements) {
const element = elements[key]
@@ -232,11 +232,11 @@ const Docs = (props) => {
// Fix location..
if (element.innerHTML.toLowerCase() === name) {
//element.scrollIntoView({behavior: "smooth"})
element.scrollTo({
top: element.offsetTop-offset,
behavior: "smooth"
})
element.scrollIntoView({behavior: "smooth"})
//element.scrollTo({
// top: element.offsetTop-offset,
// behavior: "smooth"
//})
found = true
//element.scrollTo({
// top: element.offsetTop-100,
@@ -392,7 +392,7 @@ const Docs = (props) => {
{itemMatching && tocLines !== null && tocLines !== undefined && tocLines.length > 0 ?
<div style={{marginLeft: 5}}>
{tocLines.map((data, index) => {
console.log(data)
//console.log(data)
return (
<Link key={index} style={innerHrefStyle} to={data.link} onClick={() => {}}>
+4
View File
@@ -91,6 +91,10 @@ const SetAuthentication = (props) => {
if (query[0] === "client_secret") {
appAuthData.fields.push({"key": "client_secret", "value": query[1]})
}
if (query[0] === "oauth_url") {
appAuthData.fields.push({"key": "oauth_url", "value": query[1]})
}
}
}