strapi-plugin-oidc 1.6.3 → 1.6.4
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/dist/admin/{index-P9HriRms.mjs → index-AxBC5YLT.mjs} +8 -5
- package/dist/admin/{index-DTOcUHZi.js → index-DowwUs07.js} +81 -110
- package/dist/admin/{index-f3cmU_tE.js → index-EAfqxfV4.js} +8 -5
- package/dist/admin/{index-DmJadA2p.mjs → index-MnV7H8G6.mjs} +81 -110
- package/dist/admin/index.js +1 -1
- package/dist/admin/index.mjs +1 -1
- package/dist/server/index.js +131 -180
- package/dist/server/index.mjs +131 -180
- package/package.json +1 -1
|
@@ -5,7 +5,7 @@ import { useState, useRef, useCallback, useEffect, memo } from "react";
|
|
|
5
5
|
import { Typography, Flex, Box, MultiSelect, MultiSelectOption, Dialog, Button, Table, Pagination, PreviousLink, NextLink, PageLink, Field, Divider, Thead, Tr, Th, Tbody, Td, IconButton, Tooltip, Alert } from "@strapi/design-system";
|
|
6
6
|
import { WarningCircle, Download, Upload, Trash, Plus, Information } from "@strapi/icons";
|
|
7
7
|
import { useIntl } from "react-intl";
|
|
8
|
-
import { g as getTrad } from "./index-
|
|
8
|
+
import { g as getTrad } from "./index-AxBC5YLT.mjs";
|
|
9
9
|
import styled from "styled-components";
|
|
10
10
|
function Role({ oidcRoles, roles, onChangeRole }) {
|
|
11
11
|
const { formatMessage } = useIntl();
|
|
@@ -18,9 +18,7 @@ function Role({ oidcRoles, roles, onChangeRole }) {
|
|
|
18
18
|
placeholder: formatMessage(getTrad("roles.placeholder")),
|
|
19
19
|
value: oidcRole.role ? oidcRole.role.map((r) => String(r)) : [],
|
|
20
20
|
onChange: (value) => {
|
|
21
|
-
if (value && value.length > 0)
|
|
22
|
-
onChangeRole(value, oidcRole.oauth_type);
|
|
23
|
-
}
|
|
21
|
+
if (value && value.length > 0) onChangeRole(value, oidcRole.oauth_type);
|
|
24
22
|
},
|
|
25
23
|
children: roles.map((role) => /* @__PURE__ */ jsx(MultiSelectOption, { value: String(role.id), children: role.name }, role.id))
|
|
26
24
|
}
|
|
@@ -73,19 +71,11 @@ function ConfirmDialog({
|
|
|
73
71
|
function TablePagination({ page, pageCount, onPageChange }) {
|
|
74
72
|
const { formatMessage } = useIntl();
|
|
75
73
|
if (pageCount <= 1) return null;
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
onClick: (e) => {
|
|
82
|
-
e.preventDefault();
|
|
83
|
-
onPageChange(num);
|
|
84
|
-
},
|
|
85
|
-
children: formatMessage(getTrad("pagination.page"), { page: num })
|
|
86
|
-
},
|
|
87
|
-
num
|
|
88
|
-
);
|
|
74
|
+
const handleClick = (e, num) => {
|
|
75
|
+
e.preventDefault();
|
|
76
|
+
onPageChange(num);
|
|
77
|
+
};
|
|
78
|
+
const pageLink = (num) => /* @__PURE__ */ jsx(PageLink, { number: num, href: "#", onClick: (e) => handleClick(e, num), children: formatMessage(getTrad("pagination.page"), { page: num }) }, num);
|
|
89
79
|
const Ellipsis = () => /* @__PURE__ */ jsx(Typography, { textColor: "neutral600", paddingLeft: 2, paddingRight: 2, children: "…" });
|
|
90
80
|
let pages;
|
|
91
81
|
if (pageCount <= 10) {
|
|
@@ -112,31 +102,13 @@ function TablePagination({ page, pageCount, onPageChange }) {
|
|
|
112
102
|
] });
|
|
113
103
|
}
|
|
114
104
|
return /* @__PURE__ */ jsx(Box, { paddingTop: 4, children: /* @__PURE__ */ jsx(Flex, { justifyContent: "flex-end", children: /* @__PURE__ */ jsxs(Pagination, { activePage: page, pageCount, children: [
|
|
115
|
-
/* @__PURE__ */ jsx(
|
|
116
|
-
PreviousLink,
|
|
117
|
-
{
|
|
118
|
-
href: "#",
|
|
119
|
-
onClick: (e) => {
|
|
120
|
-
e.preventDefault();
|
|
121
|
-
onPageChange(Math.max(1, page - 1));
|
|
122
|
-
},
|
|
123
|
-
children: formatMessage(getTrad("pagination.previous"))
|
|
124
|
-
}
|
|
125
|
-
),
|
|
105
|
+
/* @__PURE__ */ jsx(PreviousLink, { href: "#", onClick: (e) => handleClick(e, Math.max(1, page - 1)), children: formatMessage(getTrad("pagination.previous")) }),
|
|
126
106
|
pages,
|
|
127
|
-
/* @__PURE__ */ jsx(
|
|
128
|
-
NextLink,
|
|
129
|
-
{
|
|
130
|
-
href: "#",
|
|
131
|
-
onClick: (e) => {
|
|
132
|
-
e.preventDefault();
|
|
133
|
-
onPageChange(Math.min(pageCount, page + 1));
|
|
134
|
-
},
|
|
135
|
-
children: formatMessage(getTrad("pagination.next"))
|
|
136
|
-
}
|
|
137
|
-
)
|
|
107
|
+
/* @__PURE__ */ jsx(NextLink, { href: "#", onClick: (e) => handleClick(e, Math.min(pageCount, page + 1)), children: formatMessage(getTrad("pagination.next")) })
|
|
138
108
|
] }) }) });
|
|
139
109
|
}
|
|
110
|
+
const PAGE_SIZE$1 = 10;
|
|
111
|
+
const EMAIL_REGEX = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
140
112
|
function Whitelist({
|
|
141
113
|
users,
|
|
142
114
|
useWhitelist,
|
|
@@ -152,11 +124,8 @@ function Whitelist({
|
|
|
152
124
|
const { formatMessage } = useIntl();
|
|
153
125
|
const { toggleNotification } = useNotification();
|
|
154
126
|
const fileInputRef = useRef(null);
|
|
155
|
-
const
|
|
156
|
-
const
|
|
157
|
-
const paginatedUsers = users.slice((page - 1) * PAGE_SIZE2, page * PAGE_SIZE2);
|
|
158
|
-
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
159
|
-
const isValidEmail = emailRegex.test(email);
|
|
127
|
+
const pageCount = Math.ceil(users.length / PAGE_SIZE$1) || 1;
|
|
128
|
+
const paginatedUsers = users.slice((page - 1) * PAGE_SIZE$1, page * PAGE_SIZE$1);
|
|
160
129
|
const onSaveEmail = useCallback(() => {
|
|
161
130
|
const emailText = email.trim();
|
|
162
131
|
if (users.some((user) => user.email === emailText)) {
|
|
@@ -172,14 +141,15 @@ function Whitelist({
|
|
|
172
141
|
const handleImport = useCallback(
|
|
173
142
|
async (e) => {
|
|
174
143
|
const file = e.target.files?.[0];
|
|
175
|
-
if (!fileInputRef.current) return;
|
|
144
|
+
if (!fileInputRef.current || !file) return;
|
|
176
145
|
fileInputRef.current.value = "";
|
|
177
|
-
if (!file) return;
|
|
178
146
|
try {
|
|
179
147
|
const text = await file.text();
|
|
180
148
|
const parsed = JSON.parse(text);
|
|
181
149
|
if (!Array.isArray(parsed)) throw new Error();
|
|
182
|
-
const emails = parsed.filter((item) => item?.email).map(
|
|
150
|
+
const emails = parsed.filter((item) => item?.email).map(
|
|
151
|
+
(item) => String(item.email).trim().toLowerCase()
|
|
152
|
+
).filter((email2) => EMAIL_REGEX.test(email2));
|
|
183
153
|
const count = await onImport(emails);
|
|
184
154
|
if (count === 0) {
|
|
185
155
|
toggleNotification({
|
|
@@ -259,7 +229,7 @@ function Whitelist({
|
|
|
259
229
|
type: "text",
|
|
260
230
|
disabled: loading,
|
|
261
231
|
value: email,
|
|
262
|
-
hasError: Boolean(email && !
|
|
232
|
+
hasError: Boolean(email && !EMAIL_REGEX.test(email)),
|
|
263
233
|
onChange: (e) => setEmail(e.currentTarget.value),
|
|
264
234
|
placeholder: formatMessage(getTrad("whitelist.email.placeholder"))
|
|
265
235
|
}
|
|
@@ -269,7 +239,7 @@ function Whitelist({
|
|
|
269
239
|
{
|
|
270
240
|
size: "L",
|
|
271
241
|
startIcon: /* @__PURE__ */ jsx(Plus, {}),
|
|
272
|
-
disabled: loading || email.trim() === "" || !
|
|
242
|
+
disabled: loading || email.trim() === "" || !EMAIL_REGEX.test(email),
|
|
273
243
|
loading,
|
|
274
244
|
onClick: onSaveEmail,
|
|
275
245
|
children: formatMessage(getTrad("page.add"))
|
|
@@ -285,7 +255,7 @@ function Whitelist({
|
|
|
285
255
|
/* @__PURE__ */ jsx(Th, { style: { paddingRight: 0 }, children: " " })
|
|
286
256
|
] }) }),
|
|
287
257
|
/* @__PURE__ */ jsx(Tbody, { children: users.length === 0 ? /* @__PURE__ */ jsx(Tr, { children: /* @__PURE__ */ jsx(Td, { colSpan: 4, children: /* @__PURE__ */ jsx(Flex, { justifyContent: "center", padding: 4, children: /* @__PURE__ */ jsx(Typography, { textColor: "neutral600", children: formatMessage(getTrad("whitelist.table.empty")) }) }) }) }) : paginatedUsers.map((user, index) => /* @__PURE__ */ jsxs(Tr, { children: [
|
|
288
|
-
/* @__PURE__ */ jsx(Td, { children: index + 1 + (page - 1) *
|
|
258
|
+
/* @__PURE__ */ jsx(Td, { children: index + 1 + (page - 1) * PAGE_SIZE$1 }),
|
|
289
259
|
/* @__PURE__ */ jsx(Td, { children: user.email }),
|
|
290
260
|
/* @__PURE__ */ jsx(Td, { children: /* @__PURE__ */ jsx(LocalizedDate, { date: user.createdAt, options: { month: "long" } }) }),
|
|
291
261
|
/* @__PURE__ */ jsx(Td, { style: { paddingRight: 0 }, children: /* @__PURE__ */ jsx(
|
|
@@ -463,7 +433,7 @@ function AuditLog() {
|
|
|
463
433
|
/* @__PURE__ */ jsx(Th, { children: formatMessage(getTrad("auditlog.table.details")) })
|
|
464
434
|
] }) }),
|
|
465
435
|
/* @__PURE__ */ jsxs(Tbody, { children: [
|
|
466
|
-
loading && /* @__PURE__ */ jsx(Tr, { children: /* @__PURE__ */ jsx(Td, { colSpan: 5, children: /* @__PURE__ */ jsx(Flex, { justifyContent: "center", padding: 4, children: /* @__PURE__ */ jsx(Typography, { textColor: "neutral600", children: "
|
|
436
|
+
loading && /* @__PURE__ */ jsx(Tr, { children: /* @__PURE__ */ jsx(Td, { colSpan: 5, children: /* @__PURE__ */ jsx(Flex, { justifyContent: "center", padding: 4, children: /* @__PURE__ */ jsx(Typography, { textColor: "neutral600", children: formatMessage(getTrad("auditlog.loading")) }) }) }) }),
|
|
467
437
|
!loading && records.length === 0 && /* @__PURE__ */ jsx(Tr, { children: /* @__PURE__ */ jsx(Td, { colSpan: 5, children: /* @__PURE__ */ jsx(Flex, { justifyContent: "center", padding: 4, children: /* @__PURE__ */ jsx(Typography, { textColor: "neutral600", children: formatMessage(getTrad("auditlog.table.empty")) }) }) }) }),
|
|
468
438
|
!loading && records.map((record) => /* @__PURE__ */ jsxs(Tr, { children: [
|
|
469
439
|
/* @__PURE__ */ jsx(Td, { children: /* @__PURE__ */ jsx(Typography, { variant: "omega", children: /* @__PURE__ */ jsx(LocalizedDate, { date: record.createdAt, options: { second: "2-digit" } }) }) }),
|
|
@@ -629,47 +599,52 @@ function useOidcSettings() {
|
|
|
629
599
|
setRoles(response.data.data);
|
|
630
600
|
});
|
|
631
601
|
get("/strapi-plugin-oidc/whitelist").then((response) => {
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
602
|
+
const data = response.data;
|
|
603
|
+
setWhitelistResponse(data);
|
|
604
|
+
setUsers(data.whitelistUsers);
|
|
605
|
+
setInitialUsers(deepClone(data.whitelistUsers));
|
|
606
|
+
setUseWhitelist(data.useWhitelist);
|
|
607
|
+
setInitialUseWhitelist(data.useWhitelist);
|
|
608
|
+
setEnforceOIDC(data.enforceOIDC);
|
|
609
|
+
setInitialEnforceOIDC(data.enforceOIDC);
|
|
610
|
+
setEnforceOIDCConfig(data.enforceOIDCConfig ?? null);
|
|
640
611
|
});
|
|
641
612
|
}, [get]);
|
|
642
|
-
const onChangeRole = (values, oidcId) => {
|
|
643
|
-
|
|
644
|
-
(role) => role.oauth_type === oidcId ? { ...role, role: values } : role
|
|
613
|
+
const onChangeRole = useCallback((values, oidcId) => {
|
|
614
|
+
setOIDCRoles(
|
|
615
|
+
(prev) => prev.map((role) => role.oauth_type === oidcId ? { ...role, role: values } : role)
|
|
645
616
|
);
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
}
|
|
658
|
-
|
|
659
|
-
|
|
617
|
+
}, []);
|
|
618
|
+
const onRegisterWhitelist = useCallback((email) => {
|
|
619
|
+
setUsers((prev) => [...prev, { email, createdAt: (/* @__PURE__ */ new Date()).toISOString() }]);
|
|
620
|
+
}, []);
|
|
621
|
+
const onDeleteWhitelist = useCallback(
|
|
622
|
+
(email) => {
|
|
623
|
+
setUsers((prev) => {
|
|
624
|
+
const updated = prev.filter((u) => u.email !== email);
|
|
625
|
+
if (useWhitelist && updated.length === 0) setEnforceOIDC(false);
|
|
626
|
+
return updated;
|
|
627
|
+
});
|
|
628
|
+
},
|
|
629
|
+
[useWhitelist]
|
|
630
|
+
);
|
|
631
|
+
const onDeleteAll = useCallback(() => {
|
|
660
632
|
setUsers([]);
|
|
661
633
|
if (useWhitelist) setEnforceOIDC(false);
|
|
662
|
-
};
|
|
663
|
-
const onImport =
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
634
|
+
}, [useWhitelist]);
|
|
635
|
+
const onImport = useCallback(
|
|
636
|
+
async (emails) => {
|
|
637
|
+
const response = await post("/strapi-plugin-oidc/whitelist/import", {
|
|
638
|
+
users: emails.map((e) => ({ email: e }))
|
|
639
|
+
});
|
|
640
|
+
const refreshed = await get("/strapi-plugin-oidc/whitelist");
|
|
641
|
+
setUsers(refreshed.data.whitelistUsers);
|
|
642
|
+
setInitialUsers(deepClone(refreshed.data.whitelistUsers));
|
|
643
|
+
return response.data.importedCount;
|
|
644
|
+
},
|
|
645
|
+
[post, get]
|
|
646
|
+
);
|
|
647
|
+
const onExport = useCallback(async () => {
|
|
673
648
|
const response = await get("/strapi-plugin-oidc/whitelist/export");
|
|
674
649
|
const data = response.data;
|
|
675
650
|
const datetime = formatDatetimeForFilename(/* @__PURE__ */ new Date());
|
|
@@ -680,41 +655,37 @@ function useOidcSettings() {
|
|
|
680
655
|
a.download = `strapi-oidc-whitelist-${datetime}.json`;
|
|
681
656
|
a.click();
|
|
682
657
|
URL.revokeObjectURL(url);
|
|
683
|
-
};
|
|
684
|
-
const onToggleWhitelist = (
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
setEnforceOIDC(false);
|
|
689
|
-
}
|
|
690
|
-
|
|
691
|
-
|
|
658
|
+
}, [get]);
|
|
659
|
+
const onToggleWhitelist = useCallback(
|
|
660
|
+
(e) => {
|
|
661
|
+
const checked = e.target.checked;
|
|
662
|
+
setUseWhitelist(checked);
|
|
663
|
+
if (checked && users.length === 0) setEnforceOIDC(false);
|
|
664
|
+
},
|
|
665
|
+
[users.length]
|
|
666
|
+
);
|
|
667
|
+
const onToggleEnforce = useCallback((e) => {
|
|
692
668
|
setEnforceOIDC(e.target.checked);
|
|
693
|
-
};
|
|
669
|
+
}, []);
|
|
694
670
|
const isDirty = useWhitelist !== initialUseWhitelist || enforceOIDC !== initialEnforceOIDC || JSON.stringify(oidcRoles) !== JSON.stringify(initialOidcRoles) || JSON.stringify(users) !== JSON.stringify(initialUsers);
|
|
695
|
-
const onSaveAll = async () => {
|
|
671
|
+
const onSaveAll = useCallback(async () => {
|
|
696
672
|
setLoading(true);
|
|
697
673
|
try {
|
|
698
674
|
await put("/strapi-plugin-oidc/oidc-roles", {
|
|
699
|
-
roles: oidcRoles.map((role) => ({
|
|
700
|
-
oauth_type: role.oauth_type,
|
|
701
|
-
role: role.role
|
|
702
|
-
}))
|
|
675
|
+
roles: oidcRoles.map((role) => ({ oauth_type: role.oauth_type, role: role.role }))
|
|
703
676
|
});
|
|
704
677
|
await put("/strapi-plugin-oidc/whitelist/sync", {
|
|
705
678
|
users: users.map((u) => ({ email: u.email }))
|
|
706
679
|
});
|
|
707
|
-
await put("/strapi-plugin-oidc/whitelist/settings", {
|
|
708
|
-
useWhitelist,
|
|
709
|
-
enforceOIDC
|
|
710
|
-
});
|
|
680
|
+
await put("/strapi-plugin-oidc/whitelist/settings", { useWhitelist, enforceOIDC });
|
|
711
681
|
setInitialOIDCRoles(deepClone(oidcRoles));
|
|
712
682
|
setInitialUseWhitelist(useWhitelist);
|
|
713
683
|
setInitialEnforceOIDC(enforceOIDC);
|
|
714
684
|
get("/strapi-plugin-oidc/whitelist").then((getResponse) => {
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
685
|
+
const data = getResponse.data;
|
|
686
|
+
setWhitelistResponse(data);
|
|
687
|
+
setUsers(data.whitelistUsers);
|
|
688
|
+
setInitialUsers(deepClone(data.whitelistUsers));
|
|
718
689
|
});
|
|
719
690
|
setSuccess(true);
|
|
720
691
|
setTimeout(() => setSuccess(false), 3e3);
|
|
@@ -725,7 +696,7 @@ function useOidcSettings() {
|
|
|
725
696
|
} finally {
|
|
726
697
|
setLoading(false);
|
|
727
698
|
}
|
|
728
|
-
};
|
|
699
|
+
}, [put, get, oidcRoles, users, useWhitelist, enforceOIDC]);
|
|
729
700
|
return {
|
|
730
701
|
state: {
|
|
731
702
|
loading,
|
package/dist/admin/index.js
CHANGED
package/dist/admin/index.mjs
CHANGED