strapi-plugin-oidc 1.2.3 → 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-DZwncy7E.js → index-BqyGGX8X.js} +80 -90
- package/dist/admin/{index-DuJfeoFu.mjs → index-CFmg9Kxl.mjs} +56 -66
- package/dist/admin/{index-ENl8_IZn.js → index-Cse9ex24.js} +78 -103
- package/dist/admin/{index-CZ_FdaEz.mjs → index-D1ypRUlq.mjs} +79 -104
- package/dist/admin/index.js +1 -1
- package/dist/admin/index.mjs +1 -1
- package/dist/server/index.js +63 -49
- package/dist/server/index.mjs +63 -49
- 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,6 +359,7 @@ 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
365
|
useEffect(() => {
|
|
@@ -359,6 +377,7 @@ function useOidcSettings() {
|
|
|
359
377
|
setInitialUseWhitelist(response.data.useWhitelist);
|
|
360
378
|
setEnforceOIDC(response.data.enforceOIDC);
|
|
361
379
|
setInitialEnforceOIDC(response.data.enforceOIDC);
|
|
380
|
+
setEnforceOIDCConfig(response.data.enforceOIDCConfig ?? null);
|
|
362
381
|
});
|
|
363
382
|
}, [get]);
|
|
364
383
|
const onChangeRole = (values, oidcId) => {
|
|
@@ -437,6 +456,7 @@ function useOidcSettings() {
|
|
|
437
456
|
roles,
|
|
438
457
|
useWhitelist,
|
|
439
458
|
enforceOIDC,
|
|
459
|
+
enforceOIDCConfig,
|
|
440
460
|
initialEnforceOIDC,
|
|
441
461
|
users,
|
|
442
462
|
isDirty
|
|
@@ -507,57 +527,27 @@ function HomePage() {
|
|
|
507
527
|
] }),
|
|
508
528
|
/* @__PURE__ */ jsxs(Box, { background: "neutral0", hasRadius: true, shadow: "filterShadow", padding: 6, children: [
|
|
509
529
|
/* @__PURE__ */ jsx(Box, { paddingBottom: 6, children: /* @__PURE__ */ jsx(Typography, { variant: "beta", tag: "h2", children: formatMessage(getTrad("login.settings.title")) }) }),
|
|
510
|
-
/* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap:
|
|
511
|
-
/* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 2, children: [
|
|
512
|
-
/* @__PURE__ */ jsxs(Flex, { alignItems: "center", gap: 3, wrap: "wrap", children: [
|
|
513
|
-
/* @__PURE__ */ jsx(Typography, { variant: "omega", style: { minWidth: "280px" }, children: formatMessage(getTrad("enforce.title")) }),
|
|
514
|
-
/* @__PURE__ */ jsx(Box, { minWidth: "160px", children: /* @__PURE__ */ jsx(
|
|
515
|
-
CustomSwitch,
|
|
516
|
-
{
|
|
517
|
-
checked: state.enforceOIDC,
|
|
518
|
-
onChange: actions.onToggleEnforce,
|
|
519
|
-
disabled: state.useWhitelist && state.users.length === 0,
|
|
520
|
-
label: state.enforceOIDC ? formatMessage(getTrad("enforce.toggle.enabled")) : formatMessage(getTrad("enforce.toggle.disabled"))
|
|
521
|
-
}
|
|
522
|
-
) })
|
|
523
|
-
] }),
|
|
524
|
-
state.enforceOIDC && state.enforceOIDC !== state.initialEnforceOIDC && /* @__PURE__ */ jsx(Box, { background: "danger100", padding: 3, hasRadius: true, children: /* @__PURE__ */ jsxs(Flex, { gap: 3, alignItems: "center", children: [
|
|
525
|
-
/* @__PURE__ */ jsx(WarningCircle, { fill: "danger600" }),
|
|
526
|
-
/* @__PURE__ */ jsx(Typography, { textColor: "danger600", children: formatMessage(getTrad("enforce.warning")) })
|
|
527
|
-
] }) })
|
|
528
|
-
] }),
|
|
530
|
+
/* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 2, children: [
|
|
529
531
|
/* @__PURE__ */ jsxs(Flex, { alignItems: "center", gap: 3, wrap: "wrap", children: [
|
|
530
|
-
/* @__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")) }),
|
|
531
533
|
/* @__PURE__ */ jsx(Box, { minWidth: "160px", children: /* @__PURE__ */ jsx(
|
|
532
534
|
CustomSwitch,
|
|
533
535
|
{
|
|
534
|
-
checked: state.
|
|
535
|
-
onChange: actions.
|
|
536
|
-
|
|
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"))
|
|
537
540
|
}
|
|
538
541
|
) })
|
|
539
542
|
] }),
|
|
540
|
-
state.
|
|
541
|
-
/* @__PURE__ */ jsx(
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
children: formatMessage(getTrad("login.sso.button.text.label"))
|
|
549
|
-
}
|
|
550
|
-
),
|
|
551
|
-
/* @__PURE__ */ jsx(Box, { style: { flex: 1, minWidth: "160px" }, children: /* @__PURE__ */ jsx(
|
|
552
|
-
TextInput,
|
|
553
|
-
{
|
|
554
|
-
id: "sso-button-text",
|
|
555
|
-
"aria-label": formatMessage(getTrad("login.sso.button.text.label")),
|
|
556
|
-
value: state.ssoButtonText,
|
|
557
|
-
onChange: actions.onChangeSSOButtonText
|
|
558
|
-
}
|
|
559
|
-
) })
|
|
560
|
-
] })
|
|
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
|
+
] }) })
|
|
561
551
|
] })
|
|
562
552
|
] }),
|
|
563
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,12 +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.",
|
|
81
|
+
"login.settings.title": "Login Settings",
|
|
77
82
|
"login.sso": "Login via SSO"
|
|
78
83
|
};
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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
|
+
}
|
|
83
94
|
const name = pluginPkg.strapi.displayName;
|
|
84
95
|
const index = {
|
|
85
96
|
register(app) {
|
|
@@ -99,7 +110,7 @@ const index = {
|
|
|
99
110
|
defaultMessage: "Configuration"
|
|
100
111
|
},
|
|
101
112
|
Component: async () => {
|
|
102
|
-
return await Promise.resolve().then(() => require("./index-
|
|
113
|
+
return await Promise.resolve().then(() => require("./index-BqyGGX8X.js"));
|
|
103
114
|
},
|
|
104
115
|
permissions: [{ action: "plugin::strapi-plugin-oidc.read", subject: null }]
|
|
105
116
|
}
|
|
@@ -111,41 +122,11 @@ const index = {
|
|
|
111
122
|
});
|
|
112
123
|
},
|
|
113
124
|
bootstrap() {
|
|
114
|
-
|
|
115
|
-
let historyPatched = false;
|
|
116
|
-
const ENFORCE_CACHE_KEY = "strapi_oidc_enforced";
|
|
125
|
+
const defaultButtonText = t("login.sso");
|
|
117
126
|
const isAuthRoute = (path) => /\/auth\/(login|register|forgot-password|reset-password)/.test(path);
|
|
118
|
-
const patchHistory = () => {
|
|
119
|
-
if (historyPatched) return;
|
|
120
|
-
historyPatched = true;
|
|
121
|
-
const interceptHistory = (originalMethod) => {
|
|
122
|
-
return function(...args) {
|
|
123
|
-
const url = args[2];
|
|
124
|
-
if (url && typeof url === "string") {
|
|
125
|
-
const urlWithoutQuery = url.split("?")[0].split("#")[0];
|
|
126
|
-
if (isAuthRoute(urlWithoutQuery)) {
|
|
127
|
-
if (isLogoutInProgress) {
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
|
-
document.documentElement.style.visibility = "hidden";
|
|
131
|
-
window.location.href = "/strapi-plugin-oidc/oidc";
|
|
132
|
-
return;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
return originalMethod.apply(window.history, args);
|
|
136
|
-
};
|
|
137
|
-
};
|
|
138
|
-
window.history.pushState = interceptHistory(window.history.pushState);
|
|
139
|
-
window.history.replaceState = interceptHistory(window.history.replaceState);
|
|
140
|
-
if (isAuthRoute(window.location.pathname)) {
|
|
141
|
-
document.documentElement.style.visibility = "hidden";
|
|
142
|
-
window.location.replace("/strapi-plugin-oidc/oidc");
|
|
143
|
-
}
|
|
144
|
-
};
|
|
145
127
|
let ssoButtonInjected = false;
|
|
146
|
-
let
|
|
147
|
-
|
|
148
|
-
const injectSSOButton = () => {
|
|
128
|
+
let loginObserver = null;
|
|
129
|
+
const injectSSOButton = (buttonText) => {
|
|
149
130
|
if (ssoButtonInjected) return;
|
|
150
131
|
if (!isAuthRoute(window.location.pathname)) return;
|
|
151
132
|
if (document.getElementById("strapi-oidc-sso-btn")) return;
|
|
@@ -155,71 +136,75 @@ const index = {
|
|
|
155
136
|
btn.id = "strapi-oidc-sso-btn";
|
|
156
137
|
btn.type = "button";
|
|
157
138
|
btn.className = submitButton.className;
|
|
158
|
-
btn.style.marginTop = "8px";
|
|
159
139
|
btn.onclick = () => {
|
|
160
140
|
window.location.href = "/strapi-plugin-oidc/oidc";
|
|
161
141
|
};
|
|
162
142
|
const innerSpan = submitButton.querySelector("span");
|
|
163
143
|
const span = document.createElement("span");
|
|
164
144
|
if (innerSpan) span.className = innerSpan.className;
|
|
165
|
-
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));
|
|
166
161
|
btn.appendChild(span);
|
|
167
162
|
submitButton.parentNode.insertBefore(btn, submitButton.nextSibling);
|
|
168
163
|
ssoButtonInjected = true;
|
|
169
164
|
};
|
|
170
|
-
const
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
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();
|
|
175
176
|
});
|
|
176
|
-
ssoObserver.observe(document.body, { childList: true, subtree: true });
|
|
177
177
|
};
|
|
178
|
-
const
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
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 });
|
|
183
188
|
};
|
|
184
|
-
|
|
185
|
-
patchHistory();
|
|
186
|
-
}
|
|
187
|
-
if (isAuthRoute(window.location.pathname)) {
|
|
188
|
-
document.documentElement.style.visibility = "hidden";
|
|
189
|
-
}
|
|
190
|
-
const checkEnforceOIDC = async () => {
|
|
189
|
+
const applySettings = async () => {
|
|
191
190
|
try {
|
|
192
191
|
const response = await window.fetch("/strapi-plugin-oidc/settings/public");
|
|
193
192
|
if (response.ok) {
|
|
194
193
|
const data = await response.json();
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
patchHistory();
|
|
199
|
-
} else {
|
|
200
|
-
localStorage.removeItem(ENFORCE_CACHE_KEY);
|
|
201
|
-
document.documentElement.style.visibility = "";
|
|
202
|
-
if (data.showSSOButton !== false) {
|
|
203
|
-
ssoButtonText = data.ssoButtonText || en["login.sso"];
|
|
204
|
-
startSSOButtonObserver();
|
|
205
|
-
} else {
|
|
206
|
-
stopSSOButtonObserver();
|
|
207
|
-
}
|
|
208
|
-
}
|
|
194
|
+
startLoginObserver(data.ssoButtonText || defaultButtonText, !!data.enforceOIDC);
|
|
195
|
+
} else {
|
|
196
|
+
startLoginObserver(defaultButtonText, false);
|
|
209
197
|
}
|
|
210
198
|
} catch (error) {
|
|
211
|
-
|
|
212
|
-
console.error("Failed to
|
|
199
|
+
startLoginObserver(defaultButtonText, false);
|
|
200
|
+
console.error("Failed to fetch OIDC settings:", error);
|
|
213
201
|
}
|
|
214
202
|
};
|
|
215
|
-
|
|
203
|
+
applySettings();
|
|
216
204
|
const originalFetch = window.fetch;
|
|
217
205
|
window.fetch = async (...args) => {
|
|
218
206
|
const url = typeof args[0] === "string" ? args[0] : args[0].url;
|
|
219
207
|
const isLogout = url && url.endsWith("/admin/logout") && args[1]?.method?.toUpperCase() === "POST";
|
|
220
|
-
if (isLogout) {
|
|
221
|
-
isLogoutInProgress = true;
|
|
222
|
-
}
|
|
223
208
|
const response = await originalFetch(...args);
|
|
224
209
|
if (isLogout && response.ok) {
|
|
225
210
|
window.localStorage.removeItem("jwtToken");
|
|
@@ -231,37 +216,27 @@ const index = {
|
|
|
231
216
|
window.location.href = "/strapi-plugin-oidc/logout";
|
|
232
217
|
return new Promise(() => {
|
|
233
218
|
});
|
|
234
|
-
} else if (isLogout) {
|
|
235
|
-
isLogoutInProgress = false;
|
|
236
219
|
}
|
|
237
220
|
return response;
|
|
238
221
|
};
|
|
239
222
|
},
|
|
240
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
|
+
);
|
|
241
230
|
const importedTrads = await Promise.all(
|
|
242
231
|
locales.map((locale) => {
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
value
|
|
248
|
-
])
|
|
249
|
-
);
|
|
250
|
-
return {
|
|
251
|
-
data: newData,
|
|
252
|
-
locale
|
|
253
|
-
};
|
|
254
|
-
}).catch(() => {
|
|
255
|
-
return {
|
|
256
|
-
data: {},
|
|
257
|
-
locale
|
|
258
|
-
};
|
|
259
|
-
});
|
|
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 }));
|
|
260
236
|
})
|
|
261
237
|
);
|
|
262
|
-
return
|
|
238
|
+
return importedTrads;
|
|
263
239
|
}
|
|
264
240
|
};
|
|
265
|
-
exports.
|
|
241
|
+
exports.getTrad = getTrad;
|
|
266
242
|
exports.index = index;
|
|
267
|
-
exports.pluginId = pluginId;
|