-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Expand file tree
/
Copy pathauthentication.tsx
More file actions
350 lines (328 loc) · 10.4 KB
/
Copy pathauthentication.tsx
File metadata and controls
350 lines (328 loc) · 10.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
import React from "react";
import {
EMAIL_SETUP_DOC,
GITHUB_SIGNUP_SETUP_DOC,
GOOGLE_SIGNUP_SETUP_DOC,
} from "constants/ThirdPartyConstants";
import type { AdminConfigType } from "ee/pages/AdminSettings/config/types";
import {
CategoryType,
SettingCategories,
SettingSubtype,
SettingTypes,
} from "ee/pages/AdminSettings/config/types";
import type { AuthMethodType } from "pages/AdminSettings/Authentication/AuthPage";
import { AuthPage } from "pages/AdminSettings/Authentication/AuthPage";
import Google from "assets/images/Google.png";
import SamlSso from "assets/images/saml.svg";
import OIDC from "assets/images/oidc.svg";
import Github from "assets/images/Github.png";
import Lock from "assets/images/lock-password-line.svg";
import { useSelector } from "react-redux";
import {
getThirdPartyAuths,
getIsFormLoginEnabled,
} from "ee/selectors/organizationSelectors";
import {
FORM_LOGIN_DESC,
GITHUB_AUTH_DESC,
GOOGLE_AUTH_DESC,
OIDC_AUTH_DESC,
SAML_AUTH_DESC,
createMessage,
} from "ee/constants/messages";
import { isSAMLEnabled, isOIDCEnabled } from "ee/utils/planHelpers";
import { selectFeatureFlags } from "ee/selectors/featureFlagsSelectors";
import store from "store";
import { isMultiOrgFFEnabled } from "ee/utils/planHelpers";
import { getAppsmithConfigs } from "ee/configs";
import type { Setting } from "./types";
const featureFlags = selectFeatureFlags(store.getState());
const isMultiOrgEnabled = isMultiOrgFFEnabled(featureFlags);
const { mailEnabled } = getAppsmithConfigs();
export const FormAuth: AdminConfigType = {
type: SettingCategories.FORM_AUTH,
categoryType: CategoryType.USER_MANAGEMENT,
controlType: SettingTypes.GROUP,
title: "Form login",
subText: createMessage(FORM_LOGIN_DESC),
canSave: true,
settings: [
{
id: "isFormLoginEnabled",
category: SettingCategories.FORM_AUTH,
controlType: SettingTypes.TOGGLE,
label: "form login",
},
{
id: "isSignupDisabled",
category: SettingCategories.FORM_AUTH,
controlType: SettingTypes.TOGGLE,
label: "Form signup",
toggleText: () => "Allow all users to signup",
},
{
id: "emailVerificationEnabled",
category: SettingCategories.FORM_AUTH,
controlType: SettingTypes.TOGGLE,
label: "email verification",
isVisible: () => {
return !isMultiOrgEnabled;
},
isDisabled: (settings) => {
// Disabled when mail is not enabled, unless setting already enabled then enabled
if (!settings) {
return true;
}
if (settings.emailVerificationEnabled) {
return false;
}
return !mailEnabled;
},
},
{
id: "APPSMITH_FORM_DISABLED_BANNER",
category: SettingCategories.FORM_AUTH,
controlType: SettingTypes.CALLOUT,
label:
"To enable email verification for form login, you must enable SMTP server from email settings",
url: EMAIL_SETUP_DOC,
calloutType: "warning",
isVisible: (settings) => {
// Visible when mail is disabled, unless setting already enabled then visible
if (!settings) {
return false;
}
if (settings.emailVerificationEnabled) {
return false;
}
return !mailEnabled && !isMultiOrgEnabled;
},
},
{
id: "APPSMITH_FORM_CALLOUT_BANNER",
category: SettingCategories.FORM_AUTH,
controlType: SettingTypes.CALLOUT,
label:
"Please ensure that your SMTP settings are correctly configured to ensure that the verification emails can be delivered",
calloutType: "warning",
isVisible: (settings) => {
// Visible when mail is enabled and setting is true
if (!settings) {
return false;
}
return (
settings.emailVerificationEnabled && mailEnabled && !isMultiOrgEnabled
);
},
},
{
id: "APPSMITH_FORM_ERROR_BANNER",
category: SettingCategories.FORM_AUTH,
controlType: SettingTypes.CALLOUT,
label:
"Valid SMTP settings not found. Signup with email verification will not work without SMTP configuration",
calloutType: "error",
isVisible: (settings) => {
// Visible when mail is disabled but settings is true
if (!settings) {
return false;
}
if (
!mailEnabled &&
settings.emailVerificationEnabled &&
!isMultiOrgEnabled
) {
return true;
}
return false;
},
},
],
};
export const SingleOrgGoogleAuthSettings: Setting[] = [
{
id: "APPSMITH_OAUTH2_GOOGLE_READ_MORE",
category: SettingCategories.GOOGLE_AUTH,
controlType: SettingTypes.CALLOUT,
label: "How to configure?",
url: GOOGLE_SIGNUP_SETUP_DOC,
},
{
id: "APPSMITH_OAUTH2_GOOGLE_JS_ORIGIN_URL",
category: SettingCategories.GOOGLE_AUTH,
controlType: SettingTypes.UNEDITABLEFIELD,
label: "JavaScript origin URL",
fieldName: "js-origin-url-form",
value: "",
tooltip:
"This URL will be used while configuring the Google OAuth Client ID's authorized JavaScript origins",
helpText: "Paste this URL in your Google developer console.",
},
{
id: "APPSMITH_OAUTH2_GOOGLE_REDIRECT_URL",
category: SettingCategories.GOOGLE_AUTH,
controlType: SettingTypes.UNEDITABLEFIELD,
label: "Redirect URL",
fieldName: "redirect-url-form",
value: "/login/oauth2/code/google",
tooltip:
"This URL will be used while configuring the Google OAuth Client ID's authorized redirect URIs",
helpText: "Paste this URL in your Google developer console.",
},
{
id: "APPSMITH_OAUTH2_GOOGLE_CLIENT_ID",
category: SettingCategories.GOOGLE_AUTH,
controlType: SettingTypes.TEXTINPUT,
controlSubType: SettingSubtype.TEXT,
label: "Client ID",
isRequired: true,
},
{
id: "APPSMITH_OAUTH2_GOOGLE_CLIENT_SECRET",
category: SettingCategories.GOOGLE_AUTH,
controlType: SettingTypes.TEXTINPUT,
controlSubType: SettingSubtype.TEXT,
label: "Client secret",
isRequired: true,
},
{
id: "APPSMITH_SIGNUP_ALLOWED_DOMAINS",
category: SettingCategories.GOOGLE_AUTH,
controlType: SettingTypes.TEXTINPUT,
controlSubType: SettingSubtype.TEXT,
label: "Allowed domains",
placeholder: "domain1.com, domain2.com",
},
];
export const GoogleAuth: AdminConfigType = {
type: SettingCategories.GOOGLE_AUTH,
categoryType: CategoryType.USER_MANAGEMENT,
controlType: SettingTypes.GROUP,
title: "Google authentication",
subText: createMessage(GOOGLE_AUTH_DESC),
canSave: true,
settings: SingleOrgGoogleAuthSettings,
};
export const GithubAuth: AdminConfigType = {
type: SettingCategories.GITHUB_AUTH,
categoryType: CategoryType.USER_MANAGEMENT,
controlType: SettingTypes.GROUP,
title: "GitHub authentication",
subText: createMessage(GITHUB_AUTH_DESC),
canSave: true,
settings: [
{
id: "APPSMITH_OAUTH2_GITHUB_READ_MORE",
category: SettingCategories.GITHUB_AUTH,
controlType: SettingTypes.CALLOUT,
label: "How to configure?",
url: GITHUB_SIGNUP_SETUP_DOC,
},
{
id: "APPSMITH_OAUTH2_GITHUB_HOMEPAGE_URL",
category: SettingCategories.GITHUB_AUTH,
controlType: SettingTypes.UNEDITABLEFIELD,
label: "Homepage URL",
fieldName: "homepage-url-form",
value: "",
tooltip:
"This URL will be used while configuring the GitHub OAuth Client ID's homepage URL",
helpText: "Paste this URL in your GitHub developer settings.",
},
{
id: "APPSMITH_OAUTH2_GITHUB_REDIRECT_URL",
category: SettingCategories.GITHUB_AUTH,
controlType: SettingTypes.UNEDITABLEFIELD,
label: "Redirect URL",
fieldName: "callback-url-form",
value: "/login/oauth2/code/github",
tooltip:
"This URL will be used while configuring the GitHub OAuth Client ID's Authorization callback URL",
helpText: "Paste this URL in your GitHub developer settings.",
},
{
id: "APPSMITH_OAUTH2_GITHUB_CLIENT_ID",
category: SettingCategories.GITHUB_AUTH,
controlType: SettingTypes.TEXTINPUT,
controlSubType: SettingSubtype.TEXT,
label: "Client ID",
isRequired: true,
},
{
id: "APPSMITH_OAUTH2_GITHUB_CLIENT_SECRET",
category: SettingCategories.GITHUB_AUTH,
controlType: SettingTypes.TEXTINPUT,
controlSubType: SettingSubtype.TEXT,
label: "Client secret",
isRequired: true,
},
],
};
export const FormAuthCallout: AuthMethodType = {
id: "APPSMITH_FORM_LOGIN_AUTH",
category: SettingCategories.FORM_AUTH,
label: "Form login",
subText: createMessage(FORM_LOGIN_DESC),
image: Lock,
icon: "lock-password-line",
isFeatureEnabled: true,
};
export const GoogleAuthCallout: AuthMethodType = {
id: "APPSMITH_GOOGLE_AUTH",
category: SettingCategories.GOOGLE_AUTH,
label: "Google",
subText: createMessage(GOOGLE_AUTH_DESC),
image: Google,
isFeatureEnabled: true,
};
export const GithubAuthCallout: AuthMethodType = {
id: "APPSMITH_GITHUB_AUTH",
category: SettingCategories.GITHUB_AUTH,
label: "GitHub",
subText: createMessage(GITHUB_AUTH_DESC),
image: Github,
isFeatureEnabled: true,
};
export const SamlAuthCallout: AuthMethodType = {
id: "APPSMITH_SAML_AUTH",
category: SettingCategories.SAML_AUTH,
label: "SAML 2.0",
subText: createMessage(SAML_AUTH_DESC),
image: SamlSso,
isFeatureEnabled: isSAMLEnabled(featureFlags),
};
export const OidcAuthCallout: AuthMethodType = {
id: "APPSMITH_OIDC_AUTH",
category: SettingCategories.OIDC_AUTH,
label: "OIDC",
subText: createMessage(OIDC_AUTH_DESC),
image: OIDC,
isFeatureEnabled: isOIDCEnabled(featureFlags),
};
const AuthMethods = [
OidcAuthCallout,
SamlAuthCallout,
GoogleAuthCallout,
GithubAuthCallout,
FormAuthCallout,
];
function AuthMain() {
FormAuthCallout.isConnected = useSelector(getIsFormLoginEnabled);
const socialLoginList = useSelector(getThirdPartyAuths);
GoogleAuth.isConnected = GoogleAuthCallout.isConnected =
socialLoginList.includes("google");
GithubAuth.isConnected = GithubAuthCallout.isConnected =
socialLoginList.includes("github");
return <AuthPage authMethods={AuthMethods} />;
}
export const config: AdminConfigType = {
icon: "shield-user-line",
type: SettingCategories.AUTHENTICATION,
categoryType: CategoryType.USER_MANAGEMENT,
controlType: SettingTypes.PAGE,
title: "Authentication",
canSave: false,
children: [FormAuth, GoogleAuth, GithubAuth],
component: AuthMain,
};