strapi-plugin-oidc 1.6.3 → 1.6.5
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-f3cmU_tE.js → index-C2BnnDzh.js} +8 -8
- package/dist/admin/{index-P9HriRms.mjs → index-DgUClS5s.mjs} +8 -8
- package/dist/admin/{index-DmJadA2p.mjs → index-HQ2uuypE.mjs} +81 -110
- package/dist/admin/{index-DTOcUHZi.js → index-pWwCtdNu.js} +81 -110
- package/dist/admin/index.js +1 -1
- package/dist/admin/index.mjs +1 -1
- package/dist/server/index.js +131 -183
- package/dist/server/index.mjs +131 -183
- package/package.json +1 -1
|
@@ -66,8 +66,6 @@ const en = {
|
|
|
66
66
|
"whitelist.toggle.enabled": "Enabled",
|
|
67
67
|
"whitelist.toggle.disabled": "Disabled",
|
|
68
68
|
"whitelist.email.placeholder": "Email address",
|
|
69
|
-
"whitelist.roles.placeholder": "Select specific role(s)",
|
|
70
|
-
"whitelist.table.roles": "Role(s)",
|
|
71
69
|
"whitelist.table.empty": "No email addresses",
|
|
72
70
|
"whitelist.delete.label": "Delete",
|
|
73
71
|
"page.title.oidc": "OIDC",
|
|
@@ -91,7 +89,6 @@ const en = {
|
|
|
91
89
|
"unsaved.description": "You have unsaved changes that will be lost if you leave. Do you want to continue?",
|
|
92
90
|
"unsaved.confirm": "Leave",
|
|
93
91
|
"unsaved.cancel": "Stay",
|
|
94
|
-
"whitelist.table.roles.default": "(Default)",
|
|
95
92
|
"auditlog.title": "Audit Logs",
|
|
96
93
|
"auditlog.export": "Download",
|
|
97
94
|
"auditlog.table.timestamp": "Timestamp",
|
|
@@ -100,6 +97,7 @@ const en = {
|
|
|
100
97
|
"auditlog.table.ip": "IP",
|
|
101
98
|
"auditlog.table.details": "Details",
|
|
102
99
|
"auditlog.table.empty": "No audit log entries",
|
|
100
|
+
"auditlog.loading": "Loading…",
|
|
103
101
|
"auditlog.clear": "Clear Logs",
|
|
104
102
|
"auditlog.clear.title": "Clear All Logs",
|
|
105
103
|
"auditlog.clear.description": "This will permanently delete all {count, plural, one {# audit log entry} other {# audit log entries}}. This action cannot be undone.",
|
|
@@ -118,7 +116,9 @@ const en = {
|
|
|
118
116
|
"auditlog.action.whitelist_rejected": "The user's email address is not on the whitelist. Access was denied.",
|
|
119
117
|
"user.missing_code": "Authorisation code was not received from the OIDC provider.",
|
|
120
118
|
"user.invalid_state": "State parameter mismatch. Please restart the login flow.",
|
|
121
|
-
"user.signInError": "Authentication failed. Please try again."
|
|
119
|
+
"user.signInError": "Authentication failed. Please try again.",
|
|
120
|
+
"settings.section": "OIDC",
|
|
121
|
+
"settings.configuration": "Configuration"
|
|
122
122
|
};
|
|
123
123
|
function getTrad(id) {
|
|
124
124
|
const pluginIdWithId = `${pluginId}.${id}`;
|
|
@@ -137,7 +137,7 @@ const index = {
|
|
|
137
137
|
{
|
|
138
138
|
id: "oidc",
|
|
139
139
|
intlLabel: {
|
|
140
|
-
id:
|
|
140
|
+
id: "settings.section",
|
|
141
141
|
defaultMessage: "OIDC"
|
|
142
142
|
}
|
|
143
143
|
},
|
|
@@ -145,11 +145,11 @@ const index = {
|
|
|
145
145
|
id: "configuration",
|
|
146
146
|
to: `/settings/${pluginId}`,
|
|
147
147
|
intlLabel: {
|
|
148
|
-
id:
|
|
148
|
+
id: "settings.configuration",
|
|
149
149
|
defaultMessage: "Configuration"
|
|
150
150
|
},
|
|
151
151
|
Component: async () => {
|
|
152
|
-
return await Promise.resolve().then(() => require("./index-
|
|
152
|
+
return await Promise.resolve().then(() => require("./index-pWwCtdNu.js"));
|
|
153
153
|
},
|
|
154
154
|
permissions: [{ action: "plugin::strapi-plugin-oidc.read", subject: null }]
|
|
155
155
|
}
|
|
@@ -243,7 +243,7 @@ const index = {
|
|
|
243
243
|
const originalFetch = window.fetch;
|
|
244
244
|
window.fetch = async (...args) => {
|
|
245
245
|
const url = typeof args[0] === "string" ? args[0] : args[0].url;
|
|
246
|
-
const isLogout = url
|
|
246
|
+
const isLogout = url?.endsWith("/admin/logout") && args[1]?.method?.toUpperCase() === "POST";
|
|
247
247
|
const response = await originalFetch(...args);
|
|
248
248
|
if (isLogout && response.ok) {
|
|
249
249
|
window.localStorage.removeItem("jwtToken");
|
|
@@ -65,8 +65,6 @@ const en = {
|
|
|
65
65
|
"whitelist.toggle.enabled": "Enabled",
|
|
66
66
|
"whitelist.toggle.disabled": "Disabled",
|
|
67
67
|
"whitelist.email.placeholder": "Email address",
|
|
68
|
-
"whitelist.roles.placeholder": "Select specific role(s)",
|
|
69
|
-
"whitelist.table.roles": "Role(s)",
|
|
70
68
|
"whitelist.table.empty": "No email addresses",
|
|
71
69
|
"whitelist.delete.label": "Delete",
|
|
72
70
|
"page.title.oidc": "OIDC",
|
|
@@ -90,7 +88,6 @@ const en = {
|
|
|
90
88
|
"unsaved.description": "You have unsaved changes that will be lost if you leave. Do you want to continue?",
|
|
91
89
|
"unsaved.confirm": "Leave",
|
|
92
90
|
"unsaved.cancel": "Stay",
|
|
93
|
-
"whitelist.table.roles.default": "(Default)",
|
|
94
91
|
"auditlog.title": "Audit Logs",
|
|
95
92
|
"auditlog.export": "Download",
|
|
96
93
|
"auditlog.table.timestamp": "Timestamp",
|
|
@@ -99,6 +96,7 @@ const en = {
|
|
|
99
96
|
"auditlog.table.ip": "IP",
|
|
100
97
|
"auditlog.table.details": "Details",
|
|
101
98
|
"auditlog.table.empty": "No audit log entries",
|
|
99
|
+
"auditlog.loading": "Loading…",
|
|
102
100
|
"auditlog.clear": "Clear Logs",
|
|
103
101
|
"auditlog.clear.title": "Clear All Logs",
|
|
104
102
|
"auditlog.clear.description": "This will permanently delete all {count, plural, one {# audit log entry} other {# audit log entries}}. This action cannot be undone.",
|
|
@@ -117,7 +115,9 @@ const en = {
|
|
|
117
115
|
"auditlog.action.whitelist_rejected": "The user's email address is not on the whitelist. Access was denied.",
|
|
118
116
|
"user.missing_code": "Authorisation code was not received from the OIDC provider.",
|
|
119
117
|
"user.invalid_state": "State parameter mismatch. Please restart the login flow.",
|
|
120
|
-
"user.signInError": "Authentication failed. Please try again."
|
|
118
|
+
"user.signInError": "Authentication failed. Please try again.",
|
|
119
|
+
"settings.section": "OIDC",
|
|
120
|
+
"settings.configuration": "Configuration"
|
|
121
121
|
};
|
|
122
122
|
function getTrad(id) {
|
|
123
123
|
const pluginIdWithId = `${pluginId}.${id}`;
|
|
@@ -136,7 +136,7 @@ const index = {
|
|
|
136
136
|
{
|
|
137
137
|
id: "oidc",
|
|
138
138
|
intlLabel: {
|
|
139
|
-
id:
|
|
139
|
+
id: "settings.section",
|
|
140
140
|
defaultMessage: "OIDC"
|
|
141
141
|
}
|
|
142
142
|
},
|
|
@@ -144,11 +144,11 @@ const index = {
|
|
|
144
144
|
id: "configuration",
|
|
145
145
|
to: `/settings/${pluginId}`,
|
|
146
146
|
intlLabel: {
|
|
147
|
-
id:
|
|
147
|
+
id: "settings.configuration",
|
|
148
148
|
defaultMessage: "Configuration"
|
|
149
149
|
},
|
|
150
150
|
Component: async () => {
|
|
151
|
-
return await import("./index-
|
|
151
|
+
return await import("./index-HQ2uuypE.mjs");
|
|
152
152
|
},
|
|
153
153
|
permissions: [{ action: "plugin::strapi-plugin-oidc.read", subject: null }]
|
|
154
154
|
}
|
|
@@ -242,7 +242,7 @@ const index = {
|
|
|
242
242
|
const originalFetch = window.fetch;
|
|
243
243
|
window.fetch = async (...args) => {
|
|
244
244
|
const url = typeof args[0] === "string" ? args[0] : args[0].url;
|
|
245
|
-
const isLogout = url
|
|
245
|
+
const isLogout = url?.endsWith("/admin/logout") && args[1]?.method?.toUpperCase() === "POST";
|
|
246
246
|
const response = await originalFetch(...args);
|
|
247
247
|
if (isLogout && response.ok) {
|
|
248
248
|
window.localStorage.removeItem("jwtToken");
|
|
@@ -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-DgUClS5s.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,
|