Skip to content

Commit 83d254e

Browse files
author
FalkWolsky
committed
Enabling selection of OAuth Token in FE
1 parent c990411 commit 83d254e

File tree

6 files changed

+34
-2
lines changed

6 files changed

+34
-2
lines changed

.DS_Store

0 Bytes
Binary file not shown.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ client/node_modules/
99
client/packages/lowcoder-plugin-demo/.yarn/install-state.gz
1010
client/packages/lowcoder-plugin-demo/yarn.lock
1111
client/packages/lowcoder-plugin-demo/.yarn/cache/@types-node-npm-16.18.68-56f72825c0-094ae9ed80.zip
12+
.DS_Store

client/packages/lowcoder/src/api/datasourceApi.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ export interface HttpConfig {
102102

103103
authConfig: {
104104
type: AuthType;
105+
authId?: string;
105106
} & (
106107
| {
107108
username: string; // basic auth

client/packages/lowcoder/src/constants/userConstants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export const UserConnectionSource = {
1111
};
1212

1313
export type UserConnection = {
14+
authId: any;
1415
source: string;
1516
name: string;
1617
rawUserInfo?: JSONObject;

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

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Rule } from "antd/lib/form";
2-
import { HttpConfig } from "api/datasourceApi";
2+
import { HttpConfig, OAuthConfig } from "api/datasourceApi";
33
import {
44
DatasourceForm,
55
FormInputItem,
@@ -21,12 +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" },
2830
{ label: "Digest", value: "DIGEST_AUTH" },
29-
{ label: "OAuth 2.0(Inherit from login)", value: "OAUTH2_INHERIT_FROM_LOGIN" },
31+
{ label: "OAuth 2.0 (Inherit from login)", value: "OAUTH2_INHERIT_FROM_LOGIN" },
3032
// { label: "OAuth 2.0", value: "oAuth2" },
3133
] as const;
3234

@@ -50,7 +52,16 @@ export const HttpDatasourceForm = (props: DatasourceFormProps) => {
5052
const datasourceConfig = datasource?.datasourceConfig as HttpConfig;
5153
// const oauthConfig = datasourceConfig?.authConfig as OAuthConfig;
5254

55+
// here we get the Auth Sources from a user to enable user impersonation
56+
const userAuthSources = useSelector(getUser).connections?.filter(authSource => authSource.source !== "EMAIL");;
57+
const userAuthSourcesOptions = userAuthSources?.map(item => ({
58+
label: item.source,
59+
value: item.authId
60+
})) || [];
61+
5362
const [authType, setAuthType] = useState(datasourceConfig?.authConfig?.type);
63+
const [authId, setAuthId] = useState(datasourceConfig?.authConfig?.authId);
64+
5465
// const [grantType, setGrantType] = useState(oauthConfig?.grantType ?? "authorization_code");
5566

5667
const hostRule = useHostCheck();
@@ -98,6 +109,22 @@ export const HttpDatasourceForm = (props: DatasourceFormProps) => {
98109
}
99110
};
100111

112+
const showUserAuthSourceSelector = () => {
113+
if (authType === "OAUTH2_INHERIT_FROM_LOGIN") {
114+
return (
115+
<FormSelectItem
116+
name={"authId"}
117+
label="User Authentication Source"
118+
options={userAuthSourcesOptions}
119+
initialValue={datasourceConfig?.authConfig?authId : null}
120+
afterChange={(value) => setAuthId(value) }
121+
labelWidth={142}
122+
/>
123+
);
124+
}
125+
return null;
126+
};
127+
101128
return (
102129
<DatasourceForm form={form} preserve={false}>
103130
<FormSection size={props.size}>
@@ -149,6 +176,7 @@ export const HttpDatasourceForm = (props: DatasourceFormProps) => {
149176
afterChange={(value) => setAuthType(value)}
150177
labelWidth={142}
151178
/>
179+
{showUserAuthSourceSelector()}
152180
{showAuthItem(authType)}
153181
</FormSection>
154182

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export function useDatasourceForm() {
5050
...config,
5151
authConfig: {
5252
type: form.getFieldsValue()["authConfigType"],
53+
authId: form.getFieldsValue()["authId"],
5354
username: form.getFieldsValue()["username"],
5455
password: form.getFieldsValue()["password"],
5556
},

0 commit comments

Comments
 (0)