@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.
@@ -6,6 +6,7 @@ export interface UseCAMSMSALAuthOptions {
6
6
  scopes?: string[];
7
7
  mfaUrl?: string;
8
8
  prompt?: string;
9
+ messageOrigin?: string;
9
10
  }
10
11
  export interface UseCAMSMSALAuthReturn {
11
12
  login: () => Promise<void>;
package/dist/index.cjs.js CHANGED
@@ -16821,7 +16821,13 @@ function useCAMSMSALAuth(options) {
16821
16821
  // Center the popup window
16822
16822
  var left = (window.screen.width - 500) / 2;
16823
16823
  var top_1 = (window.screen.height - 600) / 2;
16824
- var authWindow_1 = window.open(options.mfaUrl, "_blank", "width=500,height=600,left=".concat(left, ",top=").concat(top_1, ",scrollbars=yes,resizable=yes"));
16824
+ camsSdk.Logger.info("source", {
16825
+ origin: window.location.origin,
16826
+ mfaUrl: options.mfaUrl,
16827
+ });
16828
+ var currentOrigin = window.location.origin;
16829
+ var mfaUrlWithOrigin = "".concat(options.mfaUrl, "?origin=").concat(encodeURIComponent(currentOrigin));
16830
+ var authWindow_1 = window.open(mfaUrlWithOrigin, "_blank", "width=500,height=600,left=".concat(left, ",top=").concat(top_1, ",scrollbars=yes,resizable=yes"));
16825
16831
  if (!authWindow_1) {
16826
16832
  camsSdk.Logger.error("Popup window blocked");
16827
16833
  throw new camsSdk.CAMSError(camsSdk.CAMSErrorType.POPUP_BLOCKED, "Popup blocked by browser. Please allow popups and try again.");
@@ -16831,7 +16837,7 @@ function useCAMSMSALAuth(options) {
16831
16837
  throw new camsSdk.CAMSError(camsSdk.CAMSErrorType.POPUP_BLOCKED, "Popup blocked by browser. Please allow popups and try again.");
16832
16838
  }
16833
16839
  var cleanup_1 = function () {
16834
- window.removeEventListener('message', listener_1);
16840
+ window.removeEventListener("message", listener_1);
16835
16841
  clearInterval(checkClosed_1);
16836
16842
  };
16837
16843
  var cleanupAndClose_1 = function (error) {
@@ -16851,13 +16857,16 @@ function useCAMSMSALAuth(options) {
16851
16857
  var listener_1 = function (event) {
16852
16858
  if (event.source !== authWindow_1)
16853
16859
  return;
16860
+ var expectedOrigin = options.messageOrigin || new URL(options.mfaUrl || "").origin;
16861
+ if (expectedOrigin && event.origin !== expectedOrigin)
16862
+ return;
16854
16863
  var tokenMsg = camsSdk.ProfileSchema.safeParse(event.data);
16855
16864
  if (tokenMsg.success) {
16856
16865
  localStorage.setItem(storageKey, JSON.stringify({
16857
16866
  isAuthenticated: true,
16858
16867
  accessToken: response.accessToken,
16859
16868
  idToken: response.idToken,
16860
- appCode: ''
16869
+ appCode: "",
16861
16870
  }));
16862
16871
  cleanupAndClose_1();
16863
16872
  return;
@@ -16872,10 +16881,10 @@ function useCAMSMSALAuth(options) {
16872
16881
  cleanupAndClose_1(new camsSdk.CAMSError(camsSdk.CAMSErrorType.USER_CANCELLED, errorMsg.data.error));
16873
16882
  }
16874
16883
  };
16875
- window.addEventListener('message', listener_1);
16884
+ window.addEventListener("message", listener_1);
16876
16885
  var checkClosed_1 = setInterval(function () {
16877
16886
  if (authWindow_1.closed) {
16878
- cleanupAndClose_1(new camsSdk.CAMSError(camsSdk.CAMSErrorType.USER_CANCELLED, 'Authentication cancelled'));
16887
+ cleanupAndClose_1(new camsSdk.CAMSError(camsSdk.CAMSErrorType.USER_CANCELLED, "Authentication cancelled"));
16879
16888
  }
16880
16889
  }, 1000);
16881
16890
  (_a = options.onAuthSuccess) === null || _a === void 0 ? void 0 : _a.call(options, response.accessToken);