Skip to content

Commit 57b6120

Browse files
author
FalkWolsky
committed
OAuth impersonation for GraphQL
1 parent 9aaf4b8 commit 57b6120

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

client/packages/lowcoder/src/pages/datasource/form/graphqlDatasourceForm.tsx

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,14 @@ import {
2121
} from "../form";
2222
import { DatasourceFormProps } from "./datasourceFormRegistry";
2323
import { useHostCheck } from "./useHostCheck";
24+
import { useSelector } from "react-redux";
25+
import { getUser } from "redux/selectors/usersSelectors";
2426

2527
const AuthTypeOptions = [
2628
{ label: "None", value: "NO_AUTH" },
2729
{ label: "Basic", value: "BASIC_AUTH" },
28-
{ label: "Digest", value: "DIGEST_AUTH" },
30+
{ label: "Digest", value: "DIGEST_AUTH" },
31+
{ label: "OAuth 2.0 (Inherit from login)", value: "OAUTH2_INHERIT_FROM_LOGIN" },
2932
] as const;
3033

3134
type AuthType = ValueFromOption<typeof AuthTypeOptions>;
@@ -46,7 +49,15 @@ export const GraphqlDatasourceForm = (props: DatasourceFormProps) => {
4649
const { form, datasource } = props;
4750
const datasourceConfig = datasource?.datasourceConfig as HttpConfig;
4851

52+
// here we get the Auth Sources from a user to enable user impersonation
53+
const userAuthSources = useSelector(getUser).connections?.filter(authSource => authSource.source !== "EMAIL");;
54+
const userAuthSourcesOptions = userAuthSources?.map(item => ({
55+
label: item.source,
56+
value: item.authId
57+
})) || [];
58+
4959
const [authType, setAuthType] = useState(datasourceConfig?.authConfig?.type);
60+
const [authId, setAuthId] = useState(datasourceConfig?.authConfig?.authId);
5061

5162
const hostRule = useHostCheck();
5263

@@ -93,6 +104,22 @@ export const GraphqlDatasourceForm = (props: DatasourceFormProps) => {
93104
}
94105
};
95106

107+
const showUserAuthSourceSelector = () => {
108+
if (authType === "OAUTH2_INHERIT_FROM_LOGIN") {
109+
return (
110+
<FormSelectItem
111+
name={"authId"}
112+
label="User Authentication Source"
113+
options={userAuthSourcesOptions}
114+
initialValue={datasourceConfig?.authConfig?authId : null}
115+
afterChange={(value) => setAuthId(value) }
116+
labelWidth={142}
117+
/>
118+
);
119+
}
120+
return null;
121+
};
122+
96123
return (
97124
<DatasourceForm form={form} preserve={false}>
98125
<FormSection size={props.size}>
@@ -138,6 +165,7 @@ export const GraphqlDatasourceForm = (props: DatasourceFormProps) => {
138165
afterChange={(value) => setAuthType(value)}
139166
labelWidth={142}
140167
/>
168+
{showUserAuthSourceSelector()}
141169
{showAuthItem(authType as AuthType)}
142170
</FormSection>
143171

client/packages/lowcoder/src/pages/datasource/form/useDatasourceForm.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ export function useDatasourceForm() {
6363
case "graphql":
6464
config = {
6565
...config,
66+
authConfig: {
67+
type: form.getFieldsValue()["authConfigType"],
68+
authId: form.getFieldsValue()["authId"],
69+
},
6670
sslConfig: {
6771
sslCertVerificationType: form.getFieldValue("sslCertVerificationType"),
6872
selfSignedCert: form.getFieldValue("selfSignedCert"),

client/scripts/build.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ shell.env["REACT_APP_COMMIT_ID"] = shell.env["REACT_APP_COMMIT_ID"] || shell.exe
8282

8383
// Treating warnings as errors when process.env.CI = true.
8484
shell.env["CI"] = false;
85-
shell.env["NODE_OPTIONS"] = "--max_old_space_size=4096";
85+
shell.env["NODE_OPTIONS"] = "--max_old_space_size=8192";
8686
shell.env["NODE_ENV"] = "production";
8787
shell.env["REACT_APP_LOG_LEVEL"] = "error";
8888
shell.env["REACT_APP_BUNDLE_BUILTIN_PLUGIN"] = "true";

0 commit comments

Comments
 (0)