strapi-plugin-oidc 1.8.1 → 1.8.2

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.
@@ -12,6 +12,58 @@ const strapiUtils__default = /* @__PURE__ */ _interopDefault(strapiUtils);
12
12
  const generator__default = /* @__PURE__ */ _interopDefault(generator);
13
13
  function register$1() {
14
14
  }
15
+ const errorCodes = {
16
+ TOKEN_EXCHANGE_FAILED: "TOKEN_EXCHANGE_FAILED",
17
+ USERINFO_FETCH_FAILED: "USERINFO_FETCH_FAILED",
18
+ ID_TOKEN_PARSE_FAILED: "ID_TOKEN_PARSE_FAILED",
19
+ NONCE_MISMATCH: "NONCE_MISMATCH",
20
+ ROLE_UPDATE_FAILED: "ROLE_UPDATE_FAILED",
21
+ USER_CREATION_FAILED: "USER_CREATION_FAILED",
22
+ WHITELIST_CHECK_FAILED: "WHITELIST_CHECK_FAILED",
23
+ EMAIL_NOT_VERIFIED: "EMAIL_NOT_VERIFIED",
24
+ ID_TOKEN_INVALID: "ID_TOKEN_INVALID"
25
+ };
26
+ const ERROR_DETAIL_TEMPLATES = {
27
+ token_exchange_failed: "Token exchange failed with HTTP status {status}",
28
+ userinfo_fetch_failed: "UserInfo endpoint returned HTTP {status}",
29
+ role_update_failed: "Role update failed for user {userId}: {error}",
30
+ user_creation_failed: "User creation failed for {email}: {error}",
31
+ id_token_parse_failed: "ID token parse failed: {error}",
32
+ sign_in_unknown: "Unknown sign-in error: {error}",
33
+ invalid_email: "Invalid email address received from OIDC provider",
34
+ email_not_verified: "Email address has not been verified by the OIDC provider",
35
+ id_token_invalid: "ID token verification failed: {error}",
36
+ whitelist_not_present: "Email not present in whitelist",
37
+ session_manager_unsupported: "sessionManager is not supported. Please upgrade to Strapi v5.24.1 or later."
38
+ };
39
+ function interpolate$1(template, params) {
40
+ if (!params) return template;
41
+ return template.replace(/\{(\w+)\}/g, (_, key) => String(params[key] ?? `{${key}}`));
42
+ }
43
+ function getErrorDetail(key, params) {
44
+ const template = ERROR_DETAIL_TEMPLATES[key];
45
+ if (!template) return void 0;
46
+ return interpolate$1(template, params);
47
+ }
48
+ const errorMessages = {
49
+ TOKEN_EXCHANGE_FAILED: "Token exchange failed",
50
+ USERINFO_FETCH_FAILED: "Failed to fetch user info",
51
+ ID_TOKEN_PARSE_FAILED: "Failed to parse ID token",
52
+ NONCE_MISMATCH: "Nonce mismatch",
53
+ INVALID_EMAIL: "Invalid email address received from OIDC provider",
54
+ EMAIL_NOT_VERIFIED: "Email address has not been verified by the OIDC provider",
55
+ ID_TOKEN_INVALID: "ID token verification failed",
56
+ WHITELIST_NOT_PRESENT: "Not present in whitelist",
57
+ SESSION_MANAGER_UNSUPPORTED: "sessionManager is not supported. Please upgrade to Strapi v5.24.1 or later.",
58
+ JWKS_URI_NOT_CONFIGURED: "[OIDC] OIDC_JWKS_URI is not configured — ID token signature verification is disabled. Set OIDC_JWKS_URI and OIDC_ISSUER from your provider's discovery document.",
59
+ ENFORCE_MIDDLEWARE_ERROR: "Error checking OIDC enforcement in middleware:",
60
+ ENFORCE_SYNC_ERROR: "[strapi-plugin-oidc] Failed to sync OIDC_ENFORCE to database:",
61
+ DEFAULT_ROLE_INIT_ERROR: "Could not initialize default OIDC role:",
62
+ AUDIT_LOG_CLEANUP_ERROR: "[strapi-plugin-oidc] Audit log cleanup failed:",
63
+ AUDIT_LOG_EXPORT_ERROR: "NDJSON export stream failed",
64
+ DISCOVERY_FETCH_ERROR: (url, reason) => `[strapi-plugin-oidc] Failed to fetch OIDC discovery document from ${url}: ${reason}`,
65
+ MISSING_CONFIG: (keys) => `Missing required config keys: ${keys}`
66
+ };
15
67
  function getEnforceOIDCConfig(strapi2) {
16
68
  const config2 = strapi2.config.get("plugin::strapi-plugin-oidc");
17
69
  const val = config2.OIDC_ENFORCE;
@@ -63,10 +115,9 @@ async function applyDiscovery(strapi2) {
63
115
  if (!res.ok) throw new Error(`HTTP ${res.status}`);
64
116
  doc = await res.json();
65
117
  } catch (e) {
66
- strapi2.log.error(
67
- `[strapi-plugin-oidc] Failed to fetch OIDC discovery document from ${discoveryUrl}: ${e instanceof Error ? e.message : String(e)}`
118
+ throw new Error(
119
+ errorMessages.DISCOVERY_FETCH_ERROR(discoveryUrl, e instanceof Error ? e.message : String(e))
68
120
  );
69
- return;
70
121
  }
71
122
  const updates = {};
72
123
  for (const [docField, configKey] of FIELD_MAP) {
@@ -121,7 +172,7 @@ async function bootstrap({ strapi: strapi2 }) {
121
172
  return;
122
173
  }
123
174
  } catch (err) {
124
- strapi2.log.error("Error checking OIDC enforcement in middleware:", err);
175
+ strapi2.log.error(errorMessages.ENFORCE_MIDDLEWARE_ERROR, err);
125
176
  }
126
177
  }
127
178
  await next();
@@ -158,7 +209,7 @@ async function bootstrap({ strapi: strapi2 }) {
158
209
  );
159
210
  }
160
211
  } catch (err) {
161
- strapi2.log.error("[strapi-plugin-oidc] Failed to sync OIDC_ENFORCE to database:", err);
212
+ strapi2.log.error(errorMessages.ENFORCE_SYNC_ERROR, err);
162
213
  }
163
214
  }
164
215
  try {
@@ -172,7 +223,7 @@ async function bootstrap({ strapi: strapi2 }) {
172
223
  }
173
224
  }
174
225
  } catch (err) {
175
- strapi2.log.warn("Could not initialize default OIDC role:", err.message);
226
+ strapi2.log.warn(errorMessages.DEFAULT_ROLE_INIT_ERROR, err.message);
176
227
  }
177
228
  strapi2.cron.add({
178
229
  "strapi-plugin-oidc-audit-log-cleanup": {
@@ -181,7 +232,7 @@ async function bootstrap({ strapi: strapi2 }) {
181
232
  const retentionDays = getRetentionDays();
182
233
  await getAuditLogService().cleanup(retentionDays);
183
234
  } catch (err) {
184
- strapi2.log.warn("[strapi-plugin-oidc] Audit log cleanup failed:", err.message);
235
+ strapi2.log.warn(errorMessages.AUDIT_LOG_CLEANUP_ERROR, err.message);
185
236
  }
186
237
  },
187
238
  options: { rule: "0 0 * * *" }
@@ -297,52 +348,6 @@ const EMAIL_REGEX = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
297
348
  function isValidEmail(email) {
298
349
  return EMAIL_REGEX.test(email);
299
350
  }
300
- const errorCodes = {
301
- TOKEN_EXCHANGE_FAILED: "TOKEN_EXCHANGE_FAILED",
302
- USERINFO_FETCH_FAILED: "USERINFO_FETCH_FAILED",
303
- ID_TOKEN_PARSE_FAILED: "ID_TOKEN_PARSE_FAILED",
304
- NONCE_MISMATCH: "NONCE_MISMATCH",
305
- ROLE_UPDATE_FAILED: "ROLE_UPDATE_FAILED",
306
- USER_CREATION_FAILED: "USER_CREATION_FAILED",
307
- WHITELIST_CHECK_FAILED: "WHITELIST_CHECK_FAILED",
308
- EMAIL_NOT_VERIFIED: "EMAIL_NOT_VERIFIED",
309
- ID_TOKEN_INVALID: "ID_TOKEN_INVALID"
310
- };
311
- const ERROR_DETAIL_TEMPLATES = {
312
- token_exchange_failed: "Token exchange failed with HTTP status {status}",
313
- userinfo_fetch_failed: "UserInfo endpoint returned HTTP {status}",
314
- role_update_failed: "Role update failed for user {userId}: {error}",
315
- user_creation_failed: "User creation failed for {email}: {error}",
316
- id_token_parse_failed: "ID token parse failed: {error}",
317
- sign_in_unknown: "Unknown sign-in error: {error}",
318
- invalid_email: "Invalid email address received from OIDC provider",
319
- email_not_verified: "Email address has not been verified by the OIDC provider",
320
- id_token_invalid: "ID token verification failed: {error}",
321
- whitelist_not_present: "Email not present in whitelist",
322
- session_manager_unsupported: "sessionManager is not supported. Please upgrade to Strapi v5.24.1 or later.",
323
- missing_config: "Missing required config keys: {keys}"
324
- };
325
- function interpolate$1(template, params) {
326
- if (!params) return template;
327
- return template.replace(/\{(\w+)\}/g, (_, key) => String(params[key] ?? `{${key}}`));
328
- }
329
- function getErrorDetail(key, params) {
330
- const template = ERROR_DETAIL_TEMPLATES[key];
331
- if (!template) return void 0;
332
- return interpolate$1(template, params);
333
- }
334
- const errorMessages = {
335
- TOKEN_EXCHANGE_FAILED: "Token exchange failed",
336
- USERINFO_FETCH_FAILED: "Failed to fetch user info",
337
- ID_TOKEN_PARSE_FAILED: "Failed to parse ID token",
338
- NONCE_MISMATCH: "Nonce mismatch",
339
- INVALID_EMAIL: "Invalid email address received from OIDC provider",
340
- EMAIL_NOT_VERIFIED: "Email address has not been verified by the OIDC provider",
341
- ID_TOKEN_INVALID: "ID token verification failed",
342
- WHITELIST_NOT_PRESENT: "Not present in whitelist",
343
- SESSION_MANAGER_UNSUPPORTED: "sessionManager is not supported. Please upgrade to Strapi v5.24.1 or later.",
344
- MISSING_CONFIG: (keys) => `Missing required config keys: ${keys}`
345
- };
346
351
  const en = {
347
352
  "global.plugins.strapi-plugin-oidc": "OIDC Plugin",
348
353
  "page.title": "Configure OIDC default role(s) and access controls.",
@@ -617,9 +622,7 @@ async function verifyIdToken(idToken, config2) {
617
622
  if (!jwksUri) {
618
623
  if (!jwksDisabledWarned) {
619
624
  jwksDisabledWarned = true;
620
- strapi.log.warn(
621
- "[OIDC] OIDC_JWKS_URI is not configured — ID token signature verification is disabled. Set OIDC_JWKS_URI and OIDC_ISSUER from your provider's discovery document."
622
- );
625
+ strapi.log.warn(errorMessages.JWKS_URI_NOT_CONFIGURED);
623
626
  }
624
627
  return null;
625
628
  }
@@ -1391,7 +1394,7 @@ function errorAwareNdjsonStream(strapi2, service, filters) {
1391
1394
  const gen = ndjsonRowStream(service, filters);
1392
1395
  const readable = node_stream.Readable.from(gen);
1393
1396
  readable.on("error", (err) => {
1394
- strapi2.log.error({ phase: "audit_log_export", err }, "NDJSON export stream failed");
1397
+ strapi2.log.error({ phase: "audit_log_export", err }, errorMessages.AUDIT_LOG_EXPORT_ERROR);
1395
1398
  });
1396
1399
  return readable;
1397
1400
  }
@@ -6,6 +6,58 @@ import strapiUtils from "@strapi/utils";
6
6
  import generator from "generate-password";
7
7
  function register$1() {
8
8
  }
9
+ const errorCodes = {
10
+ TOKEN_EXCHANGE_FAILED: "TOKEN_EXCHANGE_FAILED",
11
+ USERINFO_FETCH_FAILED: "USERINFO_FETCH_FAILED",
12
+ ID_TOKEN_PARSE_FAILED: "ID_TOKEN_PARSE_FAILED",
13
+ NONCE_MISMATCH: "NONCE_MISMATCH",
14
+ ROLE_UPDATE_FAILED: "ROLE_UPDATE_FAILED",
15
+ USER_CREATION_FAILED: "USER_CREATION_FAILED",
16
+ WHITELIST_CHECK_FAILED: "WHITELIST_CHECK_FAILED",
17
+ EMAIL_NOT_VERIFIED: "EMAIL_NOT_VERIFIED",
18
+ ID_TOKEN_INVALID: "ID_TOKEN_INVALID"
19
+ };
20
+ const ERROR_DETAIL_TEMPLATES = {
21
+ token_exchange_failed: "Token exchange failed with HTTP status {status}",
22
+ userinfo_fetch_failed: "UserInfo endpoint returned HTTP {status}",
23
+ role_update_failed: "Role update failed for user {userId}: {error}",
24
+ user_creation_failed: "User creation failed for {email}: {error}",
25
+ id_token_parse_failed: "ID token parse failed: {error}",
26
+ sign_in_unknown: "Unknown sign-in error: {error}",
27
+ invalid_email: "Invalid email address received from OIDC provider",
28
+ email_not_verified: "Email address has not been verified by the OIDC provider",
29
+ id_token_invalid: "ID token verification failed: {error}",
30
+ whitelist_not_present: "Email not present in whitelist",
31
+ session_manager_unsupported: "sessionManager is not supported. Please upgrade to Strapi v5.24.1 or later."
32
+ };
33
+ function interpolate$1(template, params) {
34
+ if (!params) return template;
35
+ return template.replace(/\{(\w+)\}/g, (_, key) => String(params[key] ?? `{${key}}`));
36
+ }
37
+ function getErrorDetail(key, params) {
38
+ const template = ERROR_DETAIL_TEMPLATES[key];
39
+ if (!template) return void 0;
40
+ return interpolate$1(template, params);
41
+ }
42
+ const errorMessages = {
43
+ TOKEN_EXCHANGE_FAILED: "Token exchange failed",
44
+ USERINFO_FETCH_FAILED: "Failed to fetch user info",
45
+ ID_TOKEN_PARSE_FAILED: "Failed to parse ID token",
46
+ NONCE_MISMATCH: "Nonce mismatch",
47
+ INVALID_EMAIL: "Invalid email address received from OIDC provider",
48
+ EMAIL_NOT_VERIFIED: "Email address has not been verified by the OIDC provider",
49
+ ID_TOKEN_INVALID: "ID token verification failed",
50
+ WHITELIST_NOT_PRESENT: "Not present in whitelist",
51
+ SESSION_MANAGER_UNSUPPORTED: "sessionManager is not supported. Please upgrade to Strapi v5.24.1 or later.",
52
+ JWKS_URI_NOT_CONFIGURED: "[OIDC] OIDC_JWKS_URI is not configured — ID token signature verification is disabled. Set OIDC_JWKS_URI and OIDC_ISSUER from your provider's discovery document.",
53
+ ENFORCE_MIDDLEWARE_ERROR: "Error checking OIDC enforcement in middleware:",
54
+ ENFORCE_SYNC_ERROR: "[strapi-plugin-oidc] Failed to sync OIDC_ENFORCE to database:",
55
+ DEFAULT_ROLE_INIT_ERROR: "Could not initialize default OIDC role:",
56
+ AUDIT_LOG_CLEANUP_ERROR: "[strapi-plugin-oidc] Audit log cleanup failed:",
57
+ AUDIT_LOG_EXPORT_ERROR: "NDJSON export stream failed",
58
+ DISCOVERY_FETCH_ERROR: (url, reason) => `[strapi-plugin-oidc] Failed to fetch OIDC discovery document from ${url}: ${reason}`,
59
+ MISSING_CONFIG: (keys) => `Missing required config keys: ${keys}`
60
+ };
9
61
  function getEnforceOIDCConfig(strapi2) {
10
62
  const config2 = strapi2.config.get("plugin::strapi-plugin-oidc");
11
63
  const val = config2.OIDC_ENFORCE;
@@ -57,10 +109,9 @@ async function applyDiscovery(strapi2) {
57
109
  if (!res.ok) throw new Error(`HTTP ${res.status}`);
58
110
  doc = await res.json();
59
111
  } catch (e) {
60
- strapi2.log.error(
61
- `[strapi-plugin-oidc] Failed to fetch OIDC discovery document from ${discoveryUrl}: ${e instanceof Error ? e.message : String(e)}`
112
+ throw new Error(
113
+ errorMessages.DISCOVERY_FETCH_ERROR(discoveryUrl, e instanceof Error ? e.message : String(e))
62
114
  );
63
- return;
64
115
  }
65
116
  const updates = {};
66
117
  for (const [docField, configKey] of FIELD_MAP) {
@@ -115,7 +166,7 @@ async function bootstrap({ strapi: strapi2 }) {
115
166
  return;
116
167
  }
117
168
  } catch (err) {
118
- strapi2.log.error("Error checking OIDC enforcement in middleware:", err);
169
+ strapi2.log.error(errorMessages.ENFORCE_MIDDLEWARE_ERROR, err);
119
170
  }
120
171
  }
121
172
  await next();
@@ -152,7 +203,7 @@ async function bootstrap({ strapi: strapi2 }) {
152
203
  );
153
204
  }
154
205
  } catch (err) {
155
- strapi2.log.error("[strapi-plugin-oidc] Failed to sync OIDC_ENFORCE to database:", err);
206
+ strapi2.log.error(errorMessages.ENFORCE_SYNC_ERROR, err);
156
207
  }
157
208
  }
158
209
  try {
@@ -166,7 +217,7 @@ async function bootstrap({ strapi: strapi2 }) {
166
217
  }
167
218
  }
168
219
  } catch (err) {
169
- strapi2.log.warn("Could not initialize default OIDC role:", err.message);
220
+ strapi2.log.warn(errorMessages.DEFAULT_ROLE_INIT_ERROR, err.message);
170
221
  }
171
222
  strapi2.cron.add({
172
223
  "strapi-plugin-oidc-audit-log-cleanup": {
@@ -175,7 +226,7 @@ async function bootstrap({ strapi: strapi2 }) {
175
226
  const retentionDays = getRetentionDays();
176
227
  await getAuditLogService().cleanup(retentionDays);
177
228
  } catch (err) {
178
- strapi2.log.warn("[strapi-plugin-oidc] Audit log cleanup failed:", err.message);
229
+ strapi2.log.warn(errorMessages.AUDIT_LOG_CLEANUP_ERROR, err.message);
179
230
  }
180
231
  },
181
232
  options: { rule: "0 0 * * *" }
@@ -291,52 +342,6 @@ const EMAIL_REGEX = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
291
342
  function isValidEmail(email) {
292
343
  return EMAIL_REGEX.test(email);
293
344
  }
294
- const errorCodes = {
295
- TOKEN_EXCHANGE_FAILED: "TOKEN_EXCHANGE_FAILED",
296
- USERINFO_FETCH_FAILED: "USERINFO_FETCH_FAILED",
297
- ID_TOKEN_PARSE_FAILED: "ID_TOKEN_PARSE_FAILED",
298
- NONCE_MISMATCH: "NONCE_MISMATCH",
299
- ROLE_UPDATE_FAILED: "ROLE_UPDATE_FAILED",
300
- USER_CREATION_FAILED: "USER_CREATION_FAILED",
301
- WHITELIST_CHECK_FAILED: "WHITELIST_CHECK_FAILED",
302
- EMAIL_NOT_VERIFIED: "EMAIL_NOT_VERIFIED",
303
- ID_TOKEN_INVALID: "ID_TOKEN_INVALID"
304
- };
305
- const ERROR_DETAIL_TEMPLATES = {
306
- token_exchange_failed: "Token exchange failed with HTTP status {status}",
307
- userinfo_fetch_failed: "UserInfo endpoint returned HTTP {status}",
308
- role_update_failed: "Role update failed for user {userId}: {error}",
309
- user_creation_failed: "User creation failed for {email}: {error}",
310
- id_token_parse_failed: "ID token parse failed: {error}",
311
- sign_in_unknown: "Unknown sign-in error: {error}",
312
- invalid_email: "Invalid email address received from OIDC provider",
313
- email_not_verified: "Email address has not been verified by the OIDC provider",
314
- id_token_invalid: "ID token verification failed: {error}",
315
- whitelist_not_present: "Email not present in whitelist",
316
- session_manager_unsupported: "sessionManager is not supported. Please upgrade to Strapi v5.24.1 or later.",
317
- missing_config: "Missing required config keys: {keys}"
318
- };
319
- function interpolate$1(template, params) {
320
- if (!params) return template;
321
- return template.replace(/\{(\w+)\}/g, (_, key) => String(params[key] ?? `{${key}}`));
322
- }
323
- function getErrorDetail(key, params) {
324
- const template = ERROR_DETAIL_TEMPLATES[key];
325
- if (!template) return void 0;
326
- return interpolate$1(template, params);
327
- }
328
- const errorMessages = {
329
- TOKEN_EXCHANGE_FAILED: "Token exchange failed",
330
- USERINFO_FETCH_FAILED: "Failed to fetch user info",
331
- ID_TOKEN_PARSE_FAILED: "Failed to parse ID token",
332
- NONCE_MISMATCH: "Nonce mismatch",
333
- INVALID_EMAIL: "Invalid email address received from OIDC provider",
334
- EMAIL_NOT_VERIFIED: "Email address has not been verified by the OIDC provider",
335
- ID_TOKEN_INVALID: "ID token verification failed",
336
- WHITELIST_NOT_PRESENT: "Not present in whitelist",
337
- SESSION_MANAGER_UNSUPPORTED: "sessionManager is not supported. Please upgrade to Strapi v5.24.1 or later.",
338
- MISSING_CONFIG: (keys) => `Missing required config keys: ${keys}`
339
- };
340
345
  const en = {
341
346
  "global.plugins.strapi-plugin-oidc": "OIDC Plugin",
342
347
  "page.title": "Configure OIDC default role(s) and access controls.",
@@ -611,9 +616,7 @@ async function verifyIdToken(idToken, config2) {
611
616
  if (!jwksUri) {
612
617
  if (!jwksDisabledWarned) {
613
618
  jwksDisabledWarned = true;
614
- strapi.log.warn(
615
- "[OIDC] OIDC_JWKS_URI is not configured — ID token signature verification is disabled. Set OIDC_JWKS_URI and OIDC_ISSUER from your provider's discovery document."
616
- );
619
+ strapi.log.warn(errorMessages.JWKS_URI_NOT_CONFIGURED);
617
620
  }
618
621
  return null;
619
622
  }
@@ -1385,7 +1388,7 @@ function errorAwareNdjsonStream(strapi2, service, filters) {
1385
1388
  const gen = ndjsonRowStream(service, filters);
1386
1389
  const readable = Readable.from(gen);
1387
1390
  readable.on("error", (err) => {
1388
- strapi2.log.error({ phase: "audit_log_export", err }, "NDJSON export stream failed");
1391
+ strapi2.log.error({ phase: "audit_log_export", err }, errorMessages.AUDIT_LOG_EXPORT_ERROR);
1389
1392
  });
1390
1393
  return readable;
1391
1394
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "strapi-plugin-oidc",
3
- "version": "1.8.1",
3
+ "version": "1.8.2",
4
4
  "description": "A Strapi plugin that provides OpenID Connect (OIDC) authentication functionality for the Strapi Admin Panel.",
5
5
  "strapi": {
6
6
  "displayName": "OIDC Plugin",