Skip to content

Commit e8a38c5

Browse files
authored
Merge pull request #872 from raheeliftikhar5/generic-oauth-updates-2
show source mappings in generic auth edit mode
2 parents 9980dd0 + 82be209 commit e8a38c5

File tree

3 files changed

+83
-22
lines changed

3 files changed

+83
-22
lines changed

client/packages/lowcoder/src/pages/setting/idSource/OAuthForms/GenericOAuthForm.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ import Flex from "antd/es/flex";
1717
import Button from "antd/es/button";
1818
import axios from "axios";
1919
import { IconPicker } from "@lowcoder-ee/comps/controls/iconControl";
20+
import Switch from "antd/es/switch";
2021

21-
const sourceMappingKeys = [
22+
export const sourceMappingKeys = [
2223
'uid',
2324
'email',
2425
'username',
@@ -49,7 +50,7 @@ interface OpenIdProvider {
4950
scopes_supported: string[],
5051
}
5152

52-
interface ConfigProvider {
53+
export interface ConfigProvider {
5354
authType: string,
5455
source: string,
5556
sourceName: string,
@@ -223,6 +224,7 @@ function GenericOAuthForm(props: GenericOAuthFormProp) {
223224
const isPassword = valueObject && valueObject.isPassword;
224225
const isIcon = valueObject && valueObject.isIcon;
225226
const isList = valueObject && valueObject.isList;
227+
const isSwitch = valueObject && valueObject.isSwitch;
226228
return (
227229
<div key={key}>
228230
<Form.Item
@@ -255,13 +257,15 @@ function GenericOAuthForm(props: GenericOAuthFormProp) {
255257
placeholder={trans("idSource.encryptedServer")}
256258
autoComplete={"one-time-code"}
257259
/>
258-
) : !isPassword && !isList && isIcon ? (
260+
) : isSwitch ? (
261+
<Switch />
262+
) : isIcon ? (
259263
<IconPicker
260264
onChange={(value) => form1.setFieldValue("sourceIcon", value)}
261265
label={'Source Icon'}
262266
value={form1.getFieldValue('sourceIcon')}
263267
/>
264-
) : !isPassword && isList && !isIcon ? (
268+
) : isList ? (
265269
<CustomSelect
266270
options={(value as ItemType).options}
267271
placeholder={trans("idSource.formSelectPlaceholder", {

client/packages/lowcoder/src/pages/setting/idSource/detail/index.tsx

Lines changed: 73 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ import { ItemType } from "pages/setting/idSource/idSourceConstants";
3838
import _ from "lodash";
3939
import { messageInstance } from "lowcoder-design/src/components/GlobalInstances";
4040
import { IconPicker } from "@lowcoder-ee/comps/controls/iconControl";
41+
import Switch from "antd/es/switch";
42+
import Title from "antd/es/typography/Title";
43+
import { sourceMappingKeys } from "../OAuthForms/GenericOAuthForm";
44+
import Flex from "antd/es/flex";
4145

4246
type IdSourceDetailProps = {
4347
location: Location & { state: ConfigItem };
@@ -68,13 +72,32 @@ export const IdSourceDetail = (props: IdSourceDetailProps) => {
6872
if (!configDetail) {
6973
goList();
7074
}
71-
const handleSuccess = (values: ConfigItem) => {
75+
const handleSuccess = (values: any) => {
7276
setSaveLoading(true);
73-
const params = {
74-
...values,
75-
...(configDetail.ifLocal ? null : { id: configDetail.id }),
77+
let params = {
78+
id: configDetail.id,
7679
authType: configDetail.authType,
80+
enableRegister: configDetail.enableRegister,
7781
};
82+
83+
if (configDetail.authType === AuthType.Generic) {
84+
const { uid, email, avatar, username, ...newValues } = values;
85+
params = {
86+
...newValues,
87+
sourceMappings: {
88+
uid,
89+
email,
90+
avatar,
91+
username,
92+
},
93+
...params,
94+
}
95+
} else {
96+
params = {
97+
...values,
98+
...params,
99+
}
100+
}
78101
IdSourceApi.saveConfig(params)
79102
.then((resp) => {
80103
if (validateResponse(resp)) {
@@ -157,14 +180,16 @@ export const IdSourceDetail = (props: IdSourceDetailProps) => {
157180
>
158181
{Object.entries(authConfig[configDetail.authType].form).map(([key, value]) => {
159182
const valueObject = _.isObject(value) ? (value as ItemType) : false;
160-
let required = configDetail.ifLocal || (key !== "clientSecret" && key !== "publicKey");
183+
// let required = configDetail.ifLocal || (key !== "clientSecret" && key !== "publicKey");
184+
let required = (key === "clientId" || key === "clientSecret" || key === "scope");
161185
required = valueObject ? valueObject.isRequire ?? required : required;
162186
const hasLock = valueObject && valueObject?.hasLock;
163187
const tip = valueObject && valueObject.tip;
164188
const label = valueObject ? valueObject.label : value as string;
165189
const isList = valueObject && valueObject.isList;
166190
const isPassword = valueObject && valueObject.isPassword;
167191
const isIcon = valueObject && valueObject.isIcon;
192+
const isSwitch = valueObject && valueObject.isSwitch;
168193
return (
169194
<div key={key}>
170195
<Form.Item
@@ -208,30 +233,32 @@ export const IdSourceDetail = (props: IdSourceDetailProps) => {
208233
}
209234
autoComplete={"one-time-code"}
210235
/>
211-
) : !isPassword && !isList && !isIcon ? (
212-
<Input
213-
placeholder={trans("idSource.formPlaceholder", {
214-
label,
215-
})}
216-
disabled={hasLock && lock}
217-
prefix={
218-
hasLock &&
219-
(lock ? <LockIcon onClick={() => handleLockClick()} /> : <UnLockIcon />)
220-
}
221-
/>
222-
) : !isPassword && !isList && isIcon ? (
236+
) : isSwitch ? (
237+
<Switch />
238+
) : isIcon ? (
223239
<IconPicker
224240
onChange={(value) => form.setFieldValue("sourceIcon", value)}
225241
label={'Source Icon'}
226242
value={form.getFieldValue('sourceIcon')}
227243
/>
228-
) : (
244+
) : isList ? (
229245
<CustomSelect
230246
options={(value as ItemType).options}
231247
placeholder={trans("idSource.formSelectPlaceholder", {
232248
label,
233249
})}
234250
/>
251+
) : (
252+
<Input
253+
placeholder={trans("idSource.formPlaceholder", {
254+
label,
255+
})}
256+
disabled={hasLock && lock}
257+
prefix={
258+
hasLock &&
259+
(lock ? <LockIcon onClick={() => handleLockClick()} /> : <UnLockIcon />)
260+
}
261+
/>
235262
)}
236263
</Form.Item>
237264
{hasLock && lock && (
@@ -246,6 +273,34 @@ export const IdSourceDetail = (props: IdSourceDetailProps) => {
246273
<CheckboxStyled>{trans("idSource.enableRegister")}</CheckboxStyled>
247274
</Form.Item> */}
248275

276+
{configDetail.authType === AuthType.Generic && (
277+
<>
278+
<Title level={5}>Source Mappings</Title>
279+
{sourceMappingKeys.map(sourceKey => (
280+
<Flex gap="10px" align="start" key={sourceKey} >
281+
<Input
282+
readOnly
283+
disabled
284+
value={sourceKey}
285+
style={{flex: 1}}
286+
/>
287+
<span> &#8594; </span>
288+
<Form.Item
289+
name={sourceKey}
290+
rules={[{ required: true }]}
291+
style={{flex: 1}}
292+
>
293+
<Input
294+
placeholder={trans("idSource.formPlaceholder", {
295+
label: sourceKey,
296+
})}
297+
/>
298+
</Form.Item>
299+
</Flex>
300+
))}
301+
</>
302+
)}
303+
249304
<Form.Item>
250305
<SaveButton loading={saveLoading} disabled={saveDisable} htmlType="submit">
251306
{configDetail.enable ? trans("idSource.save") : trans("idSource.saveBtn")}

client/packages/lowcoder/src/pages/setting/idSource/idSourceConstants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ export const authConfig = {
100100
userInfoEndpoint: { label: 'UserInfo Endpoint', isRequire: true },
101101
// jwks: { label: 'Authorize URL', isRequire: true },
102102
scope: "Scope",
103+
userInfoIntrospection: { label: 'Use OpenID User Introspection', isSwitch: true, isRequire: false},
103104
// baseUrl: "Base URL",
104105
// realm: "Realm",
105106
},
@@ -126,6 +127,7 @@ export type ItemType = {
126127
isRequire?: boolean;
127128
isPassword?: boolean;
128129
isIcon?: boolean;
130+
isSwitch?: boolean;
129131
hasLock?: boolean;
130132
tip?: string;
131133
}

0 commit comments

Comments
 (0)