@nibssplc/cams-sdk-react 0.0.1-beta.47 → 0.0.1-beta.48

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/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
- var authWindow_1 = window.open(options.mfaUrl, "_blank", "width=500,height=600,left=".concat(left, ",top=").concat(top_1, ",scrollbars=yes,resizable=yes"));
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('message', listener_1);
16821
+ window.removeEventListener("message", listener_1);
16816
16822
  clearInterval(checkClosed_1);
16817
16823
  };
16818
16824
  var cleanupAndClose_1 = function (error) {
@@ -16832,13 +16838,16 @@ function useCAMSMSALAuth(options) {
16832
16838
  var listener_1 = function (event) {
16833
16839
  if (event.source !== authWindow_1)
16834
16840
  return;
16841
+ var expectedOrigin = options.messageOrigin || new URL(options.mfaUrl || "").origin;
16842
+ if (expectedOrigin && event.origin !== expectedOrigin)
16843
+ return;
16835
16844
  var tokenMsg = ProfileSchema.safeParse(event.data);
16836
16845
  if (tokenMsg.success) {
16837
16846
  localStorage.setItem(storageKey, JSON.stringify({
16838
16847
  isAuthenticated: true,
16839
16848
  accessToken: response.accessToken,
16840
16849
  idToken: response.idToken,
16841
- appCode: ''
16850
+ appCode: "",
16842
16851
  }));
16843
16852
  cleanupAndClose_1();
16844
16853
  return;
@@ -16853,10 +16862,10 @@ function useCAMSMSALAuth(options) {
16853
16862
  cleanupAndClose_1(new CAMSError(CAMSErrorType.USER_CANCELLED, errorMsg.data.error));
16854
16863
  }
16855
16864
  };
16856
- window.addEventListener('message', listener_1);
16865
+ window.addEventListener("message", listener_1);
16857
16866
  var checkClosed_1 = setInterval(function () {
16858
16867
  if (authWindow_1.closed) {
16859
- cleanupAndClose_1(new CAMSError(CAMSErrorType.USER_CANCELLED, 'Authentication cancelled'));
16868
+ cleanupAndClose_1(new CAMSError(CAMSErrorType.USER_CANCELLED, "Authentication cancelled"));
16860
16869
  }
16861
16870
  }, 1000);
16862
16871
  (_a = options.onAuthSuccess) === null || _a === void 0 ? void 0 : _a.call(options, response.accessToken);