strapi-custom-auth 1.2.9 → 1.2.11
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/_chunks/{DynamicExpenses-ZL8hH1s8.js → DynamicExpenses-DS5zRFz3.js} +2 -2
- package/dist/admin/index.js +6 -19
- package/dist/admin/index.mjs +3 -16
- package/dist/server/index.js +32 -5
- package/dist/server/index.mjs +32 -5
- package/package.json +1 -1
- package/dist/_chunks/App-B-bQ656I.mjs +0 -1866
- package/dist/_chunks/App-CdSJ6UQk.js +0 -1869
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const jsxRuntime = require("react/jsx-runtime");
|
|
4
|
-
const
|
|
4
|
+
const react = require("react");
|
|
5
5
|
const designSystem = require("@strapi/design-system");
|
|
6
6
|
const DynamicExpenses = ({
|
|
7
7
|
description,
|
|
@@ -14,7 +14,7 @@ const DynamicExpenses = ({
|
|
|
14
14
|
value
|
|
15
15
|
}) => {
|
|
16
16
|
const tempValue = value ? value.split(":")[0] : null;
|
|
17
|
-
const [selection, setSelection] =
|
|
17
|
+
const [selection, setSelection] = react.useState(
|
|
18
18
|
tempValue === "p" ? "percentuali" : tempValue === "f" ? "fisse" : "nessuna"
|
|
19
19
|
);
|
|
20
20
|
return /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { fontSize: "12px" }, children: [
|
package/dist/admin/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
const
|
|
3
|
-
|
|
2
|
+
const react = require("react");
|
|
3
|
+
require("react/jsx-runtime");
|
|
4
4
|
const icons = require("@strapi/icons");
|
|
5
5
|
const __variableDynamicImportRuntimeHelper = (glob, path, segs) => {
|
|
6
6
|
const v = glob[path];
|
|
@@ -20,13 +20,12 @@ const __variableDynamicImportRuntimeHelper = (glob, path, segs) => {
|
|
|
20
20
|
};
|
|
21
21
|
const PLUGIN_ID = "strapi-custom-auth";
|
|
22
22
|
const Initializer = ({ setPlugin }) => {
|
|
23
|
-
const ref =
|
|
24
|
-
|
|
23
|
+
const ref = react.useRef(setPlugin);
|
|
24
|
+
react.useEffect(() => {
|
|
25
25
|
ref.current(PLUGIN_ID);
|
|
26
26
|
}, []);
|
|
27
27
|
return null;
|
|
28
28
|
};
|
|
29
|
-
const PluginIcon = () => /* @__PURE__ */ jsxRuntime.jsx(icons.PuzzlePiece, {});
|
|
30
29
|
const isTokenExpired = (token) => {
|
|
31
30
|
if (!token) return true;
|
|
32
31
|
try {
|
|
@@ -69,7 +68,7 @@ const originalFetch = window.fetch;
|
|
|
69
68
|
const fetchInterceptor = (storage) => {
|
|
70
69
|
window.fetch = async (input, init = {}) => {
|
|
71
70
|
const url = input instanceof Request ? input.url : input;
|
|
72
|
-
if (url.includes("/admin/renew-token") || url.includes("/auth/login") || url.includes("repos/strapi/strapi/releases/latest") || url.includes("/admin/init")) {
|
|
71
|
+
if (url.includes("/admin/renew-token") || url.includes("/auth/login") || url.includes("repos/strapi/strapi/releases/latest") || url.includes("/admin/init") || init.body instanceof FormData) {
|
|
73
72
|
return originalFetch(input, init);
|
|
74
73
|
}
|
|
75
74
|
let token = storage.getItem("jwtToken").replace(/"/g, "");
|
|
@@ -124,18 +123,6 @@ const fetchInterceptor = (storage) => {
|
|
|
124
123
|
};
|
|
125
124
|
const index = {
|
|
126
125
|
register(app) {
|
|
127
|
-
app.addMenuLink({
|
|
128
|
-
to: `plugins/${PluginIcon}`,
|
|
129
|
-
icon: PluginIcon,
|
|
130
|
-
intlLabel: {
|
|
131
|
-
id: `${PLUGIN_ID}.plugin.name`,
|
|
132
|
-
defaultMessage: PLUGIN_ID
|
|
133
|
-
},
|
|
134
|
-
Component: async () => {
|
|
135
|
-
const { App } = await Promise.resolve().then(() => require("../_chunks/App-CdSJ6UQk.js"));
|
|
136
|
-
return App;
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
126
|
app.registerPlugin({
|
|
140
127
|
id: PLUGIN_ID,
|
|
141
128
|
initializer: Initializer,
|
|
@@ -155,7 +142,7 @@ const index = {
|
|
|
155
142
|
defaultMessage: "Create your Dynamic Expenses"
|
|
156
143
|
},
|
|
157
144
|
components: {
|
|
158
|
-
Input: async () => Promise.resolve().then(() => require("../_chunks/DynamicExpenses-
|
|
145
|
+
Input: async () => Promise.resolve().then(() => require("../_chunks/DynamicExpenses-DS5zRFz3.js")).then((module2) => ({
|
|
159
146
|
default: module2.DynamicExpenses
|
|
160
147
|
}))
|
|
161
148
|
}
|
package/dist/admin/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useRef, useEffect } from "react";
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
2
|
+
import "react/jsx-runtime";
|
|
3
|
+
import { SignOut } from "@strapi/icons";
|
|
4
4
|
const __variableDynamicImportRuntimeHelper = (glob, path, segs) => {
|
|
5
5
|
const v = glob[path];
|
|
6
6
|
if (v) {
|
|
@@ -25,7 +25,6 @@ const Initializer = ({ setPlugin }) => {
|
|
|
25
25
|
}, []);
|
|
26
26
|
return null;
|
|
27
27
|
};
|
|
28
|
-
const PluginIcon = () => /* @__PURE__ */ jsx(PuzzlePiece, {});
|
|
29
28
|
const isTokenExpired = (token) => {
|
|
30
29
|
if (!token) return true;
|
|
31
30
|
try {
|
|
@@ -68,7 +67,7 @@ const originalFetch = window.fetch;
|
|
|
68
67
|
const fetchInterceptor = (storage) => {
|
|
69
68
|
window.fetch = async (input, init = {}) => {
|
|
70
69
|
const url = input instanceof Request ? input.url : input;
|
|
71
|
-
if (url.includes("/admin/renew-token") || url.includes("/auth/login") || url.includes("repos/strapi/strapi/releases/latest") || url.includes("/admin/init")) {
|
|
70
|
+
if (url.includes("/admin/renew-token") || url.includes("/auth/login") || url.includes("repos/strapi/strapi/releases/latest") || url.includes("/admin/init") || init.body instanceof FormData) {
|
|
72
71
|
return originalFetch(input, init);
|
|
73
72
|
}
|
|
74
73
|
let token = storage.getItem("jwtToken").replace(/"/g, "");
|
|
@@ -123,18 +122,6 @@ const fetchInterceptor = (storage) => {
|
|
|
123
122
|
};
|
|
124
123
|
const index = {
|
|
125
124
|
register(app) {
|
|
126
|
-
app.addMenuLink({
|
|
127
|
-
to: `plugins/${PluginIcon}`,
|
|
128
|
-
icon: PluginIcon,
|
|
129
|
-
intlLabel: {
|
|
130
|
-
id: `${PLUGIN_ID}.plugin.name`,
|
|
131
|
-
defaultMessage: PLUGIN_ID
|
|
132
|
-
},
|
|
133
|
-
Component: async () => {
|
|
134
|
-
const { App } = await import("../_chunks/App-B-bQ656I.mjs");
|
|
135
|
-
return App;
|
|
136
|
-
}
|
|
137
|
-
});
|
|
138
125
|
app.registerPlugin({
|
|
139
126
|
id: PLUGIN_ID,
|
|
140
127
|
initializer: Initializer,
|
package/dist/server/index.js
CHANGED
|
@@ -3319,18 +3319,23 @@ async function microsoftSignInCallback(ctx) {
|
|
|
3319
3319
|
const groupsList = groupResponse?.data.value;
|
|
3320
3320
|
console.log("[STRAPI-CUSTOM-AUTH] Microsoft Sign Callback USER groups", groupsList);
|
|
3321
3321
|
const { mail, givenName, surname } = userResponse?.data;
|
|
3322
|
-
const dbUser = await userService.findOneByEmail(mail);
|
|
3322
|
+
const dbUser = await userService.findOneByEmail(mail, { roles: true });
|
|
3323
3323
|
let activateUser;
|
|
3324
3324
|
let jwtToken;
|
|
3325
|
-
console.log("[STRAPI-CUSTOM-AUTH] Microsoft Sign Callback retrieve roles", await roleService.retrieveMicrosoftUserRole(groupsList, config2));
|
|
3326
3325
|
console.log("[STRAPI-CUSTOM-AUTH] Microsoft Sign Callback: check user existence");
|
|
3327
3326
|
if (dbUser) {
|
|
3328
3327
|
console.log("[STRAPI-CUSTOM-AUTH] Microsoft Sign Callback: user exists generating token");
|
|
3329
|
-
|
|
3328
|
+
const hasRoleMismatch = await roleService.checkMicrosoftUserRolesMismatch(dbUser, groupsList, config2);
|
|
3329
|
+
if (hasRoleMismatch) {
|
|
3330
|
+
console.log("[STRAPI-CUSTOM-AUTH] Microsoft Sign Callback: user exists but has role mismatch, fixing it.");
|
|
3331
|
+
activateUser = await roleService.updateMicrosoftUserRoles(dbUser, groupsList, config2);
|
|
3332
|
+
} else {
|
|
3333
|
+
activateUser = dbUser;
|
|
3334
|
+
}
|
|
3330
3335
|
jwtToken = await tokenService.createJwtToken(activateUser);
|
|
3331
3336
|
} else {
|
|
3332
3337
|
console.log("[STRAPI-CUSTOM-AUTH] Microsoft Sign Callback: user does not exist, creating it");
|
|
3333
|
-
const roles2 = await roleService.
|
|
3338
|
+
const roles2 = await roleService.retrieveMicrosoftUserRoles(groupsList, config2);
|
|
3334
3339
|
const defaultLocale = oauthService.localeFindByHeader(ctx.request.headers);
|
|
3335
3340
|
activateUser = await oauthService.createUser(mail, surname, givenName, defaultLocale, roles2);
|
|
3336
3341
|
console.log("[STRAPI-CUSTOM-AUTH] Microsoft Sign Callback: user created, generating token");
|
|
@@ -39420,7 +39425,7 @@ var role = ({ strapi: strapi2 }) => ({
|
|
|
39420
39425
|
})
|
|
39421
39426
|
);
|
|
39422
39427
|
},
|
|
39423
|
-
async
|
|
39428
|
+
async retrieveMicrosoftUserRoles(groupList, config2) {
|
|
39424
39429
|
const allowedGroups = /* @__PURE__ */ new Set([
|
|
39425
39430
|
String(config2["ENTRA_ADMIN_GROUP_NAME"]),
|
|
39426
39431
|
String(config2["ENTRA_EDITOR_GROUP_NAME"])
|
|
@@ -39434,6 +39439,28 @@ var role = ({ strapi: strapi2 }) => ({
|
|
|
39434
39439
|
}).filter(Boolean);
|
|
39435
39440
|
console.log("[STRAPI-CUSTOM-AUTH] Microsoft Sign Callback USER strapi roles matched with entra groups", roles2);
|
|
39436
39441
|
return roles2;
|
|
39442
|
+
},
|
|
39443
|
+
async checkMicrosoftUserRolesMismatch(user, groupList, config2) {
|
|
39444
|
+
console.log("[STRAPI-CUSTOM-AUTH] Microsoft Sign Callback checkMicrosoftUserRolesMismatch: START");
|
|
39445
|
+
const entraMatchedRoles = await this.retrieveMicrosoftUserRoles(groupList, config2);
|
|
39446
|
+
console.log("[STRAPI-CUSTOM-AUTH] Microsoft Sign Callback checkMicrosoftUserRolesMismatch: Roles matched with entra groups ->", entraMatchedRoles);
|
|
39447
|
+
const userCurrentRoles = user.roles.map((role2) => role2.id) || [];
|
|
39448
|
+
console.log("[STRAPI-CUSTOM-AUTH] Microsoft Sign Callback checkMicrosoftUserRolesMismatch: User current roles", userCurrentRoles);
|
|
39449
|
+
console.log("[STRAPI-CUSTOM-AUTH] Microsoft Sign Callback checkMicrosoftUserRolesMismatch: END");
|
|
39450
|
+
return entraMatchedRoles.some((roleId) => !userCurrentRoles.includes(roleId));
|
|
39451
|
+
},
|
|
39452
|
+
async updateMicrosoftUserRoles(user, groupList, config2) {
|
|
39453
|
+
console.log("[STRAPI-CUSTOM-AUTH] Microsoft Sign Callback updateMicrosoftUserRoles: START");
|
|
39454
|
+
const userService = strapi2.service("admin::user");
|
|
39455
|
+
const entraMatchedRoles = await this.retrieveMicrosoftUserRoles(groupList, config2);
|
|
39456
|
+
const userCurrentRoles = user.roles.map((role2) => role2.id) || [];
|
|
39457
|
+
const rolesToAdd = entraMatchedRoles.filter((roleId) => !userCurrentRoles.includes(roleId));
|
|
39458
|
+
console.log("[STRAPI-CUSTOM-AUTH] Microsoft Sign Callback updateMicrosoftUserRoles: Roles to add ->", rolesToAdd);
|
|
39459
|
+
await userService.updateById(user.id, { roles: [...userCurrentRoles, ...rolesToAdd] });
|
|
39460
|
+
console.log("[STRAPI-CUSTOM-AUTH] Microsoft Sign Callback updateMicrosoftUserRoles: Updated user roles");
|
|
39461
|
+
const updatedUser = await userService.findOne(user.id);
|
|
39462
|
+
console.log("[STRAPI-CUSTOM-AUTH] Microsoft Sign Callback updateMicrosoftUserRoles: END");
|
|
39463
|
+
return updatedUser;
|
|
39437
39464
|
}
|
|
39438
39465
|
});
|
|
39439
39466
|
const role$1 = /* @__PURE__ */ getDefaultExportFromCjs(role);
|
package/dist/server/index.mjs
CHANGED
|
@@ -3304,18 +3304,23 @@ async function microsoftSignInCallback(ctx) {
|
|
|
3304
3304
|
const groupsList = groupResponse?.data.value;
|
|
3305
3305
|
console.log("[STRAPI-CUSTOM-AUTH] Microsoft Sign Callback USER groups", groupsList);
|
|
3306
3306
|
const { mail, givenName, surname } = userResponse?.data;
|
|
3307
|
-
const dbUser = await userService.findOneByEmail(mail);
|
|
3307
|
+
const dbUser = await userService.findOneByEmail(mail, { roles: true });
|
|
3308
3308
|
let activateUser;
|
|
3309
3309
|
let jwtToken;
|
|
3310
|
-
console.log("[STRAPI-CUSTOM-AUTH] Microsoft Sign Callback retrieve roles", await roleService.retrieveMicrosoftUserRole(groupsList, config2));
|
|
3311
3310
|
console.log("[STRAPI-CUSTOM-AUTH] Microsoft Sign Callback: check user existence");
|
|
3312
3311
|
if (dbUser) {
|
|
3313
3312
|
console.log("[STRAPI-CUSTOM-AUTH] Microsoft Sign Callback: user exists generating token");
|
|
3314
|
-
|
|
3313
|
+
const hasRoleMismatch = await roleService.checkMicrosoftUserRolesMismatch(dbUser, groupsList, config2);
|
|
3314
|
+
if (hasRoleMismatch) {
|
|
3315
|
+
console.log("[STRAPI-CUSTOM-AUTH] Microsoft Sign Callback: user exists but has role mismatch, fixing it.");
|
|
3316
|
+
activateUser = await roleService.updateMicrosoftUserRoles(dbUser, groupsList, config2);
|
|
3317
|
+
} else {
|
|
3318
|
+
activateUser = dbUser;
|
|
3319
|
+
}
|
|
3315
3320
|
jwtToken = await tokenService.createJwtToken(activateUser);
|
|
3316
3321
|
} else {
|
|
3317
3322
|
console.log("[STRAPI-CUSTOM-AUTH] Microsoft Sign Callback: user does not exist, creating it");
|
|
3318
|
-
const roles2 = await roleService.
|
|
3323
|
+
const roles2 = await roleService.retrieveMicrosoftUserRoles(groupsList, config2);
|
|
3319
3324
|
const defaultLocale = oauthService.localeFindByHeader(ctx.request.headers);
|
|
3320
3325
|
activateUser = await oauthService.createUser(mail, surname, givenName, defaultLocale, roles2);
|
|
3321
3326
|
console.log("[STRAPI-CUSTOM-AUTH] Microsoft Sign Callback: user created, generating token");
|
|
@@ -39405,7 +39410,7 @@ var role = ({ strapi: strapi2 }) => ({
|
|
|
39405
39410
|
})
|
|
39406
39411
|
);
|
|
39407
39412
|
},
|
|
39408
|
-
async
|
|
39413
|
+
async retrieveMicrosoftUserRoles(groupList, config2) {
|
|
39409
39414
|
const allowedGroups = /* @__PURE__ */ new Set([
|
|
39410
39415
|
String(config2["ENTRA_ADMIN_GROUP_NAME"]),
|
|
39411
39416
|
String(config2["ENTRA_EDITOR_GROUP_NAME"])
|
|
@@ -39419,6 +39424,28 @@ var role = ({ strapi: strapi2 }) => ({
|
|
|
39419
39424
|
}).filter(Boolean);
|
|
39420
39425
|
console.log("[STRAPI-CUSTOM-AUTH] Microsoft Sign Callback USER strapi roles matched with entra groups", roles2);
|
|
39421
39426
|
return roles2;
|
|
39427
|
+
},
|
|
39428
|
+
async checkMicrosoftUserRolesMismatch(user, groupList, config2) {
|
|
39429
|
+
console.log("[STRAPI-CUSTOM-AUTH] Microsoft Sign Callback checkMicrosoftUserRolesMismatch: START");
|
|
39430
|
+
const entraMatchedRoles = await this.retrieveMicrosoftUserRoles(groupList, config2);
|
|
39431
|
+
console.log("[STRAPI-CUSTOM-AUTH] Microsoft Sign Callback checkMicrosoftUserRolesMismatch: Roles matched with entra groups ->", entraMatchedRoles);
|
|
39432
|
+
const userCurrentRoles = user.roles.map((role2) => role2.id) || [];
|
|
39433
|
+
console.log("[STRAPI-CUSTOM-AUTH] Microsoft Sign Callback checkMicrosoftUserRolesMismatch: User current roles", userCurrentRoles);
|
|
39434
|
+
console.log("[STRAPI-CUSTOM-AUTH] Microsoft Sign Callback checkMicrosoftUserRolesMismatch: END");
|
|
39435
|
+
return entraMatchedRoles.some((roleId) => !userCurrentRoles.includes(roleId));
|
|
39436
|
+
},
|
|
39437
|
+
async updateMicrosoftUserRoles(user, groupList, config2) {
|
|
39438
|
+
console.log("[STRAPI-CUSTOM-AUTH] Microsoft Sign Callback updateMicrosoftUserRoles: START");
|
|
39439
|
+
const userService = strapi2.service("admin::user");
|
|
39440
|
+
const entraMatchedRoles = await this.retrieveMicrosoftUserRoles(groupList, config2);
|
|
39441
|
+
const userCurrentRoles = user.roles.map((role2) => role2.id) || [];
|
|
39442
|
+
const rolesToAdd = entraMatchedRoles.filter((roleId) => !userCurrentRoles.includes(roleId));
|
|
39443
|
+
console.log("[STRAPI-CUSTOM-AUTH] Microsoft Sign Callback updateMicrosoftUserRoles: Roles to add ->", rolesToAdd);
|
|
39444
|
+
await userService.updateById(user.id, { roles: [...userCurrentRoles, ...rolesToAdd] });
|
|
39445
|
+
console.log("[STRAPI-CUSTOM-AUTH] Microsoft Sign Callback updateMicrosoftUserRoles: Updated user roles");
|
|
39446
|
+
const updatedUser = await userService.findOne(user.id);
|
|
39447
|
+
console.log("[STRAPI-CUSTOM-AUTH] Microsoft Sign Callback updateMicrosoftUserRoles: END");
|
|
39448
|
+
return updatedUser;
|
|
39422
39449
|
}
|
|
39423
39450
|
});
|
|
39424
39451
|
const role$1 = /* @__PURE__ */ getDefaultExportFromCjs(role);
|
package/package.json
CHANGED