From 52ba4a9537b68bbac1388190de03a113d68dea8b Mon Sep 17 00:00:00 2001 From: frikky Date: Tue, 7 Sep 2021 03:14:36 +0200 Subject: [PATCH] Fixed oauth2 and backslash SDK issue --- backend/app_sdk/app_base.py | 44 ++++++++++++++++++------ frontend/src/components/Oauth2Auth.jsx | 4 ++- frontend/src/components/ParsedAction.jsx | 6 ++-- frontend/src/views/LoginPage.jsx | 5 ++- functions/onprem/worker/worker.go | 4 +-- 5 files changed, 45 insertions(+), 18 deletions(-) diff --git a/backend/app_sdk/app_base.py b/backend/app_sdk/app_base.py index 2617dd9a..7b90b818 100644 --- a/backend/app_sdk/app_base.py +++ b/backend/app_sdk/app_base.py @@ -521,7 +521,7 @@ class AppBase: print("[INFO] Multiplier length: %d" % len(param_multiplier)) #tmp = "" for subparams in param_multiplier: - print(f"SUBPARAMS IN MULTI: {subparams}") + #print(f"SUBPARAMS IN MULTI: {subparams}") try: #tmp = await func(**subparams) @@ -1129,6 +1129,7 @@ class AppBase: return default_error # Parses the INNER value and recurses until everything is done + # Looks for a way to use e.g. int() or number() as a value def parse_wrapper(data): try: if "(" not in data or ")" not in data: @@ -1177,7 +1178,7 @@ class AppBase: c_parentheses = parse_nested_param(parse_string, 0)[0] match_string = re.escape(c_parentheses) custom_casting = re.findall(fr"({wrapper_group})\({match_string}", parse_string) - + print("In ELSE: %s" % custom_casting) # check if a wrapper was found if len(custom_casting) != 0: inner_result = parse_type(c_parentheses, custom_casting[0]) @@ -1189,6 +1190,7 @@ class AppBase: else: parse_string = inner_result + print("PARSE STRING: %s" % parse_string) return parse_string, True # Looks for parantheses to grab special cases within a string, e.g: @@ -1203,16 +1205,28 @@ class AppBase: if "(" not in data or ")" not in data: return data + if isinstance(data, str) and len(data) > 4: + if (data[0] == "{" or data[0] == "[") and (data[len(data)-1] == "]" or data[len(data)-1] == "}"): + print("Skipping parser because use of {[ and ]}") + return data + newdata = [] newstring = "" record = True paranCnt = 0 + charcnt = 0 for char in data: if char == "(": - paranCnt += 1 - - if not record: - record = True + charskip = False + if charcnt > 0: + if data[charcnt-1] == " ": + charskip = True + + if not charskip: + paranCnt += 1 + + if not record: + record = True if record: newstring += char @@ -1227,6 +1241,8 @@ class AppBase: if paranCnt == 0: record = False + + charcnt += 1 if len(newstring) > 0: newdata.append(newstring) @@ -1378,7 +1394,7 @@ class AppBase: basejson = json.loads(basejson[value]) print("BASEJSON: %s" % basejson) except json.decoder.JSONDecodeError as e: - print("RETURNING BECAUSE '%s' IS A NORMAL STRING" % basejson[value]) + print("RETURNING BECAUSE '%s' IS A NORMAL STRING (0)" % basejson[value]) return basejson[value], False else: basejson = basejson[value] @@ -1398,7 +1414,7 @@ class AppBase: basejson = json.loads(basejson[value]) print("BASEJSON: %s" % basejson) except json.decoder.JSONDecodeError as e: - print("RETURNING BECAUSE '%s' IS A NORMAL STRING" % basejson[value]) + print("RETURNING BECAUSE '%s' IS A NORMAL STRING (1)" % basejson[value]) return basejson[value], False else: basejson = basejson[value] @@ -2206,9 +2222,9 @@ class AppBase: for i in range(len(json_replacement)): if isinstance(json_replacement[i], dict) or isinstance(json_replacement[i], list): tmp_replacer = json.dumps(json_replacement[i]) - newvalue = tmpitem.replace(actualitem[index][0], tmp_replacer, 1) + newvalue = tmpitem.replace(str(actualitem[index][0]), str(tmp_replacer), 1) else: - newvalue = tmpitem.replace(actualitem[index][0], json_replacement[i], 1) + newvalue = tmpitem.replace(str(actualitem[index][0]), str(json_replacement[i]), 1) try: newvalue = json.loads(newvalue) @@ -2281,6 +2297,7 @@ class AppBase: actualitem = replace[2] if actualitem.endswith("}$"): actualitem = actualitem[:-2] + except IndexError: continue @@ -2344,6 +2361,7 @@ class AppBase: print("(2) JSON ERROR IN FILE HANDLING: %s" % e) if not isfile: + tmpitem = tmpitem.replace("\\\\", "\\", -1) resultarray.append(tmpitem) # With this parameter ready, add it to... a greater list of parameters. Rofl @@ -2397,7 +2415,11 @@ class AppBase: else: # Parses things like int(value) print("Normal parsing (not looping)")#with data %s" % value) + + # This part has fucked over so many random JSON usages because of weird paranthesis parsing + value = parse_wrapper_start(value) + print("Post return: %s" % value) #if parameter["id"] == "body_replacement": # print("Should run body replacement in index %d with %s" % (bodyindex, parameter)) @@ -2436,7 +2458,7 @@ class AppBase: #remove_params.append(parameter["name"]) # Fix lists here # FIXME: This doesn't really do anything anymore - print("CHECKING multi execution list!") + print("CHECKING multi execution list: %d!" % len(multi_execution_lists)) if len(multi_execution_lists) > 0: print("\n Multi execution list has more data: %d" % len(multi_execution_lists)) filteredlist = [] diff --git a/frontend/src/components/Oauth2Auth.jsx b/frontend/src/components/Oauth2Auth.jsx index 64a82d5b..321cd811 100644 --- a/frontend/src/components/Oauth2Auth.jsx +++ b/frontend/src/components/Oauth2Auth.jsx @@ -45,7 +45,9 @@ const AuthenticationOauth2 = (props) => { console.log("EDIT SCOPE!") } - const redirectUri = `http://${window.location.host}/set_authentication` + 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}` const url = `${authenticationType.redirect_uri}?client_id=${client_id}&redirect_uri=${redirectUri}&response_type=code&scope=${resources}&state=${state}` diff --git a/frontend/src/components/ParsedAction.jsx b/frontend/src/components/ParsedAction.jsx index abcd6309..7e6fd11e 100644 --- a/frontend/src/components/ParsedAction.jsx +++ b/frontend/src/components/ParsedAction.jsx @@ -1552,9 +1552,9 @@ const ParsedAction = (props) => {