@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.
@@ -6,6 +6,8 @@ export interface UseCAMSMSALAuthOptions {
6
6
  scopes?: string[];
7
7
  mfaUrl?: string;
8
8
  prompt?: string;
9
+ messageOrigin?: string;
10
+ allowedOrigins?: string[];
9
11
  }
10
12
  export interface UseCAMSMSALAuthReturn {
11
13
  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,18 @@ function useCAMSMSALAuth(options) {
16851
16857
  var listener_1 = function (event) {
16852
16858
  if (event.source !== authWindow_1)
16853
16859
  return;
16860
+ var allowedOrigins = options.allowedOrigins || [
16861
+ options.messageOrigin || new URL(options.mfaUrl || "").origin
16862
+ ].filter(Boolean);
16863
+ if (allowedOrigins.length > 0 && !allowedOrigins.includes(event.origin))
16864
+ return;
16854
16865
  var tokenMsg = camsSdk.ProfileSchema.safeParse(event.data);
16855
16866
  if (tokenMsg.success) {
16856
16867
  localStorage.setItem(storageKey, JSON.stringify({
16857
16868
  isAuthenticated: true,
16858
16869
  accessToken: response.accessToken,
16859
16870
  idToken: response.idToken,
16860
- appCode: ''
16871
+ appCode: "",
16861
16872
  }));
16862
16873
  cleanupAndClose_1();
16863
16874
  return;
@@ -16872,10 +16883,10 @@ function useCAMSMSALAuth(options) {
16872
16883
  cleanupAndClose_1(new camsSdk.CAMSError(camsSdk.CAMSErrorType.USER_CANCELLED, errorMsg.data.error));
16873
16884
  }
16874
16885
  };
16875
- window.addEventListener('message', listener_1);
16886
+ window.addEventListener("message", listener_1);
16876
16887
  var checkClosed_1 = setInterval(function () {
16877
16888
  if (authWindow_1.closed) {
16878
- cleanupAndClose_1(new camsSdk.CAMSError(camsSdk.CAMSErrorType.USER_CANCELLED, 'Authentication cancelled'));
16889
+ cleanupAndClose_1(new camsSdk.CAMSError(camsSdk.CAMSErrorType.USER_CANCELLED, "Authentication cancelled"));
16879
16890
  }
16880
16891
  }, 1000);
16881
16892
  (_a = options.onAuthSuccess) === null || _a === void 0 ? void 0 : _a.call(options, response.accessToken);