@nibssplc/cams-sdk-react 1.0.0-rc.87 → 1.0.0-rc.89
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.cjs.js +18 -67
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +18 -67
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -479,14 +479,10 @@ function useCAMSMSALAuth(options) {
|
|
|
479
479
|
}
|
|
480
480
|
catch (_b) { }
|
|
481
481
|
}
|
|
482
|
-
else if (account) {
|
|
483
|
-
// Storage cleared but MSAL account exists - clear MSAL state
|
|
484
|
-
instance.logoutRedirect().catch(function () { });
|
|
485
|
-
}
|
|
486
482
|
}
|
|
487
483
|
}, [accessToken, account, instance, options.storageKey]);
|
|
488
484
|
var login = React.useCallback(function () { return __awaiter$1(_this, void 0, void 0, function () {
|
|
489
|
-
var response,
|
|
485
|
+
var response, authenticator, userConfig, camsError, err_1, camsError_1, camsError;
|
|
490
486
|
var _a;
|
|
491
487
|
return __generator$1(this, function (_b) {
|
|
492
488
|
switch (_b.label) {
|
|
@@ -505,33 +501,28 @@ function useCAMSMSALAuth(options) {
|
|
|
505
501
|
})];
|
|
506
502
|
case 2:
|
|
507
503
|
response = _b.sent();
|
|
508
|
-
mfaConfig = {
|
|
509
|
-
accessToken: response.accessToken,
|
|
510
|
-
idToken: response.idToken,
|
|
511
|
-
provider: "MSAL",
|
|
512
|
-
APIAuthEndpoint: ValidateUserEndpoint,
|
|
513
|
-
};
|
|
514
504
|
authenticator = new camsSdk.CAMSMFAAuthenticator();
|
|
515
505
|
setIsFetchingMFAConfig(true);
|
|
516
|
-
return [4 /*yield*/, authenticator.GetUserMFAConfig(
|
|
506
|
+
return [4 /*yield*/, authenticator.GetUserMFAConfig({
|
|
507
|
+
accessToken: response.accessToken,
|
|
508
|
+
idToken: response.idToken,
|
|
509
|
+
provider: "MSAL",
|
|
510
|
+
APIAuthEndpoint: ValidateUserEndpoint,
|
|
511
|
+
})];
|
|
517
512
|
case 3:
|
|
518
513
|
userConfig = _b.sent();
|
|
519
514
|
setIsFetchingMFAConfig(false);
|
|
520
|
-
|
|
521
|
-
mfaConfig: mfaConfig,
|
|
515
|
+
camsSdk.Logger.info("CAMS MFA Authenticator initialized. MSAL User Auth is Completed...", {
|
|
522
516
|
userConfig: userConfig,
|
|
517
|
+
storageKey: storageKey,
|
|
518
|
+
email: userConfig.userInfo.email,
|
|
523
519
|
});
|
|
524
|
-
camsSdk.Logger.info("MSAL User Auth is Completed");
|
|
525
520
|
// Don't persist as authenticated until MFA is complete
|
|
526
521
|
if (userConfig.isValid && userConfig.userInfo.email) {
|
|
527
|
-
camsSdk.Logger.info("MSAL User Auth is Completed...", {
|
|
528
|
-
storageKey: storageKey,
|
|
529
|
-
email: userConfig.userInfo.email,
|
|
530
|
-
});
|
|
531
522
|
setAccessToken(response.accessToken);
|
|
532
523
|
setIdToken(response.idToken);
|
|
533
524
|
localStorage.setItem(storageKey, JSON.stringify({
|
|
534
|
-
isAuthenticated:
|
|
525
|
+
isAuthenticated: !userConfig.userInfo.isMFAEnabled,
|
|
535
526
|
requiresMFA: userConfig.userInfo.isMFAEnabled,
|
|
536
527
|
accessToken: response.accessToken,
|
|
537
528
|
idToken: response.idToken,
|
|
@@ -636,17 +627,17 @@ function useCAMSMSALAuth(options) {
|
|
|
636
627
|
case 0:
|
|
637
628
|
_a.trys.push([0, 2, , 3]);
|
|
638
629
|
camsSdk.Logger.info("Logging User Out");
|
|
639
|
-
return [4 /*yield*/, instance.logoutRedirect()];
|
|
640
|
-
case 1:
|
|
641
|
-
_a.sent();
|
|
642
630
|
setAccessToken("");
|
|
643
631
|
setIdToken("");
|
|
644
632
|
setError(null);
|
|
645
633
|
setRequiresMFA(false);
|
|
646
634
|
if (typeof window !== "undefined") {
|
|
647
635
|
localStorage.removeItem(storageKey);
|
|
648
|
-
|
|
636
|
+
deleteCookie(storageKey + "-PROFILE");
|
|
649
637
|
}
|
|
638
|
+
return [4 /*yield*/, instance.logoutRedirect()];
|
|
639
|
+
case 1:
|
|
640
|
+
_a.sent();
|
|
650
641
|
return [3 /*break*/, 3];
|
|
651
642
|
case 2:
|
|
652
643
|
err_2 = _a.sent();
|
|
@@ -1563,7 +1554,7 @@ var MFAOptions = function (_a) {
|
|
|
1563
1554
|
var _f = React.useState(false), showSuccessAnimation = _f[0], setShowSuccessAnimation = _f[1];
|
|
1564
1555
|
var _g = React.useState(null), authType = _g[0], setAuthType = _g[1];
|
|
1565
1556
|
var context = useCAMSContext();
|
|
1566
|
-
var _h = context.authMode === "MSAL" && "
|
|
1557
|
+
var _h = context.authMode === "MSAL" && "EmailOTP" in context
|
|
1567
1558
|
? context
|
|
1568
1559
|
: { completeMFA: null, logout: function () { return __awaiter$1(void 0, void 0, void 0, function () { return __generator$1(this, function (_a) {
|
|
1569
1560
|
return [2 /*return*/];
|
|
@@ -1862,8 +1853,6 @@ var MFAGate = function (_a) {
|
|
|
1862
1853
|
(_a = context.onAuthSuccess) === null || _a === void 0 ? void 0 : _a.call(context, tokens);
|
|
1863
1854
|
}
|
|
1864
1855
|
}
|
|
1865
|
-
// Force state update after MFA completion
|
|
1866
|
-
setAuthState("Authenticated");
|
|
1867
1856
|
}
|
|
1868
1857
|
else if (!success) {
|
|
1869
1858
|
camsSdk.Logger.error("MFA authentication failed", { context: context || null });
|
|
@@ -1888,59 +1877,21 @@ var MFAGate = function (_a) {
|
|
|
1888
1877
|
});
|
|
1889
1878
|
}); }, [context, onAuthError]);
|
|
1890
1879
|
React.useEffect(function () {
|
|
1891
|
-
console.log("Auth evaluation triggered:", {
|
|
1892
|
-
isLoading: context.isLoading,
|
|
1893
|
-
isAuthenticated: context.isAuthenticated,
|
|
1894
|
-
contextRequiresMFA: contextRequiresMFA,
|
|
1895
|
-
contextAccessToken: !!contextAccessToken,
|
|
1896
|
-
requiresMFA: requiresMFA,
|
|
1897
|
-
});
|
|
1898
1880
|
if (context.isLoading) {
|
|
1899
1881
|
setAuthState("Loading");
|
|
1900
1882
|
return;
|
|
1901
1883
|
}
|
|
1902
|
-
// Check if user has accessToken (MSAL authenticated)
|
|
1903
1884
|
if (!contextAccessToken) {
|
|
1904
1885
|
setAuthState("Unauthenticated");
|
|
1905
1886
|
return;
|
|
1906
1887
|
}
|
|
1907
|
-
// User has accessToken, determine if MFA is required
|
|
1908
1888
|
var shouldRequireMFA = requiresMFA !== null && requiresMFA !== void 0 ? requiresMFA : contextRequiresMFA;
|
|
1909
|
-
|
|
1910
|
-
shouldRequireMFA: shouldRequireMFA,
|
|
1911
|
-
hasAccessToken: !!contextAccessToken,
|
|
1912
|
-
finalState: shouldRequireMFA ? "MFA_Required" : "Authenticated",
|
|
1913
|
-
});
|
|
1914
|
-
if (shouldRequireMFA) {
|
|
1915
|
-
setAuthState("MFA_Required");
|
|
1916
|
-
}
|
|
1917
|
-
else {
|
|
1918
|
-
setAuthState("Authenticated");
|
|
1919
|
-
}
|
|
1889
|
+
setAuthState(shouldRequireMFA ? "MFA_Required" : "Authenticated");
|
|
1920
1890
|
}, [
|
|
1921
1891
|
context.isLoading,
|
|
1922
|
-
context.isAuthenticated,
|
|
1923
|
-
contextRequiresMFA, // Now this will trigger re-evaluation when requiresMFA changes
|
|
1924
|
-
contextAccessToken, // And this when accessToken changes
|
|
1925
|
-
requiresMFA,
|
|
1926
|
-
context.authMode,
|
|
1927
|
-
]);
|
|
1928
|
-
// Debug useEffect
|
|
1929
|
-
React.useEffect(function () {
|
|
1930
|
-
console.log("Current authState:", authState);
|
|
1931
|
-
console.log("Context state:", {
|
|
1932
|
-
isLoading: context.isLoading,
|
|
1933
|
-
isAuthenticated: context.isAuthenticated,
|
|
1934
|
-
authMode: context.authMode,
|
|
1935
|
-
requiresMFA: contextRequiresMFA,
|
|
1936
|
-
hasAccessToken: !!contextAccessToken,
|
|
1937
|
-
});
|
|
1938
|
-
}, [
|
|
1939
|
-
authState,
|
|
1940
|
-
context.isLoading,
|
|
1941
|
-
context.isAuthenticated,
|
|
1942
1892
|
contextRequiresMFA,
|
|
1943
1893
|
contextAccessToken,
|
|
1894
|
+
requiresMFA,
|
|
1944
1895
|
]);
|
|
1945
1896
|
if (useADLogin && !CredentialsAuthEndpoint)
|
|
1946
1897
|
return jsxRuntime.jsx(ErrorFallback, { message: "Invalid AD Login Configuration." });
|