@nibssplc/cams-sdk-react 0.0.1-beta.47 → 0.0.1-beta.49
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/hooks/useCAMSMSALAuth.d.ts +2 -0
- package/dist/index.cjs.js +16 -5
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +16 -5
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -16802,7 +16802,13 @@ function useCAMSMSALAuth(options) {
|
|
|
16802
16802
|
// Center the popup window
|
|
16803
16803
|
var left = (window.screen.width - 500) / 2;
|
|
16804
16804
|
var top_1 = (window.screen.height - 600) / 2;
|
|
16805
|
-
|
|
16805
|
+
Logger$1.info("source", {
|
|
16806
|
+
origin: window.location.origin,
|
|
16807
|
+
mfaUrl: options.mfaUrl,
|
|
16808
|
+
});
|
|
16809
|
+
var currentOrigin = window.location.origin;
|
|
16810
|
+
var mfaUrlWithOrigin = "".concat(options.mfaUrl, "?origin=").concat(encodeURIComponent(currentOrigin));
|
|
16811
|
+
var authWindow_1 = window.open(mfaUrlWithOrigin, "_blank", "width=500,height=600,left=".concat(left, ",top=").concat(top_1, ",scrollbars=yes,resizable=yes"));
|
|
16806
16812
|
if (!authWindow_1) {
|
|
16807
16813
|
Logger$1.error("Popup window blocked");
|
|
16808
16814
|
throw new CAMSError(CAMSErrorType.POPUP_BLOCKED, "Popup blocked by browser. Please allow popups and try again.");
|
|
@@ -16812,7 +16818,7 @@ function useCAMSMSALAuth(options) {
|
|
|
16812
16818
|
throw new CAMSError(CAMSErrorType.POPUP_BLOCKED, "Popup blocked by browser. Please allow popups and try again.");
|
|
16813
16819
|
}
|
|
16814
16820
|
var cleanup_1 = function () {
|
|
16815
|
-
window.removeEventListener(
|
|
16821
|
+
window.removeEventListener("message", listener_1);
|
|
16816
16822
|
clearInterval(checkClosed_1);
|
|
16817
16823
|
};
|
|
16818
16824
|
var cleanupAndClose_1 = function (error) {
|
|
@@ -16832,13 +16838,18 @@ function useCAMSMSALAuth(options) {
|
|
|
16832
16838
|
var listener_1 = function (event) {
|
|
16833
16839
|
if (event.source !== authWindow_1)
|
|
16834
16840
|
return;
|
|
16841
|
+
var allowedOrigins = options.allowedOrigins || [
|
|
16842
|
+
options.messageOrigin || new URL(options.mfaUrl || "").origin
|
|
16843
|
+
].filter(Boolean);
|
|
16844
|
+
if (allowedOrigins.length > 0 && !allowedOrigins.includes(event.origin))
|
|
16845
|
+
return;
|
|
16835
16846
|
var tokenMsg = ProfileSchema.safeParse(event.data);
|
|
16836
16847
|
if (tokenMsg.success) {
|
|
16837
16848
|
localStorage.setItem(storageKey, JSON.stringify({
|
|
16838
16849
|
isAuthenticated: true,
|
|
16839
16850
|
accessToken: response.accessToken,
|
|
16840
16851
|
idToken: response.idToken,
|
|
16841
|
-
appCode:
|
|
16852
|
+
appCode: "",
|
|
16842
16853
|
}));
|
|
16843
16854
|
cleanupAndClose_1();
|
|
16844
16855
|
return;
|
|
@@ -16853,10 +16864,10 @@ function useCAMSMSALAuth(options) {
|
|
|
16853
16864
|
cleanupAndClose_1(new CAMSError(CAMSErrorType.USER_CANCELLED, errorMsg.data.error));
|
|
16854
16865
|
}
|
|
16855
16866
|
};
|
|
16856
|
-
window.addEventListener(
|
|
16867
|
+
window.addEventListener("message", listener_1);
|
|
16857
16868
|
var checkClosed_1 = setInterval(function () {
|
|
16858
16869
|
if (authWindow_1.closed) {
|
|
16859
|
-
cleanupAndClose_1(new CAMSError(CAMSErrorType.USER_CANCELLED,
|
|
16870
|
+
cleanupAndClose_1(new CAMSError(CAMSErrorType.USER_CANCELLED, "Authentication cancelled"));
|
|
16860
16871
|
}
|
|
16861
16872
|
}, 1000);
|
|
16862
16873
|
(_a = options.onAuthSuccess) === null || _a === void 0 ? void 0 : _a.call(options, response.accessToken);
|