strapi-plugin-oidc 1.6.5 → 1.6.6
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 +7 -7
- package/dist/admin/{index-HQ2uuypE.mjs → index-CKyNupYU.mjs} +231 -103
- package/dist/admin/{index-DgUClS5s.mjs → index-D2aMSVmR.mjs} +2 -5
- package/dist/admin/{index-pWwCtdNu.js → index-DUFtPEHD.js} +230 -102
- package/dist/admin/{index-C2BnnDzh.js → index-DVjS4hOr.js} +2 -5
- package/dist/admin/index.js +1 -1
- package/dist/admin/index.mjs +1 -1
- package/dist/server/index.js +238 -162
- package/dist/server/index.mjs +238 -162
- package/package.json +1 -1
|
@@ -7,7 +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-
|
|
10
|
+
const index = require("./index-DVjS4hOr.js");
|
|
11
11
|
const styled = require("styled-components");
|
|
12
12
|
const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
|
|
13
13
|
const styled__default = /* @__PURE__ */ _interopDefault(styled);
|
|
@@ -371,8 +371,7 @@ function AuditLog() {
|
|
|
371
371
|
});
|
|
372
372
|
return;
|
|
373
373
|
}
|
|
374
|
-
const
|
|
375
|
-
const blob = new Blob([text], { type: "application/x-ndjson" });
|
|
374
|
+
const blob = await response.blob();
|
|
376
375
|
const url = URL.createObjectURL(blob);
|
|
377
376
|
const a = document.createElement("a");
|
|
378
377
|
a.href = url;
|
|
@@ -575,75 +574,201 @@ function formatDatetimeForFilename(date) {
|
|
|
575
574
|
const seconds = String(date.getSeconds()).padStart(2, "0");
|
|
576
575
|
return `${year}${month}${day}_${hours}${minutes}${seconds}`;
|
|
577
576
|
}
|
|
578
|
-
function
|
|
579
|
-
|
|
577
|
+
function downloadJson(basename, data) {
|
|
578
|
+
const datetime = formatDatetimeForFilename(/* @__PURE__ */ new Date());
|
|
579
|
+
const blob = new Blob([JSON.stringify(data, null, 2)], { type: "application/json" });
|
|
580
|
+
const url = URL.createObjectURL(blob);
|
|
581
|
+
const a = document.createElement("a");
|
|
582
|
+
a.href = url;
|
|
583
|
+
a.download = `${basename}-${datetime}.json`;
|
|
584
|
+
a.click();
|
|
585
|
+
URL.revokeObjectURL(url);
|
|
586
|
+
}
|
|
587
|
+
const initialState = {
|
|
588
|
+
current: {
|
|
589
|
+
oidcRoles: [],
|
|
590
|
+
users: [],
|
|
591
|
+
useWhitelist: false,
|
|
592
|
+
enforceOIDC: false
|
|
593
|
+
},
|
|
594
|
+
initial: {
|
|
595
|
+
oidcRoles: [],
|
|
596
|
+
users: [],
|
|
597
|
+
useWhitelist: false,
|
|
598
|
+
enforceOIDC: false
|
|
599
|
+
},
|
|
600
|
+
roles: [],
|
|
601
|
+
enforceOIDCConfig: null,
|
|
602
|
+
auditLogEnabled: true,
|
|
603
|
+
loading: false,
|
|
604
|
+
showSuccess: false,
|
|
605
|
+
showError: false
|
|
606
|
+
};
|
|
607
|
+
function reducer(state, action) {
|
|
608
|
+
switch (action.type) {
|
|
609
|
+
case "hydrate/roles":
|
|
610
|
+
return { ...state, roles: action.roles };
|
|
611
|
+
case "hydrate/oidcRoles": {
|
|
612
|
+
const snapshot = { oidcRoles: action.oidcRoles };
|
|
613
|
+
return {
|
|
614
|
+
...state,
|
|
615
|
+
current: { ...state.current, ...snapshot },
|
|
616
|
+
initial: { ...state.initial, ...snapshot }
|
|
617
|
+
};
|
|
618
|
+
}
|
|
619
|
+
case "hydrate/whitelist": {
|
|
620
|
+
const snapshot = {
|
|
621
|
+
oidcRoles: action.snapshot.oidcRoles ?? state.current.oidcRoles,
|
|
622
|
+
users: action.snapshot.users ?? state.current.users,
|
|
623
|
+
useWhitelist: action.snapshot.useWhitelist ?? state.current.useWhitelist,
|
|
624
|
+
enforceOIDC: action.snapshot.enforceOIDC ?? state.current.enforceOIDC
|
|
625
|
+
};
|
|
626
|
+
return {
|
|
627
|
+
...state,
|
|
628
|
+
current: snapshot,
|
|
629
|
+
initial: structuredClone(snapshot),
|
|
630
|
+
enforceOIDCConfig: action.enforceOIDCConfig,
|
|
631
|
+
auditLogEnabled: action.auditLogEnabled
|
|
632
|
+
};
|
|
633
|
+
}
|
|
634
|
+
case "patch/oidcRole":
|
|
635
|
+
return {
|
|
636
|
+
...state,
|
|
637
|
+
current: {
|
|
638
|
+
...state.current,
|
|
639
|
+
oidcRoles: state.current.oidcRoles.map(
|
|
640
|
+
(role) => role.oauth_type === action.oidcId ? { ...role, role: action.values } : role
|
|
641
|
+
)
|
|
642
|
+
}
|
|
643
|
+
};
|
|
644
|
+
case "user/add":
|
|
645
|
+
return {
|
|
646
|
+
...state,
|
|
647
|
+
current: {
|
|
648
|
+
...state.current,
|
|
649
|
+
users: [
|
|
650
|
+
...state.current.users,
|
|
651
|
+
{ email: action.email, createdAt: (/* @__PURE__ */ new Date()).toISOString() }
|
|
652
|
+
]
|
|
653
|
+
}
|
|
654
|
+
};
|
|
655
|
+
case "user/delete": {
|
|
656
|
+
const updatedUsers = state.current.users.filter((u) => u.email !== action.email);
|
|
657
|
+
const updated = { users: updatedUsers };
|
|
658
|
+
let enforceOIDC = state.current.enforceOIDC;
|
|
659
|
+
if (state.current.useWhitelist && updatedUsers.length === 0) {
|
|
660
|
+
enforceOIDC = false;
|
|
661
|
+
}
|
|
662
|
+
return {
|
|
663
|
+
...state,
|
|
664
|
+
current: { ...state.current, ...updated, enforceOIDC }
|
|
665
|
+
};
|
|
666
|
+
}
|
|
667
|
+
case "users/clear": {
|
|
668
|
+
const updated = { users: [] };
|
|
669
|
+
let enforceOIDC = state.current.enforceOIDC;
|
|
670
|
+
if (state.current.useWhitelist) {
|
|
671
|
+
enforceOIDC = false;
|
|
672
|
+
}
|
|
673
|
+
return {
|
|
674
|
+
...state,
|
|
675
|
+
current: { ...state.current, ...updated, enforceOIDC }
|
|
676
|
+
};
|
|
677
|
+
}
|
|
678
|
+
case "users/replace":
|
|
679
|
+
return {
|
|
680
|
+
...state,
|
|
681
|
+
current: { ...state.current, users: action.users }
|
|
682
|
+
};
|
|
683
|
+
case "toggle/useWhitelist": {
|
|
684
|
+
const useWhitelist = action.value;
|
|
685
|
+
let enforceOIDC = state.current.enforceOIDC;
|
|
686
|
+
if (useWhitelist && state.current.users.length === 0) {
|
|
687
|
+
enforceOIDC = false;
|
|
688
|
+
}
|
|
689
|
+
return {
|
|
690
|
+
...state,
|
|
691
|
+
current: { ...state.current, useWhitelist, enforceOIDC }
|
|
692
|
+
};
|
|
693
|
+
}
|
|
694
|
+
case "toggle/enforceOIDC":
|
|
695
|
+
return {
|
|
696
|
+
...state,
|
|
697
|
+
current: { ...state.current, enforceOIDC: action.value }
|
|
698
|
+
};
|
|
699
|
+
case "commit":
|
|
700
|
+
return {
|
|
701
|
+
...state,
|
|
702
|
+
initial: structuredClone(
|
|
703
|
+
action.snapshot ? { ...state.current, ...action.snapshot } : state.current
|
|
704
|
+
)
|
|
705
|
+
};
|
|
706
|
+
case "loading":
|
|
707
|
+
return { ...state, loading: action.value };
|
|
708
|
+
case "flash/success":
|
|
709
|
+
return { ...state, showSuccess: true };
|
|
710
|
+
case "flash/error":
|
|
711
|
+
return { ...state, showError: true };
|
|
712
|
+
case "flash/clear":
|
|
713
|
+
return {
|
|
714
|
+
...state,
|
|
715
|
+
showSuccess: action.kind === "success" ? false : state.showSuccess,
|
|
716
|
+
showError: action.kind === "error" ? false : state.showError
|
|
717
|
+
};
|
|
718
|
+
default:
|
|
719
|
+
return state;
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
function isDirtyPrimitive(a, b) {
|
|
723
|
+
return a !== b;
|
|
724
|
+
}
|
|
725
|
+
function isDirtyArray(a, b) {
|
|
726
|
+
return JSON.stringify(a) !== JSON.stringify(b);
|
|
580
727
|
}
|
|
581
728
|
function useOidcSettings() {
|
|
582
729
|
const { get, put, post } = admin.useFetchClient();
|
|
583
|
-
const [
|
|
584
|
-
const [showSuccess, setSuccess] = react.useState(false);
|
|
585
|
-
const [showError, setError] = react.useState(false);
|
|
586
|
-
const [initialOidcRoles, setInitialOIDCRoles] = react.useState([]);
|
|
587
|
-
const [oidcRoles, setOIDCRoles] = react.useState([]);
|
|
588
|
-
const [roles, setRoles] = react.useState([]);
|
|
589
|
-
const [initialUseWhitelist, setInitialUseWhitelist] = react.useState(false);
|
|
590
|
-
const [useWhitelist, setUseWhitelist] = react.useState(false);
|
|
591
|
-
const [initialEnforceOIDC, setInitialEnforceOIDC] = react.useState(false);
|
|
592
|
-
const [enforceOIDC, setEnforceOIDC] = react.useState(false);
|
|
593
|
-
const [enforceOIDCConfig, setEnforceOIDCConfig] = react.useState(null);
|
|
594
|
-
const [initialUsers, setInitialUsers] = react.useState([]);
|
|
595
|
-
const [users, setUsers] = react.useState([]);
|
|
596
|
-
const [whitelistResponse, setWhitelistResponse] = react.useState({});
|
|
730
|
+
const [state, dispatch] = react.useReducer(reducer, initialState);
|
|
597
731
|
react.useEffect(() => {
|
|
598
732
|
get(`/strapi-plugin-oidc/oidc-roles`).then((response) => {
|
|
599
|
-
|
|
600
|
-
setInitialOIDCRoles(deepClone(response.data));
|
|
733
|
+
dispatch({ type: "hydrate/oidcRoles", oidcRoles: response.data });
|
|
601
734
|
});
|
|
602
735
|
get(`/admin/roles`).then((response) => {
|
|
603
|
-
|
|
736
|
+
dispatch({ type: "hydrate/roles", roles: response.data.data });
|
|
604
737
|
});
|
|
605
738
|
get("/strapi-plugin-oidc/whitelist").then((response) => {
|
|
606
739
|
const data = response.data;
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
740
|
+
dispatch({
|
|
741
|
+
type: "hydrate/whitelist",
|
|
742
|
+
snapshot: {
|
|
743
|
+
users: data.whitelistUsers,
|
|
744
|
+
useWhitelist: data.useWhitelist,
|
|
745
|
+
enforceOIDC: data.enforceOIDC
|
|
746
|
+
},
|
|
747
|
+
enforceOIDCConfig: data.enforceOIDCConfig ?? null,
|
|
748
|
+
auditLogEnabled: data.auditLogEnabled ?? true
|
|
749
|
+
});
|
|
615
750
|
});
|
|
616
751
|
}, [get]);
|
|
617
752
|
const onChangeRole = react.useCallback((values, oidcId) => {
|
|
618
|
-
|
|
619
|
-
(prev) => prev.map((role) => role.oauth_type === oidcId ? { ...role, role: values } : role)
|
|
620
|
-
);
|
|
753
|
+
dispatch({ type: "patch/oidcRole", oidcId, values });
|
|
621
754
|
}, []);
|
|
622
755
|
const onRegisterWhitelist = react.useCallback((email) => {
|
|
623
|
-
|
|
756
|
+
dispatch({ type: "user/add", email });
|
|
757
|
+
}, []);
|
|
758
|
+
const onDeleteWhitelist = react.useCallback((email) => {
|
|
759
|
+
dispatch({ type: "user/delete", email });
|
|
624
760
|
}, []);
|
|
625
|
-
const onDeleteWhitelist = react.useCallback(
|
|
626
|
-
(email) => {
|
|
627
|
-
setUsers((prev) => {
|
|
628
|
-
const updated = prev.filter((u) => u.email !== email);
|
|
629
|
-
if (useWhitelist && updated.length === 0) setEnforceOIDC(false);
|
|
630
|
-
return updated;
|
|
631
|
-
});
|
|
632
|
-
},
|
|
633
|
-
[useWhitelist]
|
|
634
|
-
);
|
|
635
761
|
const onDeleteAll = react.useCallback(() => {
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
}, [useWhitelist]);
|
|
762
|
+
dispatch({ type: "users/clear" });
|
|
763
|
+
}, []);
|
|
639
764
|
const onImport = react.useCallback(
|
|
640
765
|
async (emails) => {
|
|
641
766
|
const response = await post("/strapi-plugin-oidc/whitelist/import", {
|
|
642
767
|
users: emails.map((e) => ({ email: e }))
|
|
643
768
|
});
|
|
644
769
|
const refreshed = await get("/strapi-plugin-oidc/whitelist");
|
|
645
|
-
|
|
646
|
-
|
|
770
|
+
dispatch({ type: "users/replace", users: refreshed.data.whitelistUsers });
|
|
771
|
+
dispatch({ type: "commit" });
|
|
647
772
|
return response.data.importedCount;
|
|
648
773
|
},
|
|
649
774
|
[post, get]
|
|
@@ -651,74 +776,77 @@ function useOidcSettings() {
|
|
|
651
776
|
const onExport = react.useCallback(async () => {
|
|
652
777
|
const response = await get("/strapi-plugin-oidc/whitelist/export");
|
|
653
778
|
const data = response.data;
|
|
654
|
-
|
|
655
|
-
const blob = new Blob([JSON.stringify(data, null, 2)], { type: "application/json" });
|
|
656
|
-
const url = URL.createObjectURL(blob);
|
|
657
|
-
const a = document.createElement("a");
|
|
658
|
-
a.href = url;
|
|
659
|
-
a.download = `strapi-oidc-whitelist-${datetime}.json`;
|
|
660
|
-
a.click();
|
|
661
|
-
URL.revokeObjectURL(url);
|
|
779
|
+
downloadJson("strapi-oidc-whitelist", data);
|
|
662
780
|
}, [get]);
|
|
663
|
-
const onToggleWhitelist = react.useCallback(
|
|
664
|
-
(e)
|
|
665
|
-
|
|
666
|
-
setUseWhitelist(checked);
|
|
667
|
-
if (checked && users.length === 0) setEnforceOIDC(false);
|
|
668
|
-
},
|
|
669
|
-
[users.length]
|
|
670
|
-
);
|
|
781
|
+
const onToggleWhitelist = react.useCallback((e) => {
|
|
782
|
+
dispatch({ type: "toggle/useWhitelist", value: e.target.checked });
|
|
783
|
+
}, []);
|
|
671
784
|
const onToggleEnforce = react.useCallback((e) => {
|
|
672
|
-
|
|
785
|
+
dispatch({ type: "toggle/enforceOIDC", value: e.target.checked });
|
|
673
786
|
}, []);
|
|
674
|
-
const isDirty =
|
|
787
|
+
const isDirty = react.useMemo(
|
|
788
|
+
() => isDirtyPrimitive(state.current.useWhitelist, state.initial.useWhitelist) || isDirtyPrimitive(state.current.enforceOIDC, state.initial.enforceOIDC) || isDirtyArray(state.current.oidcRoles, state.initial.oidcRoles) || isDirtyArray(state.current.users, state.initial.users),
|
|
789
|
+
[state.current, state.initial]
|
|
790
|
+
);
|
|
675
791
|
const onSaveAll = react.useCallback(async () => {
|
|
676
|
-
|
|
792
|
+
dispatch({ type: "loading", value: true });
|
|
677
793
|
try {
|
|
678
|
-
await
|
|
679
|
-
roles
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
794
|
+
await Promise.all([
|
|
795
|
+
put("/strapi-plugin-oidc/oidc-roles", {
|
|
796
|
+
roles: state.current.oidcRoles.map((role) => ({
|
|
797
|
+
oauth_type: role.oauth_type,
|
|
798
|
+
role: role.role
|
|
799
|
+
}))
|
|
800
|
+
}),
|
|
801
|
+
put("/strapi-plugin-oidc/whitelist/sync", {
|
|
802
|
+
users: state.current.users.map((u) => ({ email: u.email }))
|
|
803
|
+
}),
|
|
804
|
+
put("/strapi-plugin-oidc/whitelist/settings", {
|
|
805
|
+
useWhitelist: state.current.useWhitelist,
|
|
806
|
+
enforceOIDC: state.current.enforceOIDC
|
|
807
|
+
})
|
|
808
|
+
]);
|
|
809
|
+
dispatch({ type: "commit" });
|
|
810
|
+
const getResponse = await get("/strapi-plugin-oidc/whitelist");
|
|
811
|
+
const data = getResponse.data;
|
|
812
|
+
dispatch({
|
|
813
|
+
type: "hydrate/whitelist",
|
|
814
|
+
snapshot: {
|
|
815
|
+
users: data.whitelistUsers,
|
|
816
|
+
useWhitelist: data.useWhitelist,
|
|
817
|
+
enforceOIDC: data.enforceOIDC
|
|
818
|
+
},
|
|
819
|
+
enforceOIDCConfig: data.enforceOIDCConfig ?? null,
|
|
820
|
+
auditLogEnabled: data.auditLogEnabled ?? true
|
|
693
821
|
});
|
|
694
|
-
|
|
695
|
-
setTimeout(() =>
|
|
822
|
+
dispatch({ type: "flash/success" });
|
|
823
|
+
setTimeout(() => dispatch({ type: "flash/clear", kind: "success" }), 3e3);
|
|
696
824
|
} catch (e) {
|
|
697
825
|
console.error(e);
|
|
698
|
-
|
|
699
|
-
setTimeout(() =>
|
|
826
|
+
dispatch({ type: "flash/error" });
|
|
827
|
+
setTimeout(() => dispatch({ type: "flash/clear", kind: "error" }), 3e3);
|
|
700
828
|
} finally {
|
|
701
|
-
|
|
829
|
+
dispatch({ type: "loading", value: false });
|
|
702
830
|
}
|
|
703
|
-
}, [put, get,
|
|
831
|
+
}, [put, get, state.current]);
|
|
704
832
|
return {
|
|
705
833
|
state: {
|
|
706
|
-
loading,
|
|
707
|
-
showSuccess,
|
|
708
|
-
showError,
|
|
709
|
-
oidcRoles,
|
|
710
|
-
roles,
|
|
711
|
-
useWhitelist,
|
|
712
|
-
enforceOIDC,
|
|
713
|
-
enforceOIDCConfig,
|
|
714
|
-
initialEnforceOIDC,
|
|
715
|
-
users,
|
|
834
|
+
loading: state.loading,
|
|
835
|
+
showSuccess: state.showSuccess,
|
|
836
|
+
showError: state.showError,
|
|
837
|
+
oidcRoles: state.current.oidcRoles,
|
|
838
|
+
roles: state.roles,
|
|
839
|
+
useWhitelist: state.current.useWhitelist,
|
|
840
|
+
enforceOIDC: state.current.enforceOIDC,
|
|
841
|
+
enforceOIDCConfig: state.enforceOIDCConfig,
|
|
842
|
+
initialEnforceOIDC: state.initial.enforceOIDC,
|
|
843
|
+
users: state.current.users,
|
|
716
844
|
isDirty,
|
|
717
|
-
auditLogEnabled:
|
|
845
|
+
auditLogEnabled: state.auditLogEnabled
|
|
718
846
|
},
|
|
719
847
|
actions: {
|
|
720
|
-
setSuccess,
|
|
721
|
-
setError,
|
|
848
|
+
setSuccess: (val) => dispatch({ type: val ? "flash/success" : "flash/clear", kind: "success" }),
|
|
849
|
+
setError: (val) => dispatch({ type: val ? "flash/error" : "flash/clear", kind: "error" }),
|
|
722
850
|
onChangeRole,
|
|
723
851
|
onRegisterWhitelist,
|
|
724
852
|
onDeleteWhitelist,
|
|
@@ -23,9 +23,6 @@ const pluginPkg = {
|
|
|
23
23
|
strapi
|
|
24
24
|
};
|
|
25
25
|
const pluginId = pluginPkg.name.replace(/^@strapi\/plugin-/i, "");
|
|
26
|
-
function getTranslation(id) {
|
|
27
|
-
return `${pluginId}.${id}`;
|
|
28
|
-
}
|
|
29
26
|
function Initializer({ setPlugin }) {
|
|
30
27
|
const ref = react.useRef();
|
|
31
28
|
ref.current = setPlugin;
|
|
@@ -149,7 +146,7 @@ const index = {
|
|
|
149
146
|
defaultMessage: "Configuration"
|
|
150
147
|
},
|
|
151
148
|
Component: async () => {
|
|
152
|
-
return await Promise.resolve().then(() => require("./index-
|
|
149
|
+
return await Promise.resolve().then(() => require("./index-DUFtPEHD.js"));
|
|
153
150
|
},
|
|
154
151
|
permissions: [{ action: "plugin::strapi-plugin-oidc.read", subject: null }]
|
|
155
152
|
}
|
|
@@ -262,7 +259,7 @@ const index = {
|
|
|
262
259
|
async registerTrads({ locales }) {
|
|
263
260
|
const transformKeys = (data) => Object.fromEntries(
|
|
264
261
|
Object.entries(data).map(([key, value]) => [
|
|
265
|
-
key.startsWith("global.") ? key :
|
|
262
|
+
key.startsWith("global.") ? key : `${pluginId}.${key}`,
|
|
266
263
|
value
|
|
267
264
|
])
|
|
268
265
|
);
|
package/dist/admin/index.js
CHANGED
package/dist/admin/index.mjs
CHANGED