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
|
@@ -49,11 +49,15 @@ const en = {
|
|
|
49
49
|
"roles.placeholder": "Select default role(s)",
|
|
50
50
|
"whitelist.title": "Whitelist",
|
|
51
51
|
"whitelist.error.unique": "Already registered email address.",
|
|
52
|
-
"whitelist.enabled": "Whitelist is currently enabled.",
|
|
53
|
-
"whitelist.disabled": "Whitelist is currently disabled.",
|
|
54
52
|
"whitelist.description": "Restrict OIDC authentication to specific email addresses and optionally assign them custom role(s).",
|
|
55
53
|
"whitelist.user_exists": "User already exists, matching existing role(s)",
|
|
56
54
|
"whitelist.users_exists": "Users already exist, matching existing role(s)",
|
|
55
|
+
"alert.title.success": "Success",
|
|
56
|
+
"alert.title.error": "Error",
|
|
57
|
+
"alert.title.info": "Info",
|
|
58
|
+
"pagination.previous": "Go to previous page",
|
|
59
|
+
"pagination.page": "Go to page {page}",
|
|
60
|
+
"pagination.next": "Go to next page",
|
|
57
61
|
"whitelist.table.no": "No.",
|
|
58
62
|
"whitelist.table.email": "Email",
|
|
59
63
|
"whitelist.table.created": "Created At",
|
|
@@ -65,7 +69,6 @@ const en = {
|
|
|
65
69
|
"whitelist.email.placeholder": "Email address",
|
|
66
70
|
"whitelist.roles.placeholder": "Select specific role(s)",
|
|
67
71
|
"whitelist.table.roles": "Role(s)",
|
|
68
|
-
"whitelist.table.roles.default": "Default",
|
|
69
72
|
"whitelist.table.empty": "No email addresses",
|
|
70
73
|
"whitelist.delete.label": "Delete",
|
|
71
74
|
"page.title.oidc": "OIDC",
|
|
@@ -73,15 +76,20 @@ const en = {
|
|
|
73
76
|
"enforce.toggle.enabled": "Enabled",
|
|
74
77
|
"enforce.toggle.disabled": "Disabled",
|
|
75
78
|
"enforce.warning": "Make sure OIDC is setup correctly before saving changes, you won't be able to login normally.",
|
|
79
|
+
"enforce.config.info": "Enforcement is controlled by the OIDC_ENFORCE config variable and cannot be changed here.",
|
|
76
80
|
"login.settings.title": "Login Settings",
|
|
77
|
-
"login.sso": "Login via SSO"
|
|
78
|
-
"login.sso.show": "Add button for OIDC on login screen",
|
|
79
|
-
"login.sso.button.text.label": "Login button text"
|
|
81
|
+
"login.sso": "Login via SSO"
|
|
80
82
|
};
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
83
|
+
function getTrad(id) {
|
|
84
|
+
const pluginIdWithId = `${pluginId}.${id}`;
|
|
85
|
+
return {
|
|
86
|
+
id: pluginIdWithId,
|
|
87
|
+
defaultMessage: en[id] || pluginIdWithId
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
function t(id) {
|
|
91
|
+
return en[id];
|
|
92
|
+
}
|
|
85
93
|
const name = pluginPkg.strapi.displayName;
|
|
86
94
|
const index = {
|
|
87
95
|
register(app) {
|
|
@@ -101,7 +109,7 @@ const index = {
|
|
|
101
109
|
defaultMessage: "Configuration"
|
|
102
110
|
},
|
|
103
111
|
Component: async () => {
|
|
104
|
-
return await import("./index-
|
|
112
|
+
return await import("./index-CFmg9Kxl.mjs");
|
|
105
113
|
},
|
|
106
114
|
permissions: [{ action: "plugin::strapi-plugin-oidc.read", subject: null }]
|
|
107
115
|
}
|
|
@@ -113,50 +121,11 @@ const index = {
|
|
|
113
121
|
});
|
|
114
122
|
},
|
|
115
123
|
bootstrap() {
|
|
116
|
-
|
|
117
|
-
let historyPatched = false;
|
|
118
|
-
const ENFORCE_CACHE_KEY = "strapi_oidc_enforced";
|
|
124
|
+
const defaultButtonText = t("login.sso");
|
|
119
125
|
const isAuthRoute = (path) => /\/auth\/(login|register|forgot-password|reset-password)/.test(path);
|
|
120
|
-
const patchHistory = () => {
|
|
121
|
-
if (historyPatched) return;
|
|
122
|
-
historyPatched = true;
|
|
123
|
-
const interceptHistory = (originalMethod) => {
|
|
124
|
-
return function(...args) {
|
|
125
|
-
const url = args[2];
|
|
126
|
-
if (url && typeof url === "string") {
|
|
127
|
-
const urlWithoutQuery = url.split("?")[0].split("#")[0];
|
|
128
|
-
if (isAuthRoute(urlWithoutQuery)) {
|
|
129
|
-
if (isLogoutInProgress) {
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
|
-
if (sessionStorage.getItem("oidc_logout")) {
|
|
133
|
-
sessionStorage.removeItem("oidc_logout");
|
|
134
|
-
return originalMethod.apply(window.history, args);
|
|
135
|
-
}
|
|
136
|
-
document.documentElement.style.visibility = "hidden";
|
|
137
|
-
window.location.href = "/strapi-plugin-oidc/oidc";
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
return originalMethod.apply(window.history, args);
|
|
142
|
-
};
|
|
143
|
-
};
|
|
144
|
-
window.history.pushState = interceptHistory(window.history.pushState);
|
|
145
|
-
window.history.replaceState = interceptHistory(window.history.replaceState);
|
|
146
|
-
if (isAuthRoute(window.location.pathname)) {
|
|
147
|
-
if (sessionStorage.getItem("oidc_logout")) {
|
|
148
|
-
sessionStorage.removeItem("oidc_logout");
|
|
149
|
-
document.documentElement.style.visibility = "";
|
|
150
|
-
} else {
|
|
151
|
-
document.documentElement.style.visibility = "hidden";
|
|
152
|
-
window.location.replace("/strapi-plugin-oidc/oidc");
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
};
|
|
156
126
|
let ssoButtonInjected = false;
|
|
157
|
-
let
|
|
158
|
-
|
|
159
|
-
const injectSSOButton = () => {
|
|
127
|
+
let loginObserver = null;
|
|
128
|
+
const injectSSOButton = (buttonText) => {
|
|
160
129
|
if (ssoButtonInjected) return;
|
|
161
130
|
if (!isAuthRoute(window.location.pathname)) return;
|
|
162
131
|
if (document.getElementById("strapi-oidc-sso-btn")) return;
|
|
@@ -166,74 +135,75 @@ const index = {
|
|
|
166
135
|
btn.id = "strapi-oidc-sso-btn";
|
|
167
136
|
btn.type = "button";
|
|
168
137
|
btn.className = submitButton.className;
|
|
169
|
-
btn.style.marginTop = "8px";
|
|
170
138
|
btn.onclick = () => {
|
|
171
139
|
window.location.href = "/strapi-plugin-oidc/oidc";
|
|
172
140
|
};
|
|
173
141
|
const innerSpan = submitButton.querySelector("span");
|
|
174
142
|
const span = document.createElement("span");
|
|
175
143
|
if (innerSpan) span.className = innerSpan.className;
|
|
176
|
-
span.
|
|
144
|
+
span.style.display = "inline-flex";
|
|
145
|
+
span.style.alignItems = "center";
|
|
146
|
+
span.style.gap = "8px";
|
|
147
|
+
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
148
|
+
svg.setAttribute("width", "16");
|
|
149
|
+
svg.setAttribute("height", "16");
|
|
150
|
+
svg.setAttribute("viewBox", "0 0 24 24");
|
|
151
|
+
svg.setAttribute("fill", "none");
|
|
152
|
+
svg.setAttribute("stroke", "currentColor");
|
|
153
|
+
svg.setAttribute("stroke-width", "2");
|
|
154
|
+
svg.setAttribute("stroke-linecap", "round");
|
|
155
|
+
svg.setAttribute("stroke-linejoin", "round");
|
|
156
|
+
svg.setAttribute("aria-hidden", "true");
|
|
157
|
+
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"/>';
|
|
158
|
+
span.appendChild(svg);
|
|
159
|
+
span.appendChild(document.createTextNode(buttonText));
|
|
177
160
|
btn.appendChild(span);
|
|
178
161
|
submitButton.parentNode.insertBefore(btn, submitButton.nextSibling);
|
|
179
162
|
ssoButtonInjected = true;
|
|
180
163
|
};
|
|
181
|
-
const
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
164
|
+
const removeEnforcedElements = () => {
|
|
165
|
+
[
|
|
166
|
+
'form > div > div:has(input[name="email"])',
|
|
167
|
+
'form > div > div:has(input[name="password"])',
|
|
168
|
+
'form > div > div:has(button[role="checkbox"])',
|
|
169
|
+
'form > div > button[type="submit"]:not(#strapi-oidc-sso-btn)'
|
|
170
|
+
].forEach((selector) => {
|
|
171
|
+
document.querySelectorAll(selector).forEach((el) => el.remove());
|
|
172
|
+
});
|
|
173
|
+
document.querySelectorAll('a[href*="forgot-password"]').forEach((el) => {
|
|
174
|
+
(el.closest("div")?.parentElement ?? el).remove();
|
|
186
175
|
});
|
|
187
|
-
ssoObserver.observe(document.body, { childList: true, subtree: true });
|
|
188
176
|
};
|
|
189
|
-
const
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
177
|
+
const startLoginObserver = (buttonText, enforced) => {
|
|
178
|
+
if (loginObserver) return;
|
|
179
|
+
const tick = () => {
|
|
180
|
+
if (!isAuthRoute(window.location.pathname)) return;
|
|
181
|
+
injectSSOButton(buttonText);
|
|
182
|
+
if (enforced) removeEnforcedElements();
|
|
183
|
+
};
|
|
184
|
+
tick();
|
|
185
|
+
loginObserver = new MutationObserver(tick);
|
|
186
|
+
loginObserver.observe(document.body, { childList: true, subtree: true });
|
|
194
187
|
};
|
|
195
|
-
|
|
196
|
-
document.documentElement.style.visibility = "hidden";
|
|
197
|
-
}
|
|
198
|
-
if (localStorage.getItem(ENFORCE_CACHE_KEY) === "1") {
|
|
199
|
-
patchHistory();
|
|
200
|
-
}
|
|
201
|
-
if (isAuthRoute(window.location.pathname)) {
|
|
202
|
-
document.documentElement.style.visibility = "hidden";
|
|
203
|
-
}
|
|
204
|
-
const checkEnforceOIDC = async () => {
|
|
188
|
+
const applySettings = async () => {
|
|
205
189
|
try {
|
|
206
190
|
const response = await window.fetch("/strapi-plugin-oidc/settings/public");
|
|
207
191
|
if (response.ok) {
|
|
208
192
|
const data = await response.json();
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
patchHistory();
|
|
213
|
-
} else {
|
|
214
|
-
localStorage.removeItem(ENFORCE_CACHE_KEY);
|
|
215
|
-
document.documentElement.style.visibility = "";
|
|
216
|
-
if (data.showSSOButton !== false) {
|
|
217
|
-
ssoButtonText = data.ssoButtonText || en["login.sso"];
|
|
218
|
-
startSSOButtonObserver();
|
|
219
|
-
} else {
|
|
220
|
-
stopSSOButtonObserver();
|
|
221
|
-
}
|
|
222
|
-
}
|
|
193
|
+
startLoginObserver(data.ssoButtonText || defaultButtonText, !!data.enforceOIDC);
|
|
194
|
+
} else {
|
|
195
|
+
startLoginObserver(defaultButtonText, false);
|
|
223
196
|
}
|
|
224
197
|
} catch (error) {
|
|
225
|
-
|
|
226
|
-
console.error("Failed to
|
|
198
|
+
startLoginObserver(defaultButtonText, false);
|
|
199
|
+
console.error("Failed to fetch OIDC settings:", error);
|
|
227
200
|
}
|
|
228
201
|
};
|
|
229
|
-
|
|
202
|
+
applySettings();
|
|
230
203
|
const originalFetch = window.fetch;
|
|
231
204
|
window.fetch = async (...args) => {
|
|
232
205
|
const url = typeof args[0] === "string" ? args[0] : args[0].url;
|
|
233
206
|
const isLogout = url && url.endsWith("/admin/logout") && args[1]?.method?.toUpperCase() === "POST";
|
|
234
|
-
if (isLogout) {
|
|
235
|
-
isLogoutInProgress = true;
|
|
236
|
-
}
|
|
237
207
|
const response = await originalFetch(...args);
|
|
238
208
|
if (isLogout && response.ok) {
|
|
239
209
|
window.localStorage.removeItem("jwtToken");
|
|
@@ -242,43 +212,32 @@ const index = {
|
|
|
242
212
|
window.sessionStorage.removeItem("isLoggedIn");
|
|
243
213
|
document.cookie = "jwtToken=;expires=Thu, 01 Jan 1970 00:00:00 GMT;path=/";
|
|
244
214
|
document.cookie = "jwtToken=;expires=Thu, 01 Jan 1970 00:00:00 GMT;path=/admin";
|
|
245
|
-
sessionStorage.setItem("oidc_logout", "1");
|
|
246
215
|
window.location.href = "/strapi-plugin-oidc/logout";
|
|
247
216
|
return new Promise(() => {
|
|
248
217
|
});
|
|
249
|
-
} else if (isLogout) {
|
|
250
|
-
isLogoutInProgress = false;
|
|
251
218
|
}
|
|
252
219
|
return response;
|
|
253
220
|
};
|
|
254
221
|
},
|
|
255
222
|
async registerTrads({ locales }) {
|
|
223
|
+
const transformKeys = (data) => Object.fromEntries(
|
|
224
|
+
Object.entries(data).map(([key, value]) => [
|
|
225
|
+
key.startsWith("global.") ? key : getTranslation(key),
|
|
226
|
+
value
|
|
227
|
+
])
|
|
228
|
+
);
|
|
256
229
|
const importedTrads = await Promise.all(
|
|
257
230
|
locales.map((locale) => {
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
value
|
|
263
|
-
])
|
|
264
|
-
);
|
|
265
|
-
return {
|
|
266
|
-
data: newData,
|
|
267
|
-
locale
|
|
268
|
-
};
|
|
269
|
-
}).catch(() => {
|
|
270
|
-
return {
|
|
271
|
-
data: {},
|
|
272
|
-
locale
|
|
273
|
-
};
|
|
274
|
-
});
|
|
231
|
+
if (locale === "en") {
|
|
232
|
+
return Promise.resolve({ data: transformKeys(en), locale });
|
|
233
|
+
}
|
|
234
|
+
return __variableDynamicImportRuntimeHelper(/* @__PURE__ */ Object.assign({}), `./translations/locales/${locale}.json`, 4).then(({ default: data }) => ({ data: transformKeys(data), locale })).catch(() => ({ data: {}, locale }));
|
|
275
235
|
})
|
|
276
236
|
);
|
|
277
|
-
return
|
|
237
|
+
return importedTrads;
|
|
278
238
|
}
|
|
279
239
|
};
|
|
280
240
|
export {
|
|
281
|
-
|
|
282
|
-
index as i
|
|
283
|
-
pluginId as p
|
|
241
|
+
getTrad as g,
|
|
242
|
+
index as i
|
|
284
243
|
};
|
package/dist/admin/index.js
CHANGED
package/dist/admin/index.mjs
CHANGED
package/dist/server/index.js
CHANGED
|
@@ -10,22 +10,19 @@ const strapiUtils__default = /* @__PURE__ */ _interopDefault(strapiUtils);
|
|
|
10
10
|
const generator__default = /* @__PURE__ */ _interopDefault(generator);
|
|
11
11
|
function register$1() {
|
|
12
12
|
}
|
|
13
|
-
function
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
maxAge: 0,
|
|
22
|
-
expires: /* @__PURE__ */ new Date(0)
|
|
23
|
-
};
|
|
13
|
+
function getEnforceOIDCConfig(strapi2) {
|
|
14
|
+
const config2 = strapi2.config.get("plugin::strapi-plugin-oidc");
|
|
15
|
+
const val = config2.OIDC_ENFORCE;
|
|
16
|
+
if (val === null || val === void 0) return null;
|
|
17
|
+
if (typeof val === "boolean") return val;
|
|
18
|
+
if (val === "true") return true;
|
|
19
|
+
if (val === "false") return false;
|
|
20
|
+
return null;
|
|
24
21
|
}
|
|
25
|
-
function
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
22
|
+
function resolveEnforceOIDC(strapi2, dbValue) {
|
|
23
|
+
const configValue = getEnforceOIDCConfig(strapi2);
|
|
24
|
+
if (configValue !== null) return configValue;
|
|
25
|
+
return dbValue ?? false;
|
|
29
26
|
}
|
|
30
27
|
async function bootstrap({ strapi: strapi2 }) {
|
|
31
28
|
const enforceOidcMiddleware = async (ctx, next) => {
|
|
@@ -38,13 +35,12 @@ async function bootstrap({ strapi: strapi2 }) {
|
|
|
38
35
|
];
|
|
39
36
|
const isPostAuth = authRoutes.includes(ctx.request.path) && ctx.request.method === "POST";
|
|
40
37
|
const isTokenRefresh = ctx.request.path === `${adminUrl}/token/refresh` && ctx.request.method === "POST";
|
|
41
|
-
|
|
42
|
-
const isGetAdminHtml = ctx.request.method === "GET" && ctx.request.path.startsWith(adminUrl) && isHtmlRequest;
|
|
43
|
-
if (isPostAuth || isTokenRefresh || isGetAdminHtml) {
|
|
38
|
+
if (isPostAuth || isTokenRefresh) {
|
|
44
39
|
try {
|
|
45
40
|
const whitelistService2 = strapi2.plugin("strapi-plugin-oidc").service("whitelist");
|
|
46
41
|
const settings = await whitelistService2.getSettings();
|
|
47
|
-
|
|
42
|
+
const enforceOIDC = resolveEnforceOIDC(strapi2, settings?.enforceOIDC);
|
|
43
|
+
if (enforceOIDC) {
|
|
48
44
|
if (isPostAuth) {
|
|
49
45
|
ctx.status = 403;
|
|
50
46
|
ctx.body = {
|
|
@@ -72,18 +68,6 @@ async function bootstrap({ strapi: strapi2 }) {
|
|
|
72
68
|
};
|
|
73
69
|
return;
|
|
74
70
|
}
|
|
75
|
-
if (isGetAdminHtml) {
|
|
76
|
-
const hasRefreshCookie = !!ctx.cookies.get("strapi_admin_refresh");
|
|
77
|
-
if (hasRefreshCookie && !hasOidcSession) {
|
|
78
|
-
clearAuthCookies(strapi2, ctx);
|
|
79
|
-
ctx.redirect("/strapi-plugin-oidc/oidc");
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
if (!hasRefreshCookie) {
|
|
83
|
-
ctx.redirect("/strapi-plugin-oidc/oidc");
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
71
|
}
|
|
88
72
|
} catch (err) {
|
|
89
73
|
strapi2.log.error("Error checking OIDC enforcement in middleware:", err);
|
|
@@ -158,8 +142,6 @@ function destroy() {
|
|
|
158
142
|
const config = {
|
|
159
143
|
default: {
|
|
160
144
|
REMEMBER_ME: false,
|
|
161
|
-
REMEMBER_ME_DAYS: 30,
|
|
162
|
-
// 30 days
|
|
163
145
|
OIDC_REDIRECT_URI: "http://localhost:1337/strapi-plugin-oidc/oidc/callback",
|
|
164
146
|
OIDC_CLIENT_ID: "",
|
|
165
147
|
OIDC_CLIENT_SECRET: "",
|
|
@@ -171,7 +153,10 @@ const config = {
|
|
|
171
153
|
OIDC_GRANT_TYPE: "authorization_code",
|
|
172
154
|
OIDC_FAMILY_NAME_FIELD: "family_name",
|
|
173
155
|
OIDC_GIVEN_NAME_FIELD: "given_name",
|
|
174
|
-
OIDC_LOGOUT_URL: ""
|
|
156
|
+
OIDC_LOGOUT_URL: "",
|
|
157
|
+
OIDC_SSO_BUTTON_TEXT: "Login via SSO",
|
|
158
|
+
OIDC_ENFORCE: null
|
|
159
|
+
// null = use DB setting; true/false = override DB (useful for lockout recovery)
|
|
175
160
|
},
|
|
176
161
|
validator() {
|
|
177
162
|
}
|
|
@@ -206,6 +191,23 @@ const contentTypes = {
|
|
|
206
191
|
roles,
|
|
207
192
|
whitelists
|
|
208
193
|
};
|
|
194
|
+
function getExpiredCookieOptions(strapi2, ctx) {
|
|
195
|
+
const isProduction = strapi2.config.get("environment") === "production";
|
|
196
|
+
return {
|
|
197
|
+
httpOnly: true,
|
|
198
|
+
secure: isProduction && ctx.request.secure,
|
|
199
|
+
path: strapi2.config.get("admin.auth.cookie.path", "/admin"),
|
|
200
|
+
domain: strapi2.config.get("admin.auth.cookie.domain") || strapi2.config.get("admin.auth.domain"),
|
|
201
|
+
sameSite: strapi2.config.get("admin.auth.cookie.sameSite", "lax"),
|
|
202
|
+
maxAge: 0,
|
|
203
|
+
expires: /* @__PURE__ */ new Date(0)
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
function clearAuthCookies(strapi2, ctx) {
|
|
207
|
+
const options2 = getExpiredCookieOptions(strapi2, ctx);
|
|
208
|
+
ctx.cookies.set("strapi_admin_refresh", "", options2);
|
|
209
|
+
ctx.cookies.set("oidc_authenticated", "", { ...options2, path: "/" });
|
|
210
|
+
}
|
|
209
211
|
function configValidation() {
|
|
210
212
|
const config2 = strapi.config.get("plugin::strapi-plugin-oidc");
|
|
211
213
|
const requiredKeys = [
|
|
@@ -345,6 +347,8 @@ async function oidcSignInCallback(ctx) {
|
|
|
345
347
|
}
|
|
346
348
|
const oidcState = ctx.cookies.get("oidc_state");
|
|
347
349
|
const codeVerifier = ctx.cookies.get("oidc_code_verifier");
|
|
350
|
+
ctx.cookies.set("oidc_state", null);
|
|
351
|
+
ctx.cookies.set("oidc_code_verifier", null);
|
|
348
352
|
if (!ctx.query.state || ctx.query.state !== oidcState) {
|
|
349
353
|
return ctx.send(oauthService2.renderSignUpError("Invalid state"));
|
|
350
354
|
}
|
|
@@ -425,14 +429,13 @@ async function info(ctx) {
|
|
|
425
429
|
const whitelistUsers = await whitelistService2.getUsers();
|
|
426
430
|
ctx.body = {
|
|
427
431
|
useWhitelist: settings.useWhitelist,
|
|
428
|
-
enforceOIDC: settings.enforceOIDC
|
|
429
|
-
|
|
430
|
-
ssoButtonText: settings.ssoButtonText || "Login via SSO",
|
|
432
|
+
enforceOIDC: resolveEnforceOIDC(strapi, settings.enforceOIDC),
|
|
433
|
+
enforceOIDCConfig: getEnforceOIDCConfig(strapi),
|
|
431
434
|
whitelistUsers
|
|
432
435
|
};
|
|
433
436
|
}
|
|
434
437
|
async function updateSettings(ctx) {
|
|
435
|
-
let { useWhitelist, enforceOIDC
|
|
438
|
+
let { useWhitelist, enforceOIDC } = ctx.request.body;
|
|
436
439
|
const whitelistService2 = strapi.plugin("strapi-plugin-oidc").service("whitelist");
|
|
437
440
|
if (useWhitelist && enforceOIDC) {
|
|
438
441
|
const users = await whitelistService2.getUsers();
|
|
@@ -440,16 +443,16 @@ async function updateSettings(ctx) {
|
|
|
440
443
|
enforceOIDC = false;
|
|
441
444
|
}
|
|
442
445
|
}
|
|
443
|
-
await whitelistService2.setSettings({ useWhitelist, enforceOIDC
|
|
444
|
-
ctx.body = { useWhitelist, enforceOIDC
|
|
446
|
+
await whitelistService2.setSettings({ useWhitelist, enforceOIDC });
|
|
447
|
+
ctx.body = { useWhitelist, enforceOIDC };
|
|
445
448
|
}
|
|
446
449
|
async function publicSettings(ctx) {
|
|
447
450
|
const whitelistService2 = strapi.plugin("strapi-plugin-oidc").service("whitelist");
|
|
448
451
|
const settings = await whitelistService2.getSettings();
|
|
452
|
+
const config2 = strapi.config.get("plugin::strapi-plugin-oidc");
|
|
449
453
|
ctx.body = {
|
|
450
|
-
enforceOIDC: settings.enforceOIDC
|
|
451
|
-
|
|
452
|
-
ssoButtonText: settings.ssoButtonText || "Login via SSO"
|
|
454
|
+
enforceOIDC: resolveEnforceOIDC(strapi, settings.enforceOIDC),
|
|
455
|
+
ssoButtonText: config2.OIDC_SSO_BUTTON_TEXT
|
|
453
456
|
};
|
|
454
457
|
}
|
|
455
458
|
async function register(ctx) {
|
|
@@ -934,13 +937,11 @@ function oauthService({ strapi: strapi2 }) {
|
|
|
934
937
|
const config2 = strapi2.config.get("plugin::strapi-plugin-oidc");
|
|
935
938
|
const REMEMBER_ME = config2["REMEMBER_ME"];
|
|
936
939
|
const rememberMe = !!REMEMBER_ME;
|
|
937
|
-
const { token: refreshToken } = await sessionManager(
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
}
|
|
943
|
-
);
|
|
940
|
+
const { token: refreshToken, absoluteExpiresAt } = await sessionManager(
|
|
941
|
+
"admin"
|
|
942
|
+
).generateRefreshToken(userId, deviceId, {
|
|
943
|
+
type: rememberMe ? "refresh" : "session"
|
|
944
|
+
});
|
|
944
945
|
const isProduction = strapi2.config.get("environment") === "production";
|
|
945
946
|
const domain = strapi2.config.get("admin.auth.cookie.domain") || strapi2.config.get("admin.auth.domain");
|
|
946
947
|
const path = strapi2.config.get("admin.auth.cookie.path", "/admin");
|
|
@@ -954,10 +955,16 @@ function oauthService({ strapi: strapi2 }) {
|
|
|
954
955
|
sameSite
|
|
955
956
|
};
|
|
956
957
|
if (rememberMe) {
|
|
957
|
-
const
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
958
|
+
const idleLifespanSec = strapi2.config.get(
|
|
959
|
+
"admin.auth.sessions.idleRefreshTokenLifespan",
|
|
960
|
+
1209600
|
|
961
|
+
// 14 days — Strapi default
|
|
962
|
+
);
|
|
963
|
+
const idleMs = idleLifespanSec * 1e3;
|
|
964
|
+
const absoluteMs = new Date(absoluteExpiresAt).getTime() - Date.now();
|
|
965
|
+
const ms = Math.min(idleMs, absoluteMs);
|
|
966
|
+
cookieOptions.maxAge = ms;
|
|
967
|
+
cookieOptions.expires = new Date(Date.now() + ms);
|
|
961
968
|
}
|
|
962
969
|
ctx.cookies.set("strapi_admin_refresh", refreshToken, cookieOptions);
|
|
963
970
|
ctx.cookies.set("oidc_authenticated", "1", { ...cookieOptions, path: "/" });
|
|
@@ -1033,9 +1040,7 @@ function whitelistService({ strapi: strapi2 }) {
|
|
|
1033
1040
|
if (!settings) {
|
|
1034
1041
|
settings = {
|
|
1035
1042
|
useWhitelist: true,
|
|
1036
|
-
enforceOIDC: false
|
|
1037
|
-
showSSOButton: true,
|
|
1038
|
-
ssoButtonText: "Login via SSO"
|
|
1043
|
+
enforceOIDC: false
|
|
1039
1044
|
};
|
|
1040
1045
|
await getPluginStore().set({ key: "settings", value: settings });
|
|
1041
1046
|
}
|