strapi-plugin-oidc 1.1.2 → 1.2.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.
@@ -0,0 +1,254 @@
1
+ "use strict";
2
+ const react = require("react");
3
+ const __variableDynamicImportRuntimeHelper = (glob, path, segs) => {
4
+ const v = glob[path];
5
+ if (v) {
6
+ return typeof v === "function" ? v() : Promise.resolve(v);
7
+ }
8
+ return new Promise((_, reject) => {
9
+ (typeof queueMicrotask === "function" ? queueMicrotask : setTimeout)(
10
+ reject.bind(
11
+ null,
12
+ new Error(
13
+ "Unknown variable dynamic import: " + path + (path.split("/").length !== segs ? ". Note that variables only represent file names one level deep." : "")
14
+ )
15
+ )
16
+ );
17
+ });
18
+ };
19
+ const name$1 = "strapi-plugin-oidc";
20
+ const strapi = { "displayName": "OIDC Plugin" };
21
+ const pluginPkg = {
22
+ name: name$1,
23
+ strapi
24
+ };
25
+ const pluginId = pluginPkg.name.replace(/^@strapi\/plugin-/i, "");
26
+ function getTranslation(id) {
27
+ return `${pluginId}.${id}`;
28
+ }
29
+ function Initializer({ setPlugin }) {
30
+ const ref = react.useRef();
31
+ ref.current = setPlugin;
32
+ react.useEffect(() => {
33
+ if (ref.current) {
34
+ ref.current(pluginId);
35
+ }
36
+ }, []);
37
+ return null;
38
+ }
39
+ const en = {
40
+ "global.plugins.strapi-plugin-oidc": "OIDC Plugin",
41
+ "page.title": "Configure OIDC default role(s) and access controls.",
42
+ "roles.notes": "Select the default role(s) assigned to new users upon their first login. This setting does not affect existing users.",
43
+ "page.save": "Save Changes",
44
+ "page.save.success": "Updated settings",
45
+ "page.save.error": "Update failed.",
46
+ "page.add": "Add",
47
+ "page.cancel": "Cancel",
48
+ "page.ok": "OK",
49
+ "roles.title": "Default Role(s)",
50
+ "roles.placeholder": "Select default role(s)",
51
+ "whitelist.title": "Whitelist",
52
+ "whitelist.error.unique": "Already registered email address.",
53
+ "whitelist.enabled": "Whitelist is currently enabled.",
54
+ "whitelist.disabled": "Whitelist is currently disabled.",
55
+ "whitelist.description": "Restrict OIDC authentication to specific email addresses and optionally assign them custom role(s).",
56
+ "whitelist.user_exists": "User already exists, matching existing role(s)",
57
+ "whitelist.users_exists": "Users already exist, matching existing role(s)",
58
+ "whitelist.table.no": "No.",
59
+ "whitelist.table.email": "Email",
60
+ "whitelist.table.created": "Created At",
61
+ "whitelist.delete.title": "Confirmation",
62
+ "whitelist.delete.description": "Are you sure you want to delete:",
63
+ "whitelist.delete.note": "This will not delete the user account in Strapi.",
64
+ "whitelist.toggle.enabled": "Enabled",
65
+ "whitelist.toggle.disabled": "Disabled",
66
+ "whitelist.email.placeholder": "Email address",
67
+ "whitelist.roles.placeholder": "Select specific role(s)",
68
+ "whitelist.table.roles": "Role(s)",
69
+ "whitelist.table.roles.default": "Default",
70
+ "whitelist.table.empty": "No email addresses",
71
+ "whitelist.delete.label": "Delete",
72
+ "page.title.oidc": "OIDC",
73
+ "enforce.title": "Enforce OIDC Login",
74
+ "enforce.toggle.enabled": "Enabled",
75
+ "enforce.toggle.disabled": "Disabled",
76
+ "enforce.warning": "Make sure OIDC is setup correctly before saving changes, you won't be able to login normally.",
77
+ "login.sso": "Login via SSO"
78
+ };
79
+ const en$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
80
+ __proto__: null,
81
+ default: en
82
+ }, Symbol.toStringTag, { value: "Module" }));
83
+ const name = pluginPkg.strapi.displayName;
84
+ const index = {
85
+ register(app) {
86
+ app.addSettingsLink(
87
+ {
88
+ id: "oidc",
89
+ intlLabel: {
90
+ id: `${pluginId}.settings.section`,
91
+ defaultMessage: "OIDC"
92
+ }
93
+ },
94
+ {
95
+ id: "configuration",
96
+ to: `/settings/${pluginId}`,
97
+ intlLabel: {
98
+ id: `${pluginId}.settings.configuration`,
99
+ defaultMessage: "Configuration"
100
+ },
101
+ Component: async () => {
102
+ return await Promise.resolve().then(() => require("./index-CQSLiYnE.js"));
103
+ },
104
+ permissions: [{ action: "plugin::strapi-plugin-oidc.read", subject: null }]
105
+ }
106
+ );
107
+ app.registerPlugin({
108
+ id: pluginId,
109
+ initializer: Initializer,
110
+ name
111
+ });
112
+ },
113
+ bootstrap() {
114
+ let isLogoutInProgress = false;
115
+ let historyPatched = false;
116
+ const ENFORCE_CACHE_KEY = "strapi_oidc_enforced";
117
+ 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
+ window.location.href = "/strapi-plugin-oidc/oidc";
131
+ return;
132
+ }
133
+ }
134
+ return originalMethod.apply(window.history, args);
135
+ };
136
+ };
137
+ window.history.pushState = interceptHistory(window.history.pushState);
138
+ window.history.replaceState = interceptHistory(window.history.replaceState);
139
+ if (isAuthRoute(window.location.pathname)) {
140
+ window.location.replace("/strapi-plugin-oidc/oidc");
141
+ }
142
+ };
143
+ let ssoButtonInjected = false;
144
+ let ssoObserver = null;
145
+ const injectSSOButton = () => {
146
+ if (ssoButtonInjected) return;
147
+ if (!isAuthRoute(window.location.pathname)) return;
148
+ if (document.getElementById("strapi-oidc-sso-btn")) return;
149
+ const submitButton = document.querySelector('form button[type="submit"]');
150
+ if (!submitButton?.parentNode) return;
151
+ const btn = document.createElement("button");
152
+ btn.id = "strapi-oidc-sso-btn";
153
+ btn.type = "button";
154
+ btn.className = submitButton.className;
155
+ btn.style.marginTop = "8px";
156
+ btn.onclick = () => {
157
+ window.location.href = "/strapi-plugin-oidc/oidc";
158
+ };
159
+ const innerSpan = submitButton.querySelector("span");
160
+ const span = document.createElement("span");
161
+ if (innerSpan) span.className = innerSpan.className;
162
+ span.textContent = en["login.sso"];
163
+ btn.appendChild(span);
164
+ submitButton.parentNode.insertBefore(btn, submitButton.nextSibling);
165
+ ssoButtonInjected = true;
166
+ };
167
+ const startSSOButtonObserver = () => {
168
+ if (ssoObserver) return;
169
+ injectSSOButton();
170
+ ssoObserver = new MutationObserver(() => {
171
+ if (isAuthRoute(window.location.pathname)) injectSSOButton();
172
+ });
173
+ ssoObserver.observe(document.body, { childList: true, subtree: true });
174
+ };
175
+ const stopSSOButtonObserver = () => {
176
+ ssoObserver?.disconnect();
177
+ ssoObserver = null;
178
+ document.getElementById("strapi-oidc-sso-btn")?.remove();
179
+ ssoButtonInjected = false;
180
+ };
181
+ if (localStorage.getItem(ENFORCE_CACHE_KEY) === "1") {
182
+ patchHistory();
183
+ }
184
+ const checkEnforceOIDC = async () => {
185
+ try {
186
+ const response = await window.fetch("/strapi-plugin-oidc/settings/public");
187
+ if (response.ok) {
188
+ const data = await response.json();
189
+ if (data.enforceOIDC) {
190
+ localStorage.setItem(ENFORCE_CACHE_KEY, "1");
191
+ stopSSOButtonObserver();
192
+ patchHistory();
193
+ } else {
194
+ localStorage.removeItem(ENFORCE_CACHE_KEY);
195
+ startSSOButtonObserver();
196
+ }
197
+ }
198
+ } catch (error) {
199
+ console.error("Failed to check OIDC enforcement setting:", error);
200
+ }
201
+ };
202
+ checkEnforceOIDC();
203
+ const originalFetch = window.fetch;
204
+ window.fetch = async (...args) => {
205
+ const url = typeof args[0] === "string" ? args[0] : args[0].url;
206
+ const isLogout = url && url.endsWith("/admin/logout") && args[1]?.method?.toUpperCase() === "POST";
207
+ if (isLogout) {
208
+ isLogoutInProgress = true;
209
+ }
210
+ const response = await originalFetch(...args);
211
+ if (isLogout && response.ok) {
212
+ window.localStorage.removeItem("jwtToken");
213
+ window.localStorage.removeItem("isLoggedIn");
214
+ window.sessionStorage.removeItem("jwtToken");
215
+ window.sessionStorage.removeItem("isLoggedIn");
216
+ document.cookie = "jwtToken=;expires=Thu, 01 Jan 1970 00:00:00 GMT;path=/";
217
+ document.cookie = "jwtToken=;expires=Thu, 01 Jan 1970 00:00:00 GMT;path=/admin";
218
+ window.location.href = "/strapi-plugin-oidc/logout";
219
+ return new Promise(() => {
220
+ });
221
+ } else if (isLogout) {
222
+ isLogoutInProgress = false;
223
+ }
224
+ return response;
225
+ };
226
+ },
227
+ async registerTrads({ locales }) {
228
+ const importedTrads = await Promise.all(
229
+ locales.map((locale) => {
230
+ return __variableDynamicImportRuntimeHelper(/* @__PURE__ */ Object.assign({ "./translations/en.json": () => Promise.resolve().then(() => en$1) }), `./translations/${locale}.json`, 3).then(({ default: data }) => {
231
+ const newData = Object.fromEntries(
232
+ Object.entries(data).map(([key, value]) => [
233
+ key.startsWith("global.") ? key : getTranslation(key),
234
+ value
235
+ ])
236
+ );
237
+ return {
238
+ data: newData,
239
+ locale
240
+ };
241
+ }).catch(() => {
242
+ return {
243
+ data: {},
244
+ locale
245
+ };
246
+ });
247
+ })
248
+ );
249
+ return Promise.resolve(importedTrads);
250
+ }
251
+ };
252
+ exports.en = en;
253
+ exports.index = index;
254
+ exports.pluginId = pluginId;
@@ -7,8 +7,7 @@ const react = require("react");
7
7
  const designSystem = require("@strapi/design-system");
8
8
  const icons = require("@strapi/icons");
9
9
  const reactIntl = require("react-intl");
10
- const index = require("./index-Csm9fJS0.js");
11
- const en = require("./en-8UlbiAHW.js");
10
+ const index = require("./index-BJPMfkrf.js");
12
11
  const styled = require("styled-components");
13
12
  const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
14
13
  const styled__default = /* @__PURE__ */ _interopDefault(styled);
@@ -16,7 +15,7 @@ function getTrad(id) {
16
15
  const pluginIdWithId = `${index.pluginId}.${id}`;
17
16
  return {
18
17
  id: pluginIdWithId,
19
- defaultMessage: en.default[id] || pluginIdWithId
18
+ defaultMessage: index.en[id] || pluginIdWithId
20
19
  };
21
20
  }
22
21
  function Role({ oidcRoles, roles, onChangeRole }) {
@@ -510,24 +509,61 @@ function HomePage$1() {
510
509
  }
511
510
  )
512
511
  ] }),
513
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { background: "neutral0", hasRadius: true, shadow: "filterShadow", padding: 6, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "stretch", gap: 4, children: [
514
- /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { justifyContent: "space-between", alignItems: "center", children: [
515
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "epsilon", tag: "h4", children: formatMessage(getTrad("enforce.title")) }),
516
- /* @__PURE__ */ jsxRuntime.jsx(
517
- CustomSwitch,
518
- {
519
- checked: state.enforceOIDC,
520
- onChange: actions.onToggleEnforce,
521
- disabled: state.useWhitelist && state.users.length === 0,
522
- label: state.enforceOIDC ? formatMessage(getTrad("enforce.toggle.enabled")) : formatMessage(getTrad("enforce.toggle.disabled"))
523
- }
524
- )
525
- ] }),
526
- state.enforceOIDC && state.enforceOIDC !== state.initialEnforceOIDC && /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { background: "danger100", padding: 3, hasRadius: true, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 3, alignItems: "center", children: [
527
- /* @__PURE__ */ jsxRuntime.jsx(icons.WarningCircle, { fill: "danger600" }),
528
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { textColor: "danger600", children: formatMessage(getTrad("enforce.warning")) })
529
- ] }) })
530
- ] }) }),
512
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { background: "neutral0", hasRadius: true, shadow: "filterShadow", padding: 6, children: [
513
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { paddingBottom: 6, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "beta", tag: "h2", children: formatMessage(getTrad("login.settings.title")) }) }),
514
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "stretch", gap: 4, children: [
515
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "stretch", gap: 2, children: [
516
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { alignItems: "center", gap: 3, wrap: "wrap", children: [
517
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "omega", style: { minWidth: "280px" }, children: formatMessage(getTrad("enforce.title")) }),
518
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { minWidth: "160px", children: /* @__PURE__ */ jsxRuntime.jsx(
519
+ CustomSwitch,
520
+ {
521
+ checked: state.enforceOIDC,
522
+ onChange: actions.onToggleEnforce,
523
+ disabled: state.useWhitelist && state.users.length === 0,
524
+ label: state.enforceOIDC ? formatMessage(getTrad("enforce.toggle.enabled")) : formatMessage(getTrad("enforce.toggle.disabled"))
525
+ }
526
+ ) })
527
+ ] }),
528
+ state.enforceOIDC && state.enforceOIDC !== state.initialEnforceOIDC && /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { background: "danger100", padding: 3, hasRadius: true, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 3, alignItems: "center", children: [
529
+ /* @__PURE__ */ jsxRuntime.jsx(icons.WarningCircle, { fill: "danger600" }),
530
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { textColor: "danger600", children: formatMessage(getTrad("enforce.warning")) })
531
+ ] }) })
532
+ ] }),
533
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { alignItems: "center", gap: 3, wrap: "wrap", children: [
534
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "omega", style: { minWidth: "280px" }, children: formatMessage(getTrad("login.sso.show")) }),
535
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { minWidth: "160px", children: /* @__PURE__ */ jsxRuntime.jsx(
536
+ CustomSwitch,
537
+ {
538
+ checked: state.showSSOButton,
539
+ onChange: actions.onToggleShowSSOButton,
540
+ label: state.showSSOButton ? formatMessage(getTrad("enforce.toggle.enabled")) : formatMessage(getTrad("enforce.toggle.disabled"))
541
+ }
542
+ ) })
543
+ ] }),
544
+ state.showSSOButton && /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { alignItems: "center", gap: 3, wrap: "wrap", children: [
545
+ /* @__PURE__ */ jsxRuntime.jsx(
546
+ designSystem.Typography,
547
+ {
548
+ variant: "omega",
549
+ tag: "label",
550
+ htmlFor: "sso-button-text",
551
+ style: { minWidth: "280px" },
552
+ children: formatMessage(getTrad("login.sso.button.text.label"))
553
+ }
554
+ ),
555
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { style: { flex: 1, minWidth: "160px" }, children: /* @__PURE__ */ jsxRuntime.jsx(
556
+ designSystem.TextInput,
557
+ {
558
+ id: "sso-button-text",
559
+ "aria-label": formatMessage(getTrad("login.sso.button.text.label")),
560
+ value: state.ssoButtonText,
561
+ onChange: actions.onChangeSSOButtonText
562
+ }
563
+ ) })
564
+ ] })
565
+ ] })
566
+ ] }),
531
567
  /* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { justifyContent: "flex-end", children: /* @__PURE__ */ jsxRuntime.jsx(
532
568
  designSystem.Button,
533
569
  {
@@ -0,0 +1,255 @@
1
+ import { useRef, useEffect } from "react";
2
+ const __variableDynamicImportRuntimeHelper = (glob, path, segs) => {
3
+ const v = glob[path];
4
+ if (v) {
5
+ return typeof v === "function" ? v() : Promise.resolve(v);
6
+ }
7
+ return new Promise((_, reject) => {
8
+ (typeof queueMicrotask === "function" ? queueMicrotask : setTimeout)(
9
+ reject.bind(
10
+ null,
11
+ new Error(
12
+ "Unknown variable dynamic import: " + path + (path.split("/").length !== segs ? ". Note that variables only represent file names one level deep." : "")
13
+ )
14
+ )
15
+ );
16
+ });
17
+ };
18
+ const name$1 = "strapi-plugin-oidc";
19
+ const strapi = { "displayName": "OIDC Plugin" };
20
+ const pluginPkg = {
21
+ name: name$1,
22
+ strapi
23
+ };
24
+ const pluginId = pluginPkg.name.replace(/^@strapi\/plugin-/i, "");
25
+ function getTranslation(id) {
26
+ return `${pluginId}.${id}`;
27
+ }
28
+ function Initializer({ setPlugin }) {
29
+ const ref = useRef();
30
+ ref.current = setPlugin;
31
+ useEffect(() => {
32
+ if (ref.current) {
33
+ ref.current(pluginId);
34
+ }
35
+ }, []);
36
+ return null;
37
+ }
38
+ const en = {
39
+ "global.plugins.strapi-plugin-oidc": "OIDC Plugin",
40
+ "page.title": "Configure OIDC default role(s) and access controls.",
41
+ "roles.notes": "Select the default role(s) assigned to new users upon their first login. This setting does not affect existing users.",
42
+ "page.save": "Save Changes",
43
+ "page.save.success": "Updated settings",
44
+ "page.save.error": "Update failed.",
45
+ "page.add": "Add",
46
+ "page.cancel": "Cancel",
47
+ "page.ok": "OK",
48
+ "roles.title": "Default Role(s)",
49
+ "roles.placeholder": "Select default role(s)",
50
+ "whitelist.title": "Whitelist",
51
+ "whitelist.error.unique": "Already registered email address.",
52
+ "whitelist.enabled": "Whitelist is currently enabled.",
53
+ "whitelist.disabled": "Whitelist is currently disabled.",
54
+ "whitelist.description": "Restrict OIDC authentication to specific email addresses and optionally assign them custom role(s).",
55
+ "whitelist.user_exists": "User already exists, matching existing role(s)",
56
+ "whitelist.users_exists": "Users already exist, matching existing role(s)",
57
+ "whitelist.table.no": "No.",
58
+ "whitelist.table.email": "Email",
59
+ "whitelist.table.created": "Created At",
60
+ "whitelist.delete.title": "Confirmation",
61
+ "whitelist.delete.description": "Are you sure you want to delete:",
62
+ "whitelist.delete.note": "This will not delete the user account in Strapi.",
63
+ "whitelist.toggle.enabled": "Enabled",
64
+ "whitelist.toggle.disabled": "Disabled",
65
+ "whitelist.email.placeholder": "Email address",
66
+ "whitelist.roles.placeholder": "Select specific role(s)",
67
+ "whitelist.table.roles": "Role(s)",
68
+ "whitelist.table.roles.default": "Default",
69
+ "whitelist.table.empty": "No email addresses",
70
+ "whitelist.delete.label": "Delete",
71
+ "page.title.oidc": "OIDC",
72
+ "enforce.title": "Enforce OIDC Login",
73
+ "enforce.toggle.enabled": "Enabled",
74
+ "enforce.toggle.disabled": "Disabled",
75
+ "enforce.warning": "Make sure OIDC is setup correctly before saving changes, you won't be able to login normally.",
76
+ "login.sso": "Login via SSO"
77
+ };
78
+ const en$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
79
+ __proto__: null,
80
+ default: en
81
+ }, Symbol.toStringTag, { value: "Module" }));
82
+ const name = pluginPkg.strapi.displayName;
83
+ const index = {
84
+ register(app) {
85
+ app.addSettingsLink(
86
+ {
87
+ id: "oidc",
88
+ intlLabel: {
89
+ id: `${pluginId}.settings.section`,
90
+ defaultMessage: "OIDC"
91
+ }
92
+ },
93
+ {
94
+ id: "configuration",
95
+ to: `/settings/${pluginId}`,
96
+ intlLabel: {
97
+ id: `${pluginId}.settings.configuration`,
98
+ defaultMessage: "Configuration"
99
+ },
100
+ Component: async () => {
101
+ return await import("./index-Dua1LXcu.mjs");
102
+ },
103
+ permissions: [{ action: "plugin::strapi-plugin-oidc.read", subject: null }]
104
+ }
105
+ );
106
+ app.registerPlugin({
107
+ id: pluginId,
108
+ initializer: Initializer,
109
+ name
110
+ });
111
+ },
112
+ bootstrap() {
113
+ let isLogoutInProgress = false;
114
+ let historyPatched = false;
115
+ const ENFORCE_CACHE_KEY = "strapi_oidc_enforced";
116
+ const isAuthRoute = (path) => /\/auth\/(login|register|forgot-password|reset-password)/.test(path);
117
+ const patchHistory = () => {
118
+ if (historyPatched) return;
119
+ historyPatched = true;
120
+ const interceptHistory = (originalMethod) => {
121
+ return function(...args) {
122
+ const url = args[2];
123
+ if (url && typeof url === "string") {
124
+ const urlWithoutQuery = url.split("?")[0].split("#")[0];
125
+ if (isAuthRoute(urlWithoutQuery)) {
126
+ if (isLogoutInProgress) {
127
+ return;
128
+ }
129
+ window.location.href = "/strapi-plugin-oidc/oidc";
130
+ return;
131
+ }
132
+ }
133
+ return originalMethod.apply(window.history, args);
134
+ };
135
+ };
136
+ window.history.pushState = interceptHistory(window.history.pushState);
137
+ window.history.replaceState = interceptHistory(window.history.replaceState);
138
+ if (isAuthRoute(window.location.pathname)) {
139
+ window.location.replace("/strapi-plugin-oidc/oidc");
140
+ }
141
+ };
142
+ let ssoButtonInjected = false;
143
+ let ssoObserver = null;
144
+ const injectSSOButton = () => {
145
+ if (ssoButtonInjected) return;
146
+ if (!isAuthRoute(window.location.pathname)) return;
147
+ if (document.getElementById("strapi-oidc-sso-btn")) return;
148
+ const submitButton = document.querySelector('form button[type="submit"]');
149
+ if (!submitButton?.parentNode) return;
150
+ const btn = document.createElement("button");
151
+ btn.id = "strapi-oidc-sso-btn";
152
+ btn.type = "button";
153
+ btn.className = submitButton.className;
154
+ btn.style.marginTop = "8px";
155
+ btn.onclick = () => {
156
+ window.location.href = "/strapi-plugin-oidc/oidc";
157
+ };
158
+ const innerSpan = submitButton.querySelector("span");
159
+ const span = document.createElement("span");
160
+ if (innerSpan) span.className = innerSpan.className;
161
+ span.textContent = en["login.sso"];
162
+ btn.appendChild(span);
163
+ submitButton.parentNode.insertBefore(btn, submitButton.nextSibling);
164
+ ssoButtonInjected = true;
165
+ };
166
+ const startSSOButtonObserver = () => {
167
+ if (ssoObserver) return;
168
+ injectSSOButton();
169
+ ssoObserver = new MutationObserver(() => {
170
+ if (isAuthRoute(window.location.pathname)) injectSSOButton();
171
+ });
172
+ ssoObserver.observe(document.body, { childList: true, subtree: true });
173
+ };
174
+ const stopSSOButtonObserver = () => {
175
+ ssoObserver?.disconnect();
176
+ ssoObserver = null;
177
+ document.getElementById("strapi-oidc-sso-btn")?.remove();
178
+ ssoButtonInjected = false;
179
+ };
180
+ if (localStorage.getItem(ENFORCE_CACHE_KEY) === "1") {
181
+ patchHistory();
182
+ }
183
+ const checkEnforceOIDC = async () => {
184
+ try {
185
+ const response = await window.fetch("/strapi-plugin-oidc/settings/public");
186
+ if (response.ok) {
187
+ const data = await response.json();
188
+ if (data.enforceOIDC) {
189
+ localStorage.setItem(ENFORCE_CACHE_KEY, "1");
190
+ stopSSOButtonObserver();
191
+ patchHistory();
192
+ } else {
193
+ localStorage.removeItem(ENFORCE_CACHE_KEY);
194
+ startSSOButtonObserver();
195
+ }
196
+ }
197
+ } catch (error) {
198
+ console.error("Failed to check OIDC enforcement setting:", error);
199
+ }
200
+ };
201
+ checkEnforceOIDC();
202
+ const originalFetch = window.fetch;
203
+ window.fetch = async (...args) => {
204
+ const url = typeof args[0] === "string" ? args[0] : args[0].url;
205
+ const isLogout = url && url.endsWith("/admin/logout") && args[1]?.method?.toUpperCase() === "POST";
206
+ if (isLogout) {
207
+ isLogoutInProgress = true;
208
+ }
209
+ const response = await originalFetch(...args);
210
+ if (isLogout && response.ok) {
211
+ window.localStorage.removeItem("jwtToken");
212
+ window.localStorage.removeItem("isLoggedIn");
213
+ window.sessionStorage.removeItem("jwtToken");
214
+ window.sessionStorage.removeItem("isLoggedIn");
215
+ document.cookie = "jwtToken=;expires=Thu, 01 Jan 1970 00:00:00 GMT;path=/";
216
+ document.cookie = "jwtToken=;expires=Thu, 01 Jan 1970 00:00:00 GMT;path=/admin";
217
+ window.location.href = "/strapi-plugin-oidc/logout";
218
+ return new Promise(() => {
219
+ });
220
+ } else if (isLogout) {
221
+ isLogoutInProgress = false;
222
+ }
223
+ return response;
224
+ };
225
+ },
226
+ async registerTrads({ locales }) {
227
+ const importedTrads = await Promise.all(
228
+ locales.map((locale) => {
229
+ return __variableDynamicImportRuntimeHelper(/* @__PURE__ */ Object.assign({ "./translations/en.json": () => Promise.resolve().then(() => en$1) }), `./translations/${locale}.json`, 3).then(({ default: data }) => {
230
+ const newData = Object.fromEntries(
231
+ Object.entries(data).map(([key, value]) => [
232
+ key.startsWith("global.") ? key : getTranslation(key),
233
+ value
234
+ ])
235
+ );
236
+ return {
237
+ data: newData,
238
+ locale
239
+ };
240
+ }).catch(() => {
241
+ return {
242
+ data: {},
243
+ locale
244
+ };
245
+ });
246
+ })
247
+ );
248
+ return Promise.resolve(importedTrads);
249
+ }
250
+ };
251
+ export {
252
+ en as e,
253
+ index as i,
254
+ pluginId as p
255
+ };