strapi-plugin-oidc 1.2.4 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -24
- package/dist/admin/{index-CYL_geya.js → index-BqyGGX8X.js} +82 -114
- package/dist/admin/{index-BD7cK7Hf.mjs → index-CFmg9Kxl.mjs} +58 -90
- package/dist/admin/{index-Cxj6lwW7.js → index-Cse9ex24.js} +78 -119
- package/dist/admin/{index-B2dKk7YS.mjs → index-D1ypRUlq.mjs} +79 -120
- package/dist/admin/index.js +1 -1
- package/dist/admin/index.mjs +1 -1
- package/dist/server/index.js +62 -57
- package/dist/server/index.mjs +62 -57
- package/package.json +1 -2
|
@@ -2,18 +2,11 @@ import { jsxs, Fragment, jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import { Routes, Route } from "react-router-dom";
|
|
3
3
|
import { useNotification, useFetchClient, Page, Layouts } from "@strapi/strapi/admin";
|
|
4
4
|
import { useState, useCallback, useEffect, memo } from "react";
|
|
5
|
-
import { Typography, Flex, Box, MultiSelect, MultiSelectOption, Field, Button, Divider, Thead, Tr, Th, Tbody, Td, Dialog, IconButton, Pagination, PreviousLink, PageLink, NextLink, Table, Alert
|
|
6
|
-
import { Plus, Trash, WarningCircle } from "@strapi/icons";
|
|
5
|
+
import { Typography, Flex, Box, MultiSelect, MultiSelectOption, Field, Button, Divider, Thead, Tr, Th, Tbody, Td, Dialog, IconButton, Pagination, PreviousLink, PageLink, NextLink, Table, Alert } from "@strapi/design-system";
|
|
6
|
+
import { Plus, Trash, WarningCircle, Information } from "@strapi/icons";
|
|
7
7
|
import { useIntl } from "react-intl";
|
|
8
|
-
import {
|
|
8
|
+
import { g as getTrad } from "./index-D1ypRUlq.mjs";
|
|
9
9
|
import styled from "styled-components";
|
|
10
|
-
function getTrad(id) {
|
|
11
|
-
const pluginIdWithId = `${pluginId}.${id}`;
|
|
12
|
-
return {
|
|
13
|
-
id: pluginIdWithId,
|
|
14
|
-
defaultMessage: en[id] || pluginIdWithId
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
10
|
function Role({ oidcRoles, roles, onChangeRole }) {
|
|
18
11
|
const { formatMessage } = useIntl();
|
|
19
12
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
@@ -86,7 +79,7 @@ function Whitelist({
|
|
|
86
79
|
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
87
80
|
return emailRegex.test(email);
|
|
88
81
|
}, [email]);
|
|
89
|
-
return /* @__PURE__ */
|
|
82
|
+
return /* @__PURE__ */ jsxs(Box, { children: [
|
|
90
83
|
/* @__PURE__ */ jsx(Typography, { tag: "p", variant: "omega", textColor: "neutral600", marginBottom: 4, children: formatMessage(getTrad("whitelist.description")) }),
|
|
91
84
|
useWhitelist && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
92
85
|
/* @__PURE__ */ jsxs(Flex, { gap: 4, marginTop: 5, marginBottom: 5, alignItems: "flex-start", children: [
|
|
@@ -202,10 +195,10 @@ function Whitelist({
|
|
|
202
195
|
e.preventDefault();
|
|
203
196
|
setPage((p) => Math.max(1, p - 1));
|
|
204
197
|
},
|
|
205
|
-
children: "
|
|
198
|
+
children: formatMessage(getTrad("pagination.previous"))
|
|
206
199
|
}
|
|
207
200
|
),
|
|
208
|
-
Array.from({ length: pageCount }).map((_, i) => /* @__PURE__ */
|
|
201
|
+
Array.from({ length: pageCount }).map((_, i) => /* @__PURE__ */ jsx(
|
|
209
202
|
PageLink,
|
|
210
203
|
{
|
|
211
204
|
number: i + 1,
|
|
@@ -214,10 +207,7 @@ function Whitelist({
|
|
|
214
207
|
e.preventDefault();
|
|
215
208
|
setPage(i + 1);
|
|
216
209
|
},
|
|
217
|
-
children:
|
|
218
|
-
"Go to page ",
|
|
219
|
-
i + 1
|
|
220
|
-
]
|
|
210
|
+
children: formatMessage(getTrad("pagination.page"), { page: i + 1 })
|
|
221
211
|
},
|
|
222
212
|
i + 1
|
|
223
213
|
)),
|
|
@@ -229,12 +219,12 @@ function Whitelist({
|
|
|
229
219
|
e.preventDefault();
|
|
230
220
|
setPage((p) => Math.min(pageCount, p + 1));
|
|
231
221
|
},
|
|
232
|
-
children: "
|
|
222
|
+
children: formatMessage(getTrad("pagination.next"))
|
|
233
223
|
}
|
|
234
224
|
)
|
|
235
225
|
] }) }) })
|
|
236
226
|
] })
|
|
237
|
-
] })
|
|
227
|
+
] });
|
|
238
228
|
}
|
|
239
229
|
const AlertMessage = styled.div`
|
|
240
230
|
position: fixed;
|
|
@@ -246,11 +236,29 @@ const AlertMessage = styled.div`
|
|
|
246
236
|
`;
|
|
247
237
|
function SuccessAlertMessage({ onClose }) {
|
|
248
238
|
const { formatMessage } = useIntl();
|
|
249
|
-
return /* @__PURE__ */ jsx(AlertMessage, { children: /* @__PURE__ */ jsx(
|
|
239
|
+
return /* @__PURE__ */ jsx(AlertMessage, { children: /* @__PURE__ */ jsx(
|
|
240
|
+
Alert,
|
|
241
|
+
{
|
|
242
|
+
title: formatMessage(getTrad("alert.title.success")),
|
|
243
|
+
variant: "success",
|
|
244
|
+
closeLabel: "",
|
|
245
|
+
onClose,
|
|
246
|
+
children: formatMessage(getTrad("page.save.success"))
|
|
247
|
+
}
|
|
248
|
+
) });
|
|
250
249
|
}
|
|
251
250
|
function ErrorAlertMessage({ onClose }) {
|
|
252
251
|
const { formatMessage } = useIntl();
|
|
253
|
-
return /* @__PURE__ */ jsx(AlertMessage, { children: /* @__PURE__ */ jsx(
|
|
252
|
+
return /* @__PURE__ */ jsx(AlertMessage, { children: /* @__PURE__ */ jsx(
|
|
253
|
+
Alert,
|
|
254
|
+
{
|
|
255
|
+
title: formatMessage(getTrad("alert.title.error")),
|
|
256
|
+
variant: "danger",
|
|
257
|
+
closeLabel: "",
|
|
258
|
+
onClose,
|
|
259
|
+
children: formatMessage(getTrad("page.save.error"))
|
|
260
|
+
}
|
|
261
|
+
) });
|
|
254
262
|
}
|
|
255
263
|
function MatchedUserAlertMessage({
|
|
256
264
|
onClose,
|
|
@@ -258,7 +266,16 @@ function MatchedUserAlertMessage({
|
|
|
258
266
|
}) {
|
|
259
267
|
const { formatMessage } = useIntl();
|
|
260
268
|
const id = count > 1 ? "whitelist.users_exists" : "whitelist.user_exists";
|
|
261
|
-
return /* @__PURE__ */ jsx(AlertMessage, { children: /* @__PURE__ */ jsx(
|
|
269
|
+
return /* @__PURE__ */ jsx(AlertMessage, { children: /* @__PURE__ */ jsx(
|
|
270
|
+
Alert,
|
|
271
|
+
{
|
|
272
|
+
title: formatMessage(getTrad("alert.title.info")),
|
|
273
|
+
variant: "default",
|
|
274
|
+
closeLabel: "",
|
|
275
|
+
onClose,
|
|
276
|
+
children: formatMessage(getTrad(id))
|
|
277
|
+
}
|
|
278
|
+
) });
|
|
262
279
|
}
|
|
263
280
|
const SwitchContainer = styled.label`
|
|
264
281
|
position: relative;
|
|
@@ -342,12 +359,9 @@ function useOidcSettings() {
|
|
|
342
359
|
const [useWhitelist, setUseWhitelist] = useState(false);
|
|
343
360
|
const [initialEnforceOIDC, setInitialEnforceOIDC] = useState(false);
|
|
344
361
|
const [enforceOIDC, setEnforceOIDC] = useState(false);
|
|
362
|
+
const [enforceOIDCConfig, setEnforceOIDCConfig] = useState(null);
|
|
345
363
|
const [initialUsers, setInitialUsers] = useState([]);
|
|
346
364
|
const [users, setUsers] = useState([]);
|
|
347
|
-
const [initialShowSSOButton, setInitialShowSSOButton] = useState(true);
|
|
348
|
-
const [showSSOButton, setShowSSOButton] = useState(true);
|
|
349
|
-
const [initialSSOButtonText, setInitialSSOButtonText] = useState("Login via SSO");
|
|
350
|
-
const [ssoButtonText, setSSOButtonText] = useState("Login via SSO");
|
|
351
365
|
useEffect(() => {
|
|
352
366
|
get(`/strapi-plugin-oidc/oidc-roles`).then((response) => {
|
|
353
367
|
setOIDCRoles(response.data);
|
|
@@ -363,10 +377,7 @@ function useOidcSettings() {
|
|
|
363
377
|
setInitialUseWhitelist(response.data.useWhitelist);
|
|
364
378
|
setEnforceOIDC(response.data.enforceOIDC);
|
|
365
379
|
setInitialEnforceOIDC(response.data.enforceOIDC);
|
|
366
|
-
|
|
367
|
-
setInitialShowSSOButton(response.data.showSSOButton !== false);
|
|
368
|
-
setSSOButtonText(response.data.ssoButtonText || "Login via SSO");
|
|
369
|
-
setInitialSSOButtonText(response.data.ssoButtonText || "Login via SSO");
|
|
380
|
+
setEnforceOIDCConfig(response.data.enforceOIDCConfig ?? null);
|
|
370
381
|
});
|
|
371
382
|
}, [get]);
|
|
372
383
|
const onChangeRole = (values, oidcId) => {
|
|
@@ -396,13 +407,7 @@ function useOidcSettings() {
|
|
|
396
407
|
const onToggleEnforce = (e) => {
|
|
397
408
|
setEnforceOIDC(e.target.checked);
|
|
398
409
|
};
|
|
399
|
-
const
|
|
400
|
-
setShowSSOButton(e.target.checked);
|
|
401
|
-
};
|
|
402
|
-
const onChangeSSOButtonText = (e) => {
|
|
403
|
-
setSSOButtonText(e.target.value);
|
|
404
|
-
};
|
|
405
|
-
const isDirty = useWhitelist !== initialUseWhitelist || enforceOIDC !== initialEnforceOIDC || showSSOButton !== initialShowSSOButton || ssoButtonText !== initialSSOButtonText || JSON.stringify(oidcRoles) !== JSON.stringify(initialOidcRoles) || JSON.stringify(users) !== JSON.stringify(initialUsers);
|
|
410
|
+
const isDirty = useWhitelist !== initialUseWhitelist || enforceOIDC !== initialEnforceOIDC || JSON.stringify(oidcRoles) !== JSON.stringify(initialOidcRoles) || JSON.stringify(users) !== JSON.stringify(initialUsers);
|
|
406
411
|
const onSaveAll = async () => {
|
|
407
412
|
setLoading(true);
|
|
408
413
|
try {
|
|
@@ -417,15 +422,11 @@ function useOidcSettings() {
|
|
|
417
422
|
});
|
|
418
423
|
await put("/strapi-plugin-oidc/whitelist/settings", {
|
|
419
424
|
useWhitelist,
|
|
420
|
-
enforceOIDC
|
|
421
|
-
showSSOButton,
|
|
422
|
-
ssoButtonText
|
|
425
|
+
enforceOIDC
|
|
423
426
|
});
|
|
424
427
|
setInitialOIDCRoles(JSON.parse(JSON.stringify(oidcRoles)));
|
|
425
428
|
setInitialUseWhitelist(useWhitelist);
|
|
426
429
|
setInitialEnforceOIDC(enforceOIDC);
|
|
427
|
-
setInitialShowSSOButton(showSSOButton);
|
|
428
|
-
setInitialSSOButtonText(ssoButtonText);
|
|
429
430
|
get("/strapi-plugin-oidc/whitelist").then((getResponse) => {
|
|
430
431
|
setUsers(getResponse.data.whitelistUsers);
|
|
431
432
|
setInitialUsers(JSON.parse(JSON.stringify(getResponse.data.whitelistUsers)));
|
|
@@ -455,10 +456,9 @@ function useOidcSettings() {
|
|
|
455
456
|
roles,
|
|
456
457
|
useWhitelist,
|
|
457
458
|
enforceOIDC,
|
|
459
|
+
enforceOIDCConfig,
|
|
458
460
|
initialEnforceOIDC,
|
|
459
461
|
users,
|
|
460
|
-
showSSOButton,
|
|
461
|
-
ssoButtonText,
|
|
462
462
|
isDirty
|
|
463
463
|
},
|
|
464
464
|
actions: {
|
|
@@ -470,8 +470,6 @@ function useOidcSettings() {
|
|
|
470
470
|
onDeleteWhitelist,
|
|
471
471
|
onToggleWhitelist,
|
|
472
472
|
onToggleEnforce,
|
|
473
|
-
onToggleShowSSOButton,
|
|
474
|
-
onChangeSSOButtonText,
|
|
475
473
|
onSaveAll
|
|
476
474
|
}
|
|
477
475
|
};
|
|
@@ -529,57 +527,27 @@ function HomePage() {
|
|
|
529
527
|
] }),
|
|
530
528
|
/* @__PURE__ */ jsxs(Box, { background: "neutral0", hasRadius: true, shadow: "filterShadow", padding: 6, children: [
|
|
531
529
|
/* @__PURE__ */ jsx(Box, { paddingBottom: 6, children: /* @__PURE__ */ jsx(Typography, { variant: "beta", tag: "h2", children: formatMessage(getTrad("login.settings.title")) }) }),
|
|
532
|
-
/* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap:
|
|
533
|
-
/* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 2, children: [
|
|
534
|
-
/* @__PURE__ */ jsxs(Flex, { alignItems: "center", gap: 3, wrap: "wrap", children: [
|
|
535
|
-
/* @__PURE__ */ jsx(Typography, { variant: "omega", style: { minWidth: "280px" }, children: formatMessage(getTrad("enforce.title")) }),
|
|
536
|
-
/* @__PURE__ */ jsx(Box, { minWidth: "160px", children: /* @__PURE__ */ jsx(
|
|
537
|
-
CustomSwitch,
|
|
538
|
-
{
|
|
539
|
-
checked: state.enforceOIDC,
|
|
540
|
-
onChange: actions.onToggleEnforce,
|
|
541
|
-
disabled: state.useWhitelist && state.users.length === 0,
|
|
542
|
-
label: state.enforceOIDC ? formatMessage(getTrad("enforce.toggle.enabled")) : formatMessage(getTrad("enforce.toggle.disabled"))
|
|
543
|
-
}
|
|
544
|
-
) })
|
|
545
|
-
] }),
|
|
546
|
-
state.enforceOIDC && state.enforceOIDC !== state.initialEnforceOIDC && /* @__PURE__ */ jsx(Box, { background: "danger100", padding: 3, hasRadius: true, children: /* @__PURE__ */ jsxs(Flex, { gap: 3, alignItems: "center", children: [
|
|
547
|
-
/* @__PURE__ */ jsx(WarningCircle, { fill: "danger600" }),
|
|
548
|
-
/* @__PURE__ */ jsx(Typography, { textColor: "danger600", children: formatMessage(getTrad("enforce.warning")) })
|
|
549
|
-
] }) })
|
|
550
|
-
] }),
|
|
530
|
+
/* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 2, children: [
|
|
551
531
|
/* @__PURE__ */ jsxs(Flex, { alignItems: "center", gap: 3, wrap: "wrap", children: [
|
|
552
|
-
/* @__PURE__ */ jsx(Typography, { variant: "omega", style: { minWidth: "280px" }, children: formatMessage(getTrad("
|
|
532
|
+
/* @__PURE__ */ jsx(Typography, { variant: "omega", style: { minWidth: "280px" }, children: formatMessage(getTrad("enforce.title")) }),
|
|
553
533
|
/* @__PURE__ */ jsx(Box, { minWidth: "160px", children: /* @__PURE__ */ jsx(
|
|
554
534
|
CustomSwitch,
|
|
555
535
|
{
|
|
556
|
-
checked: state.
|
|
557
|
-
onChange: actions.
|
|
558
|
-
|
|
536
|
+
checked: state.enforceOIDC,
|
|
537
|
+
onChange: actions.onToggleEnforce,
|
|
538
|
+
disabled: state.enforceOIDCConfig !== null || state.useWhitelist && state.users.length === 0,
|
|
539
|
+
label: state.enforceOIDC ? formatMessage(getTrad("enforce.toggle.enabled")) : formatMessage(getTrad("enforce.toggle.disabled"))
|
|
559
540
|
}
|
|
560
541
|
) })
|
|
561
542
|
] }),
|
|
562
|
-
state.
|
|
563
|
-
/* @__PURE__ */ jsx(
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
children: formatMessage(getTrad("login.sso.button.text.label"))
|
|
571
|
-
}
|
|
572
|
-
),
|
|
573
|
-
/* @__PURE__ */ jsx(Box, { style: { flex: 1, minWidth: "160px" }, children: /* @__PURE__ */ jsx(
|
|
574
|
-
TextInput,
|
|
575
|
-
{
|
|
576
|
-
id: "sso-button-text",
|
|
577
|
-
"aria-label": formatMessage(getTrad("login.sso.button.text.label")),
|
|
578
|
-
value: state.ssoButtonText,
|
|
579
|
-
onChange: actions.onChangeSSOButtonText
|
|
580
|
-
}
|
|
581
|
-
) })
|
|
582
|
-
] })
|
|
543
|
+
state.enforceOIDCConfig !== null && /* @__PURE__ */ jsx(Box, { background: "primary100", padding: 3, hasRadius: true, children: /* @__PURE__ */ jsxs(Flex, { gap: 3, alignItems: "center", children: [
|
|
544
|
+
/* @__PURE__ */ jsx(Information, { fill: "primary600" }),
|
|
545
|
+
/* @__PURE__ */ jsx(Typography, { textColor: "primary600", children: formatMessage(getTrad("enforce.config.info")) })
|
|
546
|
+
] }) }),
|
|
547
|
+
state.enforceOIDCConfig === null && state.enforceOIDC && state.enforceOIDC !== state.initialEnforceOIDC && /* @__PURE__ */ jsx(Box, { background: "danger100", padding: 3, hasRadius: true, children: /* @__PURE__ */ jsxs(Flex, { gap: 3, alignItems: "center", children: [
|
|
548
|
+
/* @__PURE__ */ jsx(WarningCircle, { fill: "danger600" }),
|
|
549
|
+
/* @__PURE__ */ jsx(Typography, { textColor: "danger600", children: formatMessage(getTrad("enforce.warning")) })
|
|
550
|
+
] }) })
|
|
583
551
|
] })
|
|
584
552
|
] }),
|
|
585
553
|
/* @__PURE__ */ jsx(Flex, { justifyContent: "flex-end", children: /* @__PURE__ */ jsx(
|
|
@@ -50,11 +50,15 @@ const en = {
|
|
|
50
50
|
"roles.placeholder": "Select default role(s)",
|
|
51
51
|
"whitelist.title": "Whitelist",
|
|
52
52
|
"whitelist.error.unique": "Already registered email address.",
|
|
53
|
-
"whitelist.enabled": "Whitelist is currently enabled.",
|
|
54
|
-
"whitelist.disabled": "Whitelist is currently disabled.",
|
|
55
53
|
"whitelist.description": "Restrict OIDC authentication to specific email addresses and optionally assign them custom role(s).",
|
|
56
54
|
"whitelist.user_exists": "User already exists, matching existing role(s)",
|
|
57
55
|
"whitelist.users_exists": "Users already exist, matching existing role(s)",
|
|
56
|
+
"alert.title.success": "Success",
|
|
57
|
+
"alert.title.error": "Error",
|
|
58
|
+
"alert.title.info": "Info",
|
|
59
|
+
"pagination.previous": "Go to previous page",
|
|
60
|
+
"pagination.page": "Go to page {page}",
|
|
61
|
+
"pagination.next": "Go to next page",
|
|
58
62
|
"whitelist.table.no": "No.",
|
|
59
63
|
"whitelist.table.email": "Email",
|
|
60
64
|
"whitelist.table.created": "Created At",
|
|
@@ -66,7 +70,6 @@ const en = {
|
|
|
66
70
|
"whitelist.email.placeholder": "Email address",
|
|
67
71
|
"whitelist.roles.placeholder": "Select specific role(s)",
|
|
68
72
|
"whitelist.table.roles": "Role(s)",
|
|
69
|
-
"whitelist.table.roles.default": "Default",
|
|
70
73
|
"whitelist.table.empty": "No email addresses",
|
|
71
74
|
"whitelist.delete.label": "Delete",
|
|
72
75
|
"page.title.oidc": "OIDC",
|
|
@@ -74,15 +77,20 @@ const en = {
|
|
|
74
77
|
"enforce.toggle.enabled": "Enabled",
|
|
75
78
|
"enforce.toggle.disabled": "Disabled",
|
|
76
79
|
"enforce.warning": "Make sure OIDC is setup correctly before saving changes, you won't be able to login normally.",
|
|
80
|
+
"enforce.config.info": "Enforcement is controlled by the OIDC_ENFORCE config variable and cannot be changed here.",
|
|
77
81
|
"login.settings.title": "Login Settings",
|
|
78
|
-
"login.sso": "Login via SSO"
|
|
79
|
-
"login.sso.show": "Add button for OIDC on login screen",
|
|
80
|
-
"login.sso.button.text.label": "Login button text"
|
|
82
|
+
"login.sso": "Login via SSO"
|
|
81
83
|
};
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
84
|
+
function getTrad(id) {
|
|
85
|
+
const pluginIdWithId = `${pluginId}.${id}`;
|
|
86
|
+
return {
|
|
87
|
+
id: pluginIdWithId,
|
|
88
|
+
defaultMessage: en[id] || pluginIdWithId
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
function t(id) {
|
|
92
|
+
return en[id];
|
|
93
|
+
}
|
|
86
94
|
const name = pluginPkg.strapi.displayName;
|
|
87
95
|
const index = {
|
|
88
96
|
register(app) {
|
|
@@ -102,7 +110,7 @@ const index = {
|
|
|
102
110
|
defaultMessage: "Configuration"
|
|
103
111
|
},
|
|
104
112
|
Component: async () => {
|
|
105
|
-
return await Promise.resolve().then(() => require("./index-
|
|
113
|
+
return await Promise.resolve().then(() => require("./index-BqyGGX8X.js"));
|
|
106
114
|
},
|
|
107
115
|
permissions: [{ action: "plugin::strapi-plugin-oidc.read", subject: null }]
|
|
108
116
|
}
|
|
@@ -114,50 +122,11 @@ const index = {
|
|
|
114
122
|
});
|
|
115
123
|
},
|
|
116
124
|
bootstrap() {
|
|
117
|
-
|
|
118
|
-
let historyPatched = false;
|
|
119
|
-
const ENFORCE_CACHE_KEY = "strapi_oidc_enforced";
|
|
125
|
+
const defaultButtonText = t("login.sso");
|
|
120
126
|
const isAuthRoute = (path) => /\/auth\/(login|register|forgot-password|reset-password)/.test(path);
|
|
121
|
-
const patchHistory = () => {
|
|
122
|
-
if (historyPatched) return;
|
|
123
|
-
historyPatched = true;
|
|
124
|
-
const interceptHistory = (originalMethod) => {
|
|
125
|
-
return function(...args) {
|
|
126
|
-
const url = args[2];
|
|
127
|
-
if (url && typeof url === "string") {
|
|
128
|
-
const urlWithoutQuery = url.split("?")[0].split("#")[0];
|
|
129
|
-
if (isAuthRoute(urlWithoutQuery)) {
|
|
130
|
-
if (isLogoutInProgress) {
|
|
131
|
-
return;
|
|
132
|
-
}
|
|
133
|
-
if (sessionStorage.getItem("oidc_logout")) {
|
|
134
|
-
sessionStorage.removeItem("oidc_logout");
|
|
135
|
-
return originalMethod.apply(window.history, args);
|
|
136
|
-
}
|
|
137
|
-
document.documentElement.style.visibility = "hidden";
|
|
138
|
-
window.location.href = "/strapi-plugin-oidc/oidc";
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
return originalMethod.apply(window.history, args);
|
|
143
|
-
};
|
|
144
|
-
};
|
|
145
|
-
window.history.pushState = interceptHistory(window.history.pushState);
|
|
146
|
-
window.history.replaceState = interceptHistory(window.history.replaceState);
|
|
147
|
-
if (isAuthRoute(window.location.pathname)) {
|
|
148
|
-
if (sessionStorage.getItem("oidc_logout")) {
|
|
149
|
-
sessionStorage.removeItem("oidc_logout");
|
|
150
|
-
document.documentElement.style.visibility = "";
|
|
151
|
-
} else {
|
|
152
|
-
document.documentElement.style.visibility = "hidden";
|
|
153
|
-
window.location.replace("/strapi-plugin-oidc/oidc");
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
};
|
|
157
127
|
let ssoButtonInjected = false;
|
|
158
|
-
let
|
|
159
|
-
|
|
160
|
-
const injectSSOButton = () => {
|
|
128
|
+
let loginObserver = null;
|
|
129
|
+
const injectSSOButton = (buttonText) => {
|
|
161
130
|
if (ssoButtonInjected) return;
|
|
162
131
|
if (!isAuthRoute(window.location.pathname)) return;
|
|
163
132
|
if (document.getElementById("strapi-oidc-sso-btn")) return;
|
|
@@ -167,74 +136,75 @@ const index = {
|
|
|
167
136
|
btn.id = "strapi-oidc-sso-btn";
|
|
168
137
|
btn.type = "button";
|
|
169
138
|
btn.className = submitButton.className;
|
|
170
|
-
btn.style.marginTop = "8px";
|
|
171
139
|
btn.onclick = () => {
|
|
172
140
|
window.location.href = "/strapi-plugin-oidc/oidc";
|
|
173
141
|
};
|
|
174
142
|
const innerSpan = submitButton.querySelector("span");
|
|
175
143
|
const span = document.createElement("span");
|
|
176
144
|
if (innerSpan) span.className = innerSpan.className;
|
|
177
|
-
span.
|
|
145
|
+
span.style.display = "inline-flex";
|
|
146
|
+
span.style.alignItems = "center";
|
|
147
|
+
span.style.gap = "8px";
|
|
148
|
+
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
149
|
+
svg.setAttribute("width", "16");
|
|
150
|
+
svg.setAttribute("height", "16");
|
|
151
|
+
svg.setAttribute("viewBox", "0 0 24 24");
|
|
152
|
+
svg.setAttribute("fill", "none");
|
|
153
|
+
svg.setAttribute("stroke", "currentColor");
|
|
154
|
+
svg.setAttribute("stroke-width", "2");
|
|
155
|
+
svg.setAttribute("stroke-linecap", "round");
|
|
156
|
+
svg.setAttribute("stroke-linejoin", "round");
|
|
157
|
+
svg.setAttribute("aria-hidden", "true");
|
|
158
|
+
svg.innerHTML = '<path d="M2.586 17.414A2 2 0 0 0 2 18.828V21a1 1 0 0 0 1 1h3a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h1a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h.172a2 2 0 0 0 1.414-.586l.814-.814a6.5 6.5 0 1 0-4-4z"/><circle cx="16.5" cy="7.5" r=".5" fill="currentColor"/>';
|
|
159
|
+
span.appendChild(svg);
|
|
160
|
+
span.appendChild(document.createTextNode(buttonText));
|
|
178
161
|
btn.appendChild(span);
|
|
179
162
|
submitButton.parentNode.insertBefore(btn, submitButton.nextSibling);
|
|
180
163
|
ssoButtonInjected = true;
|
|
181
164
|
};
|
|
182
|
-
const
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
165
|
+
const removeEnforcedElements = () => {
|
|
166
|
+
[
|
|
167
|
+
'form > div > div:has(input[name="email"])',
|
|
168
|
+
'form > div > div:has(input[name="password"])',
|
|
169
|
+
'form > div > div:has(button[role="checkbox"])',
|
|
170
|
+
'form > div > button[type="submit"]:not(#strapi-oidc-sso-btn)'
|
|
171
|
+
].forEach((selector) => {
|
|
172
|
+
document.querySelectorAll(selector).forEach((el) => el.remove());
|
|
173
|
+
});
|
|
174
|
+
document.querySelectorAll('a[href*="forgot-password"]').forEach((el) => {
|
|
175
|
+
(el.closest("div")?.parentElement ?? el).remove();
|
|
187
176
|
});
|
|
188
|
-
ssoObserver.observe(document.body, { childList: true, subtree: true });
|
|
189
177
|
};
|
|
190
|
-
const
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
178
|
+
const startLoginObserver = (buttonText, enforced) => {
|
|
179
|
+
if (loginObserver) return;
|
|
180
|
+
const tick = () => {
|
|
181
|
+
if (!isAuthRoute(window.location.pathname)) return;
|
|
182
|
+
injectSSOButton(buttonText);
|
|
183
|
+
if (enforced) removeEnforcedElements();
|
|
184
|
+
};
|
|
185
|
+
tick();
|
|
186
|
+
loginObserver = new MutationObserver(tick);
|
|
187
|
+
loginObserver.observe(document.body, { childList: true, subtree: true });
|
|
195
188
|
};
|
|
196
|
-
|
|
197
|
-
document.documentElement.style.visibility = "hidden";
|
|
198
|
-
}
|
|
199
|
-
if (localStorage.getItem(ENFORCE_CACHE_KEY) === "1") {
|
|
200
|
-
patchHistory();
|
|
201
|
-
}
|
|
202
|
-
if (isAuthRoute(window.location.pathname)) {
|
|
203
|
-
document.documentElement.style.visibility = "hidden";
|
|
204
|
-
}
|
|
205
|
-
const checkEnforceOIDC = async () => {
|
|
189
|
+
const applySettings = async () => {
|
|
206
190
|
try {
|
|
207
191
|
const response = await window.fetch("/strapi-plugin-oidc/settings/public");
|
|
208
192
|
if (response.ok) {
|
|
209
193
|
const data = await response.json();
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
patchHistory();
|
|
214
|
-
} else {
|
|
215
|
-
localStorage.removeItem(ENFORCE_CACHE_KEY);
|
|
216
|
-
document.documentElement.style.visibility = "";
|
|
217
|
-
if (data.showSSOButton !== false) {
|
|
218
|
-
ssoButtonText = data.ssoButtonText || en["login.sso"];
|
|
219
|
-
startSSOButtonObserver();
|
|
220
|
-
} else {
|
|
221
|
-
stopSSOButtonObserver();
|
|
222
|
-
}
|
|
223
|
-
}
|
|
194
|
+
startLoginObserver(data.ssoButtonText || defaultButtonText, !!data.enforceOIDC);
|
|
195
|
+
} else {
|
|
196
|
+
startLoginObserver(defaultButtonText, false);
|
|
224
197
|
}
|
|
225
198
|
} catch (error) {
|
|
226
|
-
|
|
227
|
-
console.error("Failed to
|
|
199
|
+
startLoginObserver(defaultButtonText, false);
|
|
200
|
+
console.error("Failed to fetch OIDC settings:", error);
|
|
228
201
|
}
|
|
229
202
|
};
|
|
230
|
-
|
|
203
|
+
applySettings();
|
|
231
204
|
const originalFetch = window.fetch;
|
|
232
205
|
window.fetch = async (...args) => {
|
|
233
206
|
const url = typeof args[0] === "string" ? args[0] : args[0].url;
|
|
234
207
|
const isLogout = url && url.endsWith("/admin/logout") && args[1]?.method?.toUpperCase() === "POST";
|
|
235
|
-
if (isLogout) {
|
|
236
|
-
isLogoutInProgress = true;
|
|
237
|
-
}
|
|
238
208
|
const response = await originalFetch(...args);
|
|
239
209
|
if (isLogout && response.ok) {
|
|
240
210
|
window.localStorage.removeItem("jwtToken");
|
|
@@ -243,41 +213,30 @@ const index = {
|
|
|
243
213
|
window.sessionStorage.removeItem("isLoggedIn");
|
|
244
214
|
document.cookie = "jwtToken=;expires=Thu, 01 Jan 1970 00:00:00 GMT;path=/";
|
|
245
215
|
document.cookie = "jwtToken=;expires=Thu, 01 Jan 1970 00:00:00 GMT;path=/admin";
|
|
246
|
-
sessionStorage.setItem("oidc_logout", "1");
|
|
247
216
|
window.location.href = "/strapi-plugin-oidc/logout";
|
|
248
217
|
return new Promise(() => {
|
|
249
218
|
});
|
|
250
|
-
} else if (isLogout) {
|
|
251
|
-
isLogoutInProgress = false;
|
|
252
219
|
}
|
|
253
220
|
return response;
|
|
254
221
|
};
|
|
255
222
|
},
|
|
256
223
|
async registerTrads({ locales }) {
|
|
224
|
+
const transformKeys = (data) => Object.fromEntries(
|
|
225
|
+
Object.entries(data).map(([key, value]) => [
|
|
226
|
+
key.startsWith("global.") ? key : getTranslation(key),
|
|
227
|
+
value
|
|
228
|
+
])
|
|
229
|
+
);
|
|
257
230
|
const importedTrads = await Promise.all(
|
|
258
231
|
locales.map((locale) => {
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
value
|
|
264
|
-
])
|
|
265
|
-
);
|
|
266
|
-
return {
|
|
267
|
-
data: newData,
|
|
268
|
-
locale
|
|
269
|
-
};
|
|
270
|
-
}).catch(() => {
|
|
271
|
-
return {
|
|
272
|
-
data: {},
|
|
273
|
-
locale
|
|
274
|
-
};
|
|
275
|
-
});
|
|
232
|
+
if (locale === "en") {
|
|
233
|
+
return Promise.resolve({ data: transformKeys(en), locale });
|
|
234
|
+
}
|
|
235
|
+
return __variableDynamicImportRuntimeHelper(/* @__PURE__ */ Object.assign({}), `./translations/locales/${locale}.json`, 4).then(({ default: data }) => ({ data: transformKeys(data), locale })).catch(() => ({ data: {}, locale }));
|
|
276
236
|
})
|
|
277
237
|
);
|
|
278
|
-
return
|
|
238
|
+
return importedTrads;
|
|
279
239
|
}
|
|
280
240
|
};
|
|
281
|
-
exports.
|
|
241
|
+
exports.getTrad = getTrad;
|
|
282
242
|
exports.index = index;
|
|
283
|
-
exports.pluginId = pluginId;
|