@nibssplc/cams-sdk-react 0.0.1-beta.46 → 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/hooks/useCAMSMSALAuth.d.ts +1 -0
- package/dist/index.cjs.js +61 -3
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +62 -4
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -16821,15 +16821,72 @@ 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
|
-
|
|
16825
|
-
|
|
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"));
|
|
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.");
|
|
16828
16834
|
}
|
|
16829
|
-
if (
|
|
16835
|
+
if (authWindow_1.closed) {
|
|
16830
16836
|
camsSdk.Logger.error("Popup immediately closed by blocker");
|
|
16831
16837
|
throw new camsSdk.CAMSError(camsSdk.CAMSErrorType.POPUP_BLOCKED, "Popup blocked by browser. Please allow popups and try again.");
|
|
16832
16838
|
}
|
|
16839
|
+
var cleanup_1 = function () {
|
|
16840
|
+
window.removeEventListener("message", listener_1);
|
|
16841
|
+
clearInterval(checkClosed_1);
|
|
16842
|
+
};
|
|
16843
|
+
var cleanupAndClose_1 = function (error) {
|
|
16844
|
+
var _a;
|
|
16845
|
+
cleanup_1();
|
|
16846
|
+
try {
|
|
16847
|
+
if (authWindow_1 && !authWindow_1.closed) {
|
|
16848
|
+
authWindow_1.close();
|
|
16849
|
+
}
|
|
16850
|
+
}
|
|
16851
|
+
catch (_b) { }
|
|
16852
|
+
if (error) {
|
|
16853
|
+
setError(error);
|
|
16854
|
+
(_a = options.onAuthError) === null || _a === void 0 ? void 0 : _a.call(options, error);
|
|
16855
|
+
}
|
|
16856
|
+
};
|
|
16857
|
+
var listener_1 = function (event) {
|
|
16858
|
+
if (event.source !== authWindow_1)
|
|
16859
|
+
return;
|
|
16860
|
+
var expectedOrigin = options.messageOrigin || new URL(options.mfaUrl || "").origin;
|
|
16861
|
+
if (expectedOrigin && event.origin !== expectedOrigin)
|
|
16862
|
+
return;
|
|
16863
|
+
var tokenMsg = camsSdk.ProfileSchema.safeParse(event.data);
|
|
16864
|
+
if (tokenMsg.success) {
|
|
16865
|
+
localStorage.setItem(storageKey, JSON.stringify({
|
|
16866
|
+
isAuthenticated: true,
|
|
16867
|
+
accessToken: response.accessToken,
|
|
16868
|
+
idToken: response.idToken,
|
|
16869
|
+
appCode: "",
|
|
16870
|
+
}));
|
|
16871
|
+
cleanupAndClose_1();
|
|
16872
|
+
return;
|
|
16873
|
+
}
|
|
16874
|
+
var authFailureMsg = camsSdk.AuthFailureMessageSchema.safeParse(event.data);
|
|
16875
|
+
if (authFailureMsg.success) {
|
|
16876
|
+
cleanupAndClose_1(new camsSdk.CAMSError(camsSdk.CAMSErrorType.API_VALIDATION_ERROR, authFailureMsg.data.error));
|
|
16877
|
+
return;
|
|
16878
|
+
}
|
|
16879
|
+
var errorMsg = camsSdk.ErrorMessageSchema.safeParse(event.data);
|
|
16880
|
+
if (errorMsg.success) {
|
|
16881
|
+
cleanupAndClose_1(new camsSdk.CAMSError(camsSdk.CAMSErrorType.USER_CANCELLED, errorMsg.data.error));
|
|
16882
|
+
}
|
|
16883
|
+
};
|
|
16884
|
+
window.addEventListener("message", listener_1);
|
|
16885
|
+
var checkClosed_1 = setInterval(function () {
|
|
16886
|
+
if (authWindow_1.closed) {
|
|
16887
|
+
cleanupAndClose_1(new camsSdk.CAMSError(camsSdk.CAMSErrorType.USER_CANCELLED, "Authentication cancelled"));
|
|
16888
|
+
}
|
|
16889
|
+
}, 1000);
|
|
16833
16890
|
(_a = options.onAuthSuccess) === null || _a === void 0 ? void 0 : _a.call(options, response.accessToken);
|
|
16834
16891
|
}
|
|
16835
16892
|
})];
|
|
@@ -16870,6 +16927,7 @@ function useCAMSMSALAuth(options) {
|
|
|
16870
16927
|
setToken("");
|
|
16871
16928
|
setAccessToken("");
|
|
16872
16929
|
setIdToken("");
|
|
16930
|
+
setAppCode("");
|
|
16873
16931
|
setError(null);
|
|
16874
16932
|
if (typeof window !== "undefined") {
|
|
16875
16933
|
localStorage.removeItem(storageKey);
|