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
package/dist/server/index.js
CHANGED
|
@@ -36,52 +36,45 @@ function getRetentionDays() {
|
|
|
36
36
|
function isAuditLogEnabled() {
|
|
37
37
|
return getRetentionDays() !== 0;
|
|
38
38
|
}
|
|
39
|
+
const AUTH_ROUTES = ["login", "register", "register-admin", "forgot-password", "reset-password"];
|
|
39
40
|
async function bootstrap({ strapi: strapi2 }) {
|
|
40
41
|
const adminUrl = strapi2.config.get("admin.url", "/admin");
|
|
41
|
-
const authRoutes = [
|
|
42
|
-
`${adminUrl}/login`,
|
|
43
|
-
`${adminUrl}/register`,
|
|
44
|
-
`${adminUrl}/register-admin`,
|
|
45
|
-
`${adminUrl}/forgot-password`,
|
|
46
|
-
`${adminUrl}/reset-password`
|
|
47
|
-
];
|
|
48
42
|
const tokenRefreshPath = `${adminUrl}/token/refresh`;
|
|
49
43
|
const enforceOidcMiddleware = async (ctx, next) => {
|
|
50
|
-
const
|
|
51
|
-
const
|
|
52
|
-
|
|
44
|
+
const path = ctx.request.path;
|
|
45
|
+
const isPost = ctx.request.method === "POST";
|
|
46
|
+
const isAuthRoute = AUTH_ROUTES.some((r) => path.includes(r));
|
|
47
|
+
const isTokenRefresh = path === tokenRefreshPath;
|
|
48
|
+
if (isAuthRoute && isPost || isTokenRefresh) {
|
|
53
49
|
try {
|
|
54
50
|
const whitelistService2 = strapi2.plugin("strapi-plugin-oidc").service("whitelist");
|
|
55
51
|
const settings = await whitelistService2.getSettings();
|
|
56
52
|
const enforceOIDC = resolveEnforceOIDC(strapi2, settings?.enforceOIDC);
|
|
57
|
-
if (enforceOIDC) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
};
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
53
|
+
if (enforceOIDC && isAuthRoute && isPost) {
|
|
54
|
+
ctx.status = 403;
|
|
55
|
+
ctx.body = {
|
|
56
|
+
data: null,
|
|
57
|
+
error: {
|
|
58
|
+
status: 403,
|
|
59
|
+
name: "ForbiddenError",
|
|
60
|
+
message: "Local login is disabled. Please use OIDC.",
|
|
61
|
+
details: {}
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
if (enforceOIDC && isTokenRefresh && !ctx.cookies.get("oidc_authenticated")) {
|
|
67
|
+
ctx.status = 401;
|
|
68
|
+
ctx.body = {
|
|
69
|
+
data: null,
|
|
70
|
+
error: {
|
|
71
|
+
status: 401,
|
|
72
|
+
name: "UnauthorizedError",
|
|
73
|
+
message: "Session was not created via OIDC. Please log in again.",
|
|
74
|
+
details: {}
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
return;
|
|
85
78
|
}
|
|
86
79
|
} catch (err) {
|
|
87
80
|
strapi2.log.error("Error checking OIDC enforcement in middleware:", err);
|
|
@@ -95,18 +88,8 @@ async function bootstrap({ strapi: strapi2 }) {
|
|
|
95
88
|
strapi2.server.use(enforceOidcMiddleware);
|
|
96
89
|
}
|
|
97
90
|
const actions = [
|
|
98
|
-
{
|
|
99
|
-
|
|
100
|
-
displayName: "Read",
|
|
101
|
-
uid: "read",
|
|
102
|
-
pluginName: "strapi-plugin-oidc"
|
|
103
|
-
},
|
|
104
|
-
{
|
|
105
|
-
section: "plugins",
|
|
106
|
-
displayName: "Update",
|
|
107
|
-
uid: "update",
|
|
108
|
-
pluginName: "strapi-plugin-oidc"
|
|
109
|
-
}
|
|
91
|
+
{ section: "plugins", displayName: "Read", uid: "read", pluginName: "strapi-plugin-oidc" },
|
|
92
|
+
{ section: "plugins", displayName: "Update", uid: "update", pluginName: "strapi-plugin-oidc" }
|
|
110
93
|
];
|
|
111
94
|
await strapi2.admin.services.permission.actionProvider.registerMany(actions);
|
|
112
95
|
const enforceOIDCConfig = getEnforceOIDCConfig(strapi2);
|
|
@@ -125,17 +108,12 @@ async function bootstrap({ strapi: strapi2 }) {
|
|
|
125
108
|
}
|
|
126
109
|
}
|
|
127
110
|
try {
|
|
128
|
-
const oidcRoleCount = await strapi2.query("plugin::strapi-plugin-oidc.roles").count({
|
|
129
|
-
where: { oauth_type: "4" }
|
|
130
|
-
});
|
|
111
|
+
const oidcRoleCount = await strapi2.query("plugin::strapi-plugin-oidc.roles").count({ where: { oauth_type: "4" } });
|
|
131
112
|
if (oidcRoleCount === 0) {
|
|
132
113
|
const defaultRole = await strapi2.query("admin::role").findOne({ where: { code: "strapi-editor" } }) ?? await strapi2.query("admin::role").findOne({});
|
|
133
114
|
if (defaultRole) {
|
|
134
115
|
await strapi2.query("plugin::strapi-plugin-oidc.roles").create({
|
|
135
|
-
data: {
|
|
136
|
-
oauth_type: "4",
|
|
137
|
-
roles: [defaultRole.id.toString()]
|
|
138
|
-
}
|
|
116
|
+
data: { oauth_type: "4", roles: [String(defaultRole.id)] }
|
|
139
117
|
});
|
|
140
118
|
}
|
|
141
119
|
}
|
|
@@ -153,7 +131,6 @@ async function bootstrap({ strapi: strapi2 }) {
|
|
|
153
131
|
}
|
|
154
132
|
},
|
|
155
133
|
options: { rule: "0 0 * * *" }
|
|
156
|
-
// daily at midnight
|
|
157
134
|
}
|
|
158
135
|
});
|
|
159
136
|
}
|
|
@@ -255,24 +232,37 @@ const errorCodes = {
|
|
|
255
232
|
USER_CREATION_FAILED: "USER_CREATION_FAILED",
|
|
256
233
|
WHITELIST_CHECK_FAILED: "WHITELIST_CHECK_FAILED"
|
|
257
234
|
};
|
|
235
|
+
const ERROR_DETAIL_TEMPLATES = {
|
|
236
|
+
token_exchange_failed: "Token exchange failed with HTTP status {status}",
|
|
237
|
+
userinfo_fetch_failed: "UserInfo endpoint returned HTTP {status}",
|
|
238
|
+
role_update_failed: "Role update failed for user {userId}: {error}",
|
|
239
|
+
user_creation_failed: "User creation failed for {email}: {error}",
|
|
240
|
+
id_token_parse_failed: "ID token parse failed: {error}",
|
|
241
|
+
sign_in_unknown: "Unknown sign-in error: {error}",
|
|
242
|
+
invalid_email: "Invalid email address received from OIDC provider",
|
|
243
|
+
whitelist_not_present: "Email not present in whitelist",
|
|
244
|
+
session_manager_unsupported: "sessionManager is not supported. Please upgrade to Strapi v5.24.1 or later.",
|
|
245
|
+
missing_config: "Missing required config keys: {keys}"
|
|
246
|
+
};
|
|
247
|
+
function interpolate$1(template, params) {
|
|
248
|
+
if (!params) return template;
|
|
249
|
+
return template.replace(/\{(\w+)\}/g, (_, key) => String(params[key] ?? `{${key}}`));
|
|
250
|
+
}
|
|
258
251
|
function getErrorDetail(key, params) {
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
case "userinfo_fetch_failed":
|
|
263
|
-
return `UserInfo endpoint returned HTTP ${params?.status ?? "unknown"}`;
|
|
264
|
-
case "role_update_failed":
|
|
265
|
-
return `Role update failed for user ${params?.userId}: ${params?.error ?? "unknown"}`;
|
|
266
|
-
case "user_creation_failed":
|
|
267
|
-
return `User creation failed for ${params?.email}: ${params?.error ?? "unknown"}`;
|
|
268
|
-
case "id_token_parse_failed":
|
|
269
|
-
return `ID token parse failed: ${params?.error ?? "unknown"}`;
|
|
270
|
-
case "sign_in_unknown":
|
|
271
|
-
return `Unknown sign-in error: ${params?.error ?? "unknown"}`;
|
|
272
|
-
default:
|
|
273
|
-
return void 0;
|
|
274
|
-
}
|
|
252
|
+
const template = ERROR_DETAIL_TEMPLATES[key];
|
|
253
|
+
if (!template) return void 0;
|
|
254
|
+
return interpolate$1(template, params);
|
|
275
255
|
}
|
|
256
|
+
const errorMessages = {
|
|
257
|
+
TOKEN_EXCHANGE_FAILED: "Token exchange failed",
|
|
258
|
+
USERINFO_FETCH_FAILED: "Failed to fetch user info",
|
|
259
|
+
ID_TOKEN_PARSE_FAILED: "Failed to parse ID token",
|
|
260
|
+
NONCE_MISMATCH: "Nonce mismatch",
|
|
261
|
+
INVALID_EMAIL: "Invalid email address received from OIDC provider",
|
|
262
|
+
WHITELIST_NOT_PRESENT: "Not present in whitelist",
|
|
263
|
+
SESSION_MANAGER_UNSUPPORTED: "sessionManager is not supported. Please upgrade to Strapi v5.24.1 or later.",
|
|
264
|
+
MISSING_CONFIG: (keys) => `Missing required config keys: ${keys}`
|
|
265
|
+
};
|
|
276
266
|
const en = {
|
|
277
267
|
"global.plugins.strapi-plugin-oidc": "OIDC Plugin",
|
|
278
268
|
"page.title": "Configure OIDC default role(s) and access controls.",
|
|
@@ -303,8 +293,6 @@ const en = {
|
|
|
303
293
|
"whitelist.toggle.enabled": "Enabled",
|
|
304
294
|
"whitelist.toggle.disabled": "Disabled",
|
|
305
295
|
"whitelist.email.placeholder": "Email address",
|
|
306
|
-
"whitelist.roles.placeholder": "Select specific role(s)",
|
|
307
|
-
"whitelist.table.roles": "Role(s)",
|
|
308
296
|
"whitelist.table.empty": "No email addresses",
|
|
309
297
|
"whitelist.delete.label": "Delete",
|
|
310
298
|
"page.title.oidc": "OIDC",
|
|
@@ -328,7 +316,6 @@ const en = {
|
|
|
328
316
|
"unsaved.description": "You have unsaved changes that will be lost if you leave. Do you want to continue?",
|
|
329
317
|
"unsaved.confirm": "Leave",
|
|
330
318
|
"unsaved.cancel": "Stay",
|
|
331
|
-
"whitelist.table.roles.default": "(Default)",
|
|
332
319
|
"auditlog.title": "Audit Logs",
|
|
333
320
|
"auditlog.export": "Download",
|
|
334
321
|
"auditlog.table.timestamp": "Timestamp",
|
|
@@ -337,6 +324,7 @@ const en = {
|
|
|
337
324
|
"auditlog.table.ip": "IP",
|
|
338
325
|
"auditlog.table.details": "Details",
|
|
339
326
|
"auditlog.table.empty": "No audit log entries",
|
|
327
|
+
"auditlog.loading": "Loading…",
|
|
340
328
|
"auditlog.clear": "Clear Logs",
|
|
341
329
|
"auditlog.clear.title": "Clear All Logs",
|
|
342
330
|
"auditlog.clear.description": "This will permanently delete all {count, plural, one {# audit log entry} other {# audit log entries}}. This action cannot be undone.",
|
|
@@ -355,7 +343,9 @@ const en = {
|
|
|
355
343
|
"auditlog.action.whitelist_rejected": "The user's email address is not on the whitelist. Access was denied.",
|
|
356
344
|
"user.missing_code": "Authorisation code was not received from the OIDC provider.",
|
|
357
345
|
"user.invalid_state": "State parameter mismatch. Please restart the login flow.",
|
|
358
|
-
"user.signInError": "Authentication failed. Please try again."
|
|
346
|
+
"user.signInError": "Authentication failed. Please try again.",
|
|
347
|
+
"settings.section": "OIDC",
|
|
348
|
+
"settings.configuration": "Configuration"
|
|
359
349
|
};
|
|
360
350
|
const userFacingMessages = {
|
|
361
351
|
get missing_code() {
|
|
@@ -382,12 +372,11 @@ const REQUIRED_CONFIG_KEYS = [
|
|
|
382
372
|
];
|
|
383
373
|
function configValidation() {
|
|
384
374
|
const config2 = strapi.config.get("plugin::strapi-plugin-oidc");
|
|
385
|
-
|
|
375
|
+
const missing = REQUIRED_CONFIG_KEYS.filter((key) => !config2[key]);
|
|
376
|
+
if (missing.length === 0) {
|
|
386
377
|
return config2;
|
|
387
378
|
}
|
|
388
|
-
throw new Error(
|
|
389
|
-
`The following configuration keys are required: ${REQUIRED_CONFIG_KEYS.join(", ")}`
|
|
390
|
-
);
|
|
379
|
+
throw new Error(errorMessages.MISSING_CONFIG(missing.join(", ")));
|
|
391
380
|
}
|
|
392
381
|
async function oidcSignIn(ctx) {
|
|
393
382
|
const { OIDC_CLIENT_ID, OIDC_REDIRECT_URI, OIDC_SCOPE, OIDC_AUTHORIZATION_ENDPOINT } = configValidation();
|
|
@@ -428,7 +417,7 @@ async function exchangeTokenAndFetchUserInfo(config2, params, expectedNonce) {
|
|
|
428
417
|
}
|
|
429
418
|
});
|
|
430
419
|
if (!response.ok) {
|
|
431
|
-
throw new Error(
|
|
420
|
+
throw new Error(errorMessages.TOKEN_EXCHANGE_FAILED);
|
|
432
421
|
}
|
|
433
422
|
const tokenData = await response.json();
|
|
434
423
|
if (tokenData.id_token) {
|
|
@@ -436,18 +425,18 @@ async function exchangeTokenAndFetchUserInfo(config2, params, expectedNonce) {
|
|
|
436
425
|
const payloadB64 = tokenData.id_token.split(".")[1];
|
|
437
426
|
const idTokenPayload = JSON.parse(Buffer.from(payloadB64, "base64url").toString("utf8"));
|
|
438
427
|
if (idTokenPayload.nonce !== expectedNonce) {
|
|
439
|
-
throw new Error(
|
|
428
|
+
throw new Error(errorMessages.NONCE_MISMATCH);
|
|
440
429
|
}
|
|
441
430
|
} catch (e) {
|
|
442
431
|
if (e.message === "Nonce mismatch") throw e;
|
|
443
|
-
throw new Error(
|
|
432
|
+
throw new Error(errorMessages.ID_TOKEN_PARSE_FAILED);
|
|
444
433
|
}
|
|
445
434
|
}
|
|
446
435
|
const userResponse = await fetch(config2.OIDC_USERINFO_ENDPOINT, {
|
|
447
436
|
headers: { Authorization: `Bearer ${tokenData.access_token}` }
|
|
448
437
|
});
|
|
449
438
|
if (!userResponse.ok) {
|
|
450
|
-
throw new Error(
|
|
439
|
+
throw new Error(errorMessages.USERINFO_FETCH_FAILED);
|
|
451
440
|
}
|
|
452
441
|
const userInfo = await userResponse.json();
|
|
453
442
|
return { userInfo, accessToken: tokenData.access_token };
|
|
@@ -495,7 +484,11 @@ async function registerNewUser(oauthService2, email, userResponseData, config2,
|
|
|
495
484
|
return activateUser;
|
|
496
485
|
}
|
|
497
486
|
function rolesChanged(current, next) {
|
|
498
|
-
|
|
487
|
+
if (current.size !== next.size) return true;
|
|
488
|
+
for (const id of next) {
|
|
489
|
+
if (!current.has(id)) return true;
|
|
490
|
+
}
|
|
491
|
+
return false;
|
|
499
492
|
}
|
|
500
493
|
async function updateUserRoles(user, currentRoleIds, newRoleIds) {
|
|
501
494
|
try {
|
|
@@ -522,7 +515,7 @@ async function handleUserAuthentication(userService, oauthService2, roleService2
|
|
|
522
515
|
const rawEmail = String(userResponseData.email ?? "");
|
|
523
516
|
const email = rawEmail.toLowerCase();
|
|
524
517
|
if (!email || !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) {
|
|
525
|
-
throw new Error(
|
|
518
|
+
throw new Error(errorMessages.INVALID_EMAIL);
|
|
526
519
|
}
|
|
527
520
|
await whitelistService2.checkWhitelistForEmail(email);
|
|
528
521
|
const allRoles = await strapi.db.query("admin::role").findMany();
|
|
@@ -552,52 +545,39 @@ async function handleUserAuthentication(userService, oauthService2, roleService2
|
|
|
552
545
|
return { activateUser: user, jwtToken, userCreated, rolesUpdated, resolvedRoleNames };
|
|
553
546
|
}
|
|
554
547
|
function classifyOidcError(msg, userInfo) {
|
|
555
|
-
|
|
556
|
-
{
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
}
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
}
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
}
|
|
579
|
-
}
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
},
|
|
589
|
-
{
|
|
590
|
-
test: (m) => m === "User creation failed" || m.includes("createUser"),
|
|
591
|
-
result: {
|
|
592
|
-
action: "login_failure",
|
|
593
|
-
code: errorCodes.USER_CREATION_FAILED,
|
|
594
|
-
key: "user_creation_failed",
|
|
595
|
-
params: userInfo?.email ? { email: userInfo.email, error: msg } : void 0
|
|
596
|
-
}
|
|
597
|
-
}
|
|
598
|
-
];
|
|
599
|
-
for (const { test, result } of errorMap) {
|
|
600
|
-
if (test(msg)) return result;
|
|
548
|
+
if (msg.includes("whitelist")) {
|
|
549
|
+
return {
|
|
550
|
+
action: "whitelist_rejected",
|
|
551
|
+
code: errorCodes.WHITELIST_CHECK_FAILED,
|
|
552
|
+
key: "whitelist_rejected"
|
|
553
|
+
};
|
|
554
|
+
}
|
|
555
|
+
if (msg === "Nonce mismatch")
|
|
556
|
+
return { action: "nonce_mismatch", code: errorCodes.NONCE_MISMATCH };
|
|
557
|
+
if (msg === "Token exchange failed")
|
|
558
|
+
return { action: "token_exchange_failed", code: errorCodes.TOKEN_EXCHANGE_FAILED };
|
|
559
|
+
if (msg === "Failed to fetch user info") {
|
|
560
|
+
return {
|
|
561
|
+
action: "login_failure",
|
|
562
|
+
code: errorCodes.USERINFO_FETCH_FAILED,
|
|
563
|
+
key: "userinfo_fetch_failed"
|
|
564
|
+
};
|
|
565
|
+
}
|
|
566
|
+
if (msg === "Failed to parse ID token") {
|
|
567
|
+
return {
|
|
568
|
+
action: "login_failure",
|
|
569
|
+
code: errorCodes.ID_TOKEN_PARSE_FAILED,
|
|
570
|
+
key: "id_token_parse_failed",
|
|
571
|
+
params: { error: msg }
|
|
572
|
+
};
|
|
573
|
+
}
|
|
574
|
+
if (msg === "User creation failed" || msg.includes("createUser")) {
|
|
575
|
+
return {
|
|
576
|
+
action: "login_failure",
|
|
577
|
+
code: errorCodes.USER_CREATION_FAILED,
|
|
578
|
+
key: "user_creation_failed",
|
|
579
|
+
params: userInfo?.email ? { email: userInfo.email, error: msg } : void 0
|
|
580
|
+
};
|
|
601
581
|
}
|
|
602
582
|
return {
|
|
603
583
|
action: "login_failure",
|
|
@@ -830,13 +810,9 @@ async function register(ctx) {
|
|
|
830
810
|
const whitelistService2 = getWhitelistService();
|
|
831
811
|
let matchedExistingUsersCount = 0;
|
|
832
812
|
for (const singleEmail of emailList) {
|
|
833
|
-
const existingUser = await strapi.query("admin::user").findOne({
|
|
834
|
-
where: { email: singleEmail }
|
|
835
|
-
});
|
|
813
|
+
const existingUser = await strapi.query("admin::user").findOne({ where: { email: singleEmail } });
|
|
836
814
|
if (existingUser) matchedExistingUsersCount++;
|
|
837
|
-
const alreadyWhitelisted = await strapi.query("plugin::strapi-plugin-oidc.whitelists").findOne({
|
|
838
|
-
where: { email: singleEmail }
|
|
839
|
-
});
|
|
815
|
+
const alreadyWhitelisted = await strapi.query("plugin::strapi-plugin-oidc.whitelists").findOne({ where: { email: singleEmail } });
|
|
840
816
|
if (!alreadyWhitelisted) {
|
|
841
817
|
await whitelistService2.registerUser(singleEmail);
|
|
842
818
|
}
|
|
@@ -978,9 +954,7 @@ function rateLimitMiddleware(ctx, next) {
|
|
|
978
954
|
const key = getRateLimitKey(ctx);
|
|
979
955
|
const now = Date.now();
|
|
980
956
|
const windowStart = now - RATE_LIMIT_WINDOW;
|
|
981
|
-
const requestStamps = (rateLimitMap.get(key)
|
|
982
|
-
(timestamp) => timestamp > windowStart
|
|
983
|
-
);
|
|
957
|
+
const requestStamps = (rateLimitMap.get(key) ?? []).filter((ts) => ts > windowStart);
|
|
984
958
|
if (requestStamps.length >= MAX_REQUESTS) {
|
|
985
959
|
ctx.status = 429;
|
|
986
960
|
ctx.body = "Too Many Requests";
|
|
@@ -1287,9 +1261,7 @@ function oauthService({ strapi: strapi2 }) {
|
|
|
1287
1261
|
const userService = strapi2.service("admin::user");
|
|
1288
1262
|
if (/[A-Z]/.test(email)) {
|
|
1289
1263
|
const dbUser = await userService.findOneByEmail(email.toLocaleLowerCase());
|
|
1290
|
-
if (dbUser)
|
|
1291
|
-
return dbUser;
|
|
1292
|
-
}
|
|
1264
|
+
if (dbUser) return dbUser;
|
|
1293
1265
|
}
|
|
1294
1266
|
const createdUser = await userService.create({
|
|
1295
1267
|
firstname: firstname || "unset",
|
|
@@ -1305,7 +1277,6 @@ function oauthService({ strapi: strapi2 }) {
|
|
|
1305
1277
|
lastname: lastname || "user",
|
|
1306
1278
|
password: generator__default.default.generate({
|
|
1307
1279
|
length: 43,
|
|
1308
|
-
// 256 bits (https://en.wikipedia.org/wiki/Password_strength#Random_passwords)
|
|
1309
1280
|
numbers: true,
|
|
1310
1281
|
lowercase: true,
|
|
1311
1282
|
uppercase: true,
|
|
@@ -1316,14 +1287,10 @@ function oauthService({ strapi: strapi2 }) {
|
|
|
1316
1287
|
});
|
|
1317
1288
|
},
|
|
1318
1289
|
addGmailAlias(baseEmail, baseAlias) {
|
|
1319
|
-
if (!baseAlias)
|
|
1320
|
-
return baseEmail;
|
|
1321
|
-
}
|
|
1290
|
+
if (!baseAlias) return baseEmail;
|
|
1322
1291
|
const alias = baseAlias.replace(/\+/g, "");
|
|
1323
|
-
const
|
|
1324
|
-
|
|
1325
|
-
const domain = baseEmail.substring(beforePosition);
|
|
1326
|
-
return `${origin}+${alias}${domain}`;
|
|
1292
|
+
const atIndex = baseEmail.indexOf("@");
|
|
1293
|
+
return `${baseEmail.slice(0, atIndex)}+${alias}${baseEmail.slice(atIndex)}`;
|
|
1327
1294
|
},
|
|
1328
1295
|
localeFindByHeader(headers) {
|
|
1329
1296
|
return headers["accept-language"]?.includes("ja") ? "ja" : "en";
|
|
@@ -1404,9 +1371,7 @@ function oauthService({ strapi: strapi2 }) {
|
|
|
1404
1371
|
async generateToken(user, ctx) {
|
|
1405
1372
|
const sessionManager = strapi2.sessionManager;
|
|
1406
1373
|
if (!sessionManager) {
|
|
1407
|
-
throw new Error(
|
|
1408
|
-
"sessionManager is not supported. Please upgrade to Strapi v5.24.1 or later."
|
|
1409
|
-
);
|
|
1374
|
+
throw new Error(errorMessages.SESSION_MANAGER_UNSUPPORTED);
|
|
1410
1375
|
}
|
|
1411
1376
|
const userId = String(user.id);
|
|
1412
1377
|
const deviceId = node_crypto.randomUUID();
|
|
@@ -1496,15 +1461,11 @@ function roleService({ strapi: strapi2 }) {
|
|
|
1496
1461
|
}
|
|
1497
1462
|
};
|
|
1498
1463
|
}
|
|
1464
|
+
const SETTINGS_CACHE_TTL_MS = 5 * 60 * 1e3;
|
|
1499
1465
|
function whitelistService({ strapi: strapi2 }) {
|
|
1500
|
-
const getPluginStore = () => strapi2.store({
|
|
1501
|
-
environment: "",
|
|
1502
|
-
type: "plugin",
|
|
1503
|
-
name: "strapi-plugin-oidc"
|
|
1504
|
-
});
|
|
1505
|
-
const getWhitelistQuery = () => strapi2.query("plugin::strapi-plugin-oidc.whitelists");
|
|
1506
1466
|
let settingsCache = null;
|
|
1507
|
-
const
|
|
1467
|
+
const getPluginStore = () => strapi2.store({ environment: "", type: "plugin", name: "strapi-plugin-oidc" });
|
|
1468
|
+
const getWhitelistQuery = () => strapi2.query("plugin::strapi-plugin-oidc.whitelists");
|
|
1508
1469
|
return {
|
|
1509
1470
|
async getSettings() {
|
|
1510
1471
|
const now = Date.now();
|
|
@@ -1513,10 +1474,7 @@ function whitelistService({ strapi: strapi2 }) {
|
|
|
1513
1474
|
}
|
|
1514
1475
|
let settings = await getPluginStore().get({ key: "settings" });
|
|
1515
1476
|
if (!settings) {
|
|
1516
|
-
settings = {
|
|
1517
|
-
useWhitelist: true,
|
|
1518
|
-
enforceOIDC: false
|
|
1519
|
-
};
|
|
1477
|
+
settings = { useWhitelist: true, enforceOIDC: false };
|
|
1520
1478
|
await getPluginStore().set({ key: "settings", value: settings });
|
|
1521
1479
|
}
|
|
1522
1480
|
settingsCache = { value: settings, ts: now };
|
|
@@ -1530,26 +1488,18 @@ function whitelistService({ strapi: strapi2 }) {
|
|
|
1530
1488
|
return getWhitelistQuery().findMany();
|
|
1531
1489
|
},
|
|
1532
1490
|
async registerUser(email) {
|
|
1533
|
-
await getWhitelistQuery().create({
|
|
1534
|
-
data: { email }
|
|
1535
|
-
});
|
|
1491
|
+
await getWhitelistQuery().create({ data: { email } });
|
|
1536
1492
|
},
|
|
1537
1493
|
async removeUser(email) {
|
|
1538
|
-
await getWhitelistQuery().deleteMany({
|
|
1539
|
-
where: { email }
|
|
1540
|
-
});
|
|
1494
|
+
await getWhitelistQuery().deleteMany({ where: { email } });
|
|
1541
1495
|
},
|
|
1542
1496
|
async checkWhitelistForEmail(email) {
|
|
1543
1497
|
const settings = await this.getSettings();
|
|
1544
|
-
if (!settings.useWhitelist)
|
|
1545
|
-
return null;
|
|
1546
|
-
}
|
|
1498
|
+
if (!settings.useWhitelist) return null;
|
|
1547
1499
|
const result = await getWhitelistQuery().findOne({
|
|
1548
1500
|
where: { email }
|
|
1549
1501
|
});
|
|
1550
|
-
if (!result)
|
|
1551
|
-
throw new Error("Not present in whitelist");
|
|
1552
|
-
}
|
|
1502
|
+
if (!result) throw new Error(errorMessages.WHITELIST_NOT_PRESENT);
|
|
1553
1503
|
return result;
|
|
1554
1504
|
}
|
|
1555
1505
|
};
|
|
@@ -1610,9 +1560,7 @@ function auditLogService({ strapi: strapi2 }) {
|
|
|
1610
1560
|
},
|
|
1611
1561
|
async cleanup(retentionDays) {
|
|
1612
1562
|
const cutoff = new Date(Date.now() - retentionDays * 864e5);
|
|
1613
|
-
await strapi2.db.query("plugin::strapi-plugin-oidc.audit-log").deleteMany({
|
|
1614
|
-
where: { createdAt: { $lt: cutoff } }
|
|
1615
|
-
});
|
|
1563
|
+
await strapi2.db.query("plugin::strapi-plugin-oidc.audit-log").deleteMany({ where: { createdAt: { $lt: cutoff } } });
|
|
1616
1564
|
}
|
|
1617
1565
|
};
|
|
1618
1566
|
}
|