From c4a06c92b91847304953aa0fd61675af70b3db87 Mon Sep 17 00:00:00 2001 From: frikky Date: Tue, 24 Aug 2021 01:39:59 +0200 Subject: [PATCH] #168: Allow ability to switch between autoconfigure or not from oauth2 app --- frontend/src/components/Oauth2Auth.jsx | 132 +++++++++++++++---------- frontend/src/views/AngularWorkflow.jsx | 21 ++-- 2 files changed, 92 insertions(+), 61 deletions(-) diff --git a/frontend/src/components/Oauth2Auth.jsx b/frontend/src/components/Oauth2Auth.jsx index 2203a7a3..b2b06d75 100644 --- a/frontend/src/components/Oauth2Auth.jsx +++ b/frontend/src/components/Oauth2Auth.jsx @@ -10,9 +10,12 @@ const AuthenticationOauth2 = (props) => { const theme = useTheme(); //const [update, setUpdate] = React.useState("|") - const [clientId, setClientId] = React.useState("") - const [clientSecret, setClientSecret] = React.useState("") + 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 [buttonClicked, setButtonClicked] = React.useState(false) + + const [manuallyConfigure, setManuallyConfigure] = React.useState(false) const [authenticationOption, setAuthenticationOptions] = React.useState({ app: JSON.parse(JSON.stringify(selectedApp)), fields: {}, @@ -24,6 +27,10 @@ const AuthenticationOauth2 = (props) => { active: true, }) + if (selectedApp.authentication === undefined) { + return null + } + const handleOauth2Request = (client_id, client_secret) => { setButtonClicked(true) //if (authenticationType.type === "oauth2" && authenticationType.redirect_uri !== undefined && authenticationType.redirect_uri !== null) { @@ -81,13 +88,6 @@ const AuthenticationOauth2 = (props) => { //} while ( } - if (selectedApp.authentication === undefined) { - return null - } - - if (selectedApp.authentication.parameters === null || selectedApp.authentication.parameters === undefined || selectedApp.authentication.parameters.length === 0) { - return null - } authenticationOption.app.actions = [] @@ -172,7 +172,7 @@ const AuthenticationOauth2 = (props) => { Oauth2 requires a client ID and secret to authenticate. This is usually made in the remote system. - Learn more about Oauth2
+ Learn more about Oauth2 with Shuffle
{/* { /> */} - { - setClientId(event.target.value) - //authenticationOption.label = event.target.value - }} - /> - { - setClientSecret(event.target.value) - //authenticationOption.label = event.target.value - }} - /> + + {!manuallyConfigure ? null : + + { + setClientId(event.target.value) + //authenticationOption.label = event.target.value + }} + /> + { + setClientSecret(event.target.value) + //authenticationOption.label = event.target.value + }} + /> + + } + + {defaultConfigSet ? + + ... or + + + : null}
) diff --git a/frontend/src/views/AngularWorkflow.jsx b/frontend/src/views/AngularWorkflow.jsx index e63065df..a988ab6b 100644 --- a/frontend/src/views/AngularWorkflow.jsx +++ b/frontend/src/views/AngularWorkflow.jsx @@ -1172,7 +1172,7 @@ const AngularWorkflow = (props) => { if (updateAction === true) { //console.log("Should update authentication for selectedAction!!") - console.log(responseJson) + //console.log(responseJson) if (selectedApp.authentication.required) { //console.log("App requires auth!!") @@ -1184,7 +1184,7 @@ const AngularWorkflow = (props) => { } var tmpAuth = JSON.parse(JSON.stringify(responseJson.data)) - console.log("FOUND AUTH: ", tmpAuth) + //console.log("FOUND AUTH: ", tmpAuth) //console.log("Checking authentication: ", tmpAuth) var latest = 0 @@ -1211,8 +1211,7 @@ const AngularWorkflow = (props) => { //if (item.id === findAuthId) { // selectedAction.selectedAuthentication = item //} - - console.log("ACTION: ", selectedAction) + //console.log("ACTION: ", selectedAction) //console.log("OPTIONS: ", authenticationOptions) selectedAction.authentication = authenticationOptions @@ -2007,14 +2006,16 @@ const AngularWorkflow = (props) => { setSelectedAction(curaction) //return } else { - //console.log("AUTHENTICATION: ", curapp.authentication) - //console.log(curapp.authentication) + console.log("AUTHENTICATION: ", curapp.authentication) + console.log(curapp.authentication) setAuthenticationType(curapp.authentication.type === "oauth2" && curapp.authentication.redirect_uri !== undefined && curapp.authentication.redirect_uri !== null ? { - "type": "oauth2", - "redirect_uri": curapp.authentication.redirect_uri, - "token_uri": curapp.authentication.token_uri, - "scope": curapp.authentication.scope, + "type": "oauth2", + "redirect_uri": curapp.authentication.redirect_uri, + "token_uri": curapp.authentication.token_uri, + "scope": curapp.authentication.scope, + "client_id": curapp.authentication.client_id, + "client_secret": curapp.authentication.client_secret, } : { "type": "" }