@nibssplc/cams-sdk-react 1.0.0-rc.81 → 1.0.0-rc.83
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/components/ADLoginModal.d.ts +1 -1
- package/dist/index.cjs.js +74 -58
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +75 -59
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -441,11 +441,9 @@ function useCAMSMSALAuth(options) {
|
|
|
441
441
|
var _d = React.useState(""), idToken = _d[0], setIdToken = _d[1];
|
|
442
442
|
var _e = React.useState(""), accessToken = _e[0], setAccessToken = _e[1];
|
|
443
443
|
var _f = React.useState(""), email = _f[0], setEmail = _f[1];
|
|
444
|
-
// const [mfaAuthenticator, setMfaAuthenticator] =
|
|
445
|
-
// useState<CAMSMFAAuthenticator | null>(null);
|
|
446
444
|
var _g = React.useState(false), requiresMFA = _g[0], setRequiresMFA = _g[1];
|
|
447
445
|
var isLoading = inProgress !== msalBrowser.InteractionStatus.None;
|
|
448
|
-
var isAuthenticated = !!account && !!accessToken
|
|
446
|
+
var isAuthenticated = !!account && !!accessToken;
|
|
449
447
|
var scopes = optScopes || ["openid", "profile", "email"];
|
|
450
448
|
var isTokenValid = function (token) {
|
|
451
449
|
try {
|
|
@@ -1663,12 +1661,13 @@ var credentialsSchema = z.z.object({
|
|
|
1663
1661
|
});
|
|
1664
1662
|
var ADLoginModal = function (_a) {
|
|
1665
1663
|
var open = _a.open, isLoading = _a.isLoading, setIsLoading = _a.setIsLoading, onOpenChange = _a.onOpenChange, onLogin = _a.onLogin;
|
|
1666
|
-
var _b = React.useState("
|
|
1667
|
-
var _c = React.useState(
|
|
1664
|
+
var _b = React.useState("Credentials"), step = _b[0], setStep = _b[1];
|
|
1665
|
+
var _c = React.useState(false), showPassword = _c[0], setShowPassword = _c[1];
|
|
1666
|
+
var _d = React.useState({
|
|
1668
1667
|
username: "",
|
|
1669
1668
|
password: "",
|
|
1670
|
-
}), credentials =
|
|
1671
|
-
var
|
|
1669
|
+
}), credentials = _d[0], setCredentials = _d[1];
|
|
1670
|
+
var _e = React.useState(""), MFACode = _e[0], setMFACode = _e[1];
|
|
1672
1671
|
var form = reactHookForm.useForm({
|
|
1673
1672
|
resolver: a$1(credentialsSchema),
|
|
1674
1673
|
defaultValues: { username: "", password: "" },
|
|
@@ -1676,7 +1675,7 @@ var ADLoginModal = function (_a) {
|
|
|
1676
1675
|
var handleCredentialsSubmit = function (values) { return __awaiter$1(void 0, void 0, void 0, function () {
|
|
1677
1676
|
return __generator$1(this, function (_a) {
|
|
1678
1677
|
setCredentials(values);
|
|
1679
|
-
setStep("
|
|
1678
|
+
setStep("MFA");
|
|
1680
1679
|
return [2 /*return*/];
|
|
1681
1680
|
});
|
|
1682
1681
|
}); };
|
|
@@ -1698,9 +1697,9 @@ var ADLoginModal = function (_a) {
|
|
|
1698
1697
|
case 2:
|
|
1699
1698
|
_a.sent();
|
|
1700
1699
|
onOpenChange(false);
|
|
1701
|
-
setStep("
|
|
1700
|
+
setStep("Credentials");
|
|
1702
1701
|
form.reset();
|
|
1703
|
-
|
|
1702
|
+
setMFACode("");
|
|
1704
1703
|
return [3 /*break*/, 5];
|
|
1705
1704
|
case 3:
|
|
1706
1705
|
error_1 = _a.sent();
|
|
@@ -1715,17 +1714,18 @@ var ADLoginModal = function (_a) {
|
|
|
1715
1714
|
}); };
|
|
1716
1715
|
var handleClose = function () {
|
|
1717
1716
|
onOpenChange(false);
|
|
1718
|
-
setStep("
|
|
1717
|
+
setStep("Credentials");
|
|
1719
1718
|
form.reset();
|
|
1720
|
-
|
|
1719
|
+
setMFACode("");
|
|
1720
|
+
setShowPassword(false);
|
|
1721
1721
|
};
|
|
1722
|
-
return (jsxRuntime.jsx(Dialog, { open: open, onOpenChange: handleClose, children: jsxRuntime.jsxs(DialogContent, { className: "min-w-[50vw] max-w-[70vw]", children: [jsxRuntime.jsx(DialogHeader, { children: jsxRuntime.jsxs("div", { className: "flex items-center gap-4", children: [jsxRuntime.jsx(lucideReact.KeyIcon, { className: "w-8 h-8 text-[#506f4a]" }), jsxRuntime.jsx(DialogTitle, { className: "text-xl", children: "Sign in with AD Credentials" })] }) }), step === "
|
|
1722
|
+
return (jsxRuntime.jsx(Dialog, { open: open, onOpenChange: handleClose, children: jsxRuntime.jsxs(DialogContent, { className: "min-w-[50vw] max-w-[70vw]", children: [jsxRuntime.jsx(DialogHeader, { children: jsxRuntime.jsxs("div", { className: "flex items-center gap-4", children: [jsxRuntime.jsx(lucideReact.KeyIcon, { className: "w-8 h-8 text-[#506f4a]" }), jsxRuntime.jsx(DialogTitle, { className: "text-xl", children: "Sign in with AD Credentials" })] }) }), step === "Credentials" ? (jsxRuntime.jsx(Form, __assign({}, form, { children: jsxRuntime.jsxs("form", { onSubmit: form.handleSubmit(handleCredentialsSubmit), className: "space-y-6", children: [jsxRuntime.jsx(FormField, { control: form.control, name: "username", render: function (_a) {
|
|
1723
1723
|
var field = _a.field;
|
|
1724
1724
|
return (jsxRuntime.jsxs(FormItem, { children: [jsxRuntime.jsx(FormLabel, { children: "Username" }), jsxRuntime.jsx(FormControl, { children: jsxRuntime.jsx(Input, __assign({ className: "h-12", placeholder: "Enter your username" }, field)) }), jsxRuntime.jsx(FormMessage, {})] }));
|
|
1725
1725
|
} }), jsxRuntime.jsx(FormField, { control: form.control, name: "password", render: function (_a) {
|
|
1726
1726
|
var field = _a.field;
|
|
1727
|
-
return (jsxRuntime.jsxs(FormItem, { children: [jsxRuntime.jsx(FormLabel, { children: "Password" }), jsxRuntime.jsx(FormControl, { children: jsxRuntime.jsx(Input, __assign({ className: "h-12", type: "password", placeholder: "Enter your password" }, field)) }), jsxRuntime.jsx(FormMessage, {})] }));
|
|
1728
|
-
} }), jsxRuntime.jsx(Button, { type: "submit", className: "py-3 w-full bg-[#506f4a] hover:bg-[#506f4a]/90", children: "Continue" })] }) }))) : (jsxRuntime.jsxs("div", { className: "space-y-4", children: [jsxRuntime.jsx(GenericOTPVerifier, { value:
|
|
1727
|
+
return (jsxRuntime.jsxs(FormItem, { children: [jsxRuntime.jsx(FormLabel, { children: "Password" }), jsxRuntime.jsx(FormControl, { children: jsxRuntime.jsxs("div", { className: "relative", children: [jsxRuntime.jsx(Input, __assign({ className: "h-12 pr-10", type: "password", placeholder: "Enter your password" }, field)), jsxRuntime.jsx("button", { type: "button", onClick: function () { return setShowPassword(!showPassword); }, className: "absolute right-3 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground", children: showPassword ? (jsxRuntime.jsx(lucideReact.EyeOff, { className: "w-5 h-5" })) : (jsxRuntime.jsx(lucideReact.Eye, { className: "w-5 h-5" })) })] }) }), jsxRuntime.jsx(FormMessage, {})] }));
|
|
1728
|
+
} }), jsxRuntime.jsx(Button, { type: "submit", className: "py-3 w-full bg-[#506f4a] hover:bg-[#506f4a]/90", children: "Continue" })] }) }))) : (jsxRuntime.jsxs("div", { className: "space-y-4", children: [jsxRuntime.jsx(GenericOTPVerifier, { value: MFACode, setValue: setMFACode, setLoading: setIsLoading, isDisabled: isLoading, onChangeOTP: handleMFASubmit, fieldName: "AuthenticatorCode" }), isLoading && (jsxRuntime.jsxs("div", { className: "flex items-center justify-center gap-2 text-sm text-muted-foreground", children: [jsxRuntime.jsx(lucideReact.Loader2, { className: "w-4 h-4 animate-spin" }), jsxRuntime.jsx("span", { children: "Verifying..." })] }))] }))] }) }));
|
|
1729
1729
|
};
|
|
1730
1730
|
|
|
1731
1731
|
var DefaultLoginPage = function (_a) {
|
|
@@ -1750,6 +1750,12 @@ var DefaultLoginPage = function (_a) {
|
|
|
1750
1750
|
console.log(data);
|
|
1751
1751
|
if (state && data && data.isValid) {
|
|
1752
1752
|
context.isAuthenticated = true;
|
|
1753
|
+
localStorage.setItem(context.storageKey, JSON.stringify({
|
|
1754
|
+
isAuthenticated: false,
|
|
1755
|
+
requiresMFA: false,
|
|
1756
|
+
accessToken: "Credentials",
|
|
1757
|
+
idToken: "Credentials",
|
|
1758
|
+
}));
|
|
1753
1759
|
context.requiresMFA = false;
|
|
1754
1760
|
context.setUserProfile({
|
|
1755
1761
|
state: "AUTH_SUCCESS",
|
|
@@ -1765,7 +1771,7 @@ var DefaultLoginPage = function (_a) {
|
|
|
1765
1771
|
});
|
|
1766
1772
|
}
|
|
1767
1773
|
else {
|
|
1768
|
-
sonner.toast.error("\u274C AD Login failed. ".concat((data === null || data === void 0 ? void 0 : data.message) ||
|
|
1774
|
+
sonner.toast.error("\u274C AD Login failed. ".concat((data === null || data === void 0 ? void 0 : data.message) || "Unknown error"));
|
|
1769
1775
|
}
|
|
1770
1776
|
return [2 /*return*/];
|
|
1771
1777
|
});
|
|
@@ -1797,7 +1803,12 @@ var DefaultLoginPage = function (_a) {
|
|
|
1797
1803
|
return __generator$1(this, function (_c) {
|
|
1798
1804
|
// Implement your AD login logic here
|
|
1799
1805
|
console.log("AD Login:", { username: username, MFACode: MFACode });
|
|
1800
|
-
handleSubmitCredentials(CredentialsAuthEndpoint, {
|
|
1806
|
+
handleSubmitCredentials(CredentialsAuthEndpoint, {
|
|
1807
|
+
username: username,
|
|
1808
|
+
password: password,
|
|
1809
|
+
MFACode: MFACode,
|
|
1810
|
+
appCode: context.appCode,
|
|
1811
|
+
});
|
|
1801
1812
|
return [2 /*return*/];
|
|
1802
1813
|
});
|
|
1803
1814
|
}); } })] }));
|
|
@@ -1816,15 +1827,14 @@ var MFAEndpointsSchema = z.object({
|
|
|
1816
1827
|
AuthChallengeVerify: z.url("MFA AuthChallengeVerify must be a valid URL"),
|
|
1817
1828
|
});
|
|
1818
1829
|
var MFAGate = function (_a) {
|
|
1819
|
-
var _b,
|
|
1820
|
-
var children = _a.children, _e = _a.fallback, fallback = _e === void 0 ? (jsxRuntime.jsx("div", { className: "h-screen flex items-center justify-center", children: jsxRuntime.jsx(LoadingSpinner, {}) })) : _e,
|
|
1830
|
+
var children = _a.children, _b = _a.fallback, fallback = _b === void 0 ? (jsxRuntime.jsx("div", { className: "h-screen flex items-center justify-center", children: jsxRuntime.jsx(LoadingSpinner, {}) })) : _b,
|
|
1821
1831
|
// loginComponent: LoginComponent = DefaultLoginPage,
|
|
1822
|
-
|
|
1832
|
+
_c = _a.usePassKey,
|
|
1823
1833
|
// loginComponent: LoginComponent = DefaultLoginPage,
|
|
1824
|
-
usePassKey =
|
|
1834
|
+
usePassKey = _c === void 0 ? false : _c, _d = _a.useADLogin, useADLogin = _d === void 0 ? false : _d, CredentialsAuthEndpoint = _a.CredentialsAuthEndpoint, PassKeysRegisterProps = _a.PassKeysRegisterProps, MFAEndpoints = _a.MFAEndpoints, requiresMFA = _a.requiresMFA, onAuthSuccess = _a.onAuthSuccess, onAuthError = _a.onAuthError;
|
|
1825
1835
|
var context = useCAMSContext();
|
|
1826
|
-
var
|
|
1827
|
-
var
|
|
1836
|
+
var _e = React.useState("Loading"), authState = _e[0], setAuthState = _e[1];
|
|
1837
|
+
var ValidatedMFAEndpoints = React.useMemo(function () {
|
|
1828
1838
|
var parsed = MFAEndpointsSchema.safeParse(MFAEndpoints);
|
|
1829
1839
|
if (!parsed.success) {
|
|
1830
1840
|
camsSdk.Logger.error("Invalid MFAEndpoint", parsed.error);
|
|
@@ -1832,6 +1842,9 @@ var MFAGate = function (_a) {
|
|
|
1832
1842
|
}
|
|
1833
1843
|
return parsed.data;
|
|
1834
1844
|
}, [MFAEndpoints]);
|
|
1845
|
+
// Extract the specific values we need from context for dependencies
|
|
1846
|
+
var contextRequiresMFA = "requiresMFA" in context ? context.requiresMFA : false;
|
|
1847
|
+
var contextAccessToken = "accessToken" in context ? context.accessToken : "";
|
|
1835
1848
|
var handleComplete = React.useCallback(function (success) {
|
|
1836
1849
|
var _a;
|
|
1837
1850
|
if (success && context.authMode === "MSAL") {
|
|
@@ -1867,61 +1880,64 @@ var MFAGate = function (_a) {
|
|
|
1867
1880
|
}
|
|
1868
1881
|
});
|
|
1869
1882
|
}); }, [context, onAuthError]);
|
|
1870
|
-
camsSdk.Logger.debug("User context:", {
|
|
1871
|
-
user: context.user,
|
|
1872
|
-
profile: (_b = context.user) === null || _b === void 0 ? void 0 : _b.profile,
|
|
1873
|
-
email: (_d = (_c = context.user) === null || _c === void 0 ? void 0 : _c.profile) === null || _d === void 0 ? void 0 : _d.email,
|
|
1874
|
-
});
|
|
1875
1883
|
React.useEffect(function () {
|
|
1884
|
+
console.log("Auth evaluation triggered:", {
|
|
1885
|
+
isLoading: context.isLoading,
|
|
1886
|
+
isAuthenticated: context.isAuthenticated,
|
|
1887
|
+
contextRequiresMFA: contextRequiresMFA,
|
|
1888
|
+
contextAccessToken: !!contextAccessToken,
|
|
1889
|
+
requiresMFA: requiresMFA,
|
|
1890
|
+
});
|
|
1876
1891
|
if (context.isLoading) {
|
|
1877
1892
|
setAuthState("Loading");
|
|
1878
1893
|
return;
|
|
1879
1894
|
}
|
|
1880
|
-
if (
|
|
1895
|
+
// Check if user has accessToken (MSAL authenticated)
|
|
1896
|
+
if (!contextAccessToken) {
|
|
1881
1897
|
setAuthState("Unauthenticated");
|
|
1882
1898
|
return;
|
|
1883
1899
|
}
|
|
1884
|
-
//
|
|
1885
|
-
var
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
}
|
|
1898
|
-
else {
|
|
1899
|
-
setAuthState("Authenticated");
|
|
1900
|
-
}
|
|
1901
|
-
}, 50);
|
|
1902
|
-
return function () { return clearTimeout(timer); };
|
|
1900
|
+
// User has accessToken, determine if MFA is required
|
|
1901
|
+
var shouldRequireMFA = requiresMFA !== null && requiresMFA !== void 0 ? requiresMFA : contextRequiresMFA;
|
|
1902
|
+
console.log("MFA decision:", {
|
|
1903
|
+
shouldRequireMFA: shouldRequireMFA,
|
|
1904
|
+
hasAccessToken: !!contextAccessToken,
|
|
1905
|
+
finalState: shouldRequireMFA ? "MFA_Required" : "Authenticated",
|
|
1906
|
+
});
|
|
1907
|
+
if (shouldRequireMFA) {
|
|
1908
|
+
setAuthState("MFA_Required");
|
|
1909
|
+
}
|
|
1910
|
+
else {
|
|
1911
|
+
setAuthState("Authenticated");
|
|
1912
|
+
}
|
|
1903
1913
|
}, [
|
|
1904
|
-
context.accessToken,
|
|
1905
1914
|
context.isLoading,
|
|
1906
1915
|
context.isAuthenticated,
|
|
1907
|
-
|
|
1916
|
+
contextRequiresMFA, // Now this will trigger re-evaluation when requiresMFA changes
|
|
1917
|
+
contextAccessToken, // And this when accessToken changes
|
|
1908
1918
|
requiresMFA,
|
|
1909
|
-
context,
|
|
1919
|
+
context.authMode,
|
|
1910
1920
|
]);
|
|
1911
|
-
//
|
|
1921
|
+
// Debug useEffect
|
|
1912
1922
|
React.useEffect(function () {
|
|
1913
1923
|
console.log("Current authState:", authState);
|
|
1914
1924
|
console.log("Context state:", {
|
|
1915
1925
|
isLoading: context.isLoading,
|
|
1916
1926
|
isAuthenticated: context.isAuthenticated,
|
|
1917
1927
|
authMode: context.authMode,
|
|
1918
|
-
requiresMFA:
|
|
1919
|
-
hasAccessToken:
|
|
1928
|
+
requiresMFA: contextRequiresMFA,
|
|
1929
|
+
hasAccessToken: !!contextAccessToken,
|
|
1920
1930
|
});
|
|
1921
|
-
}, [
|
|
1931
|
+
}, [
|
|
1932
|
+
authState,
|
|
1933
|
+
context.isLoading,
|
|
1934
|
+
context.isAuthenticated,
|
|
1935
|
+
contextRequiresMFA,
|
|
1936
|
+
contextAccessToken,
|
|
1937
|
+
]);
|
|
1922
1938
|
if (useADLogin && !CredentialsAuthEndpoint)
|
|
1923
1939
|
return jsxRuntime.jsx(ErrorFallback, { message: "Invalid AD Login Configuration." });
|
|
1924
|
-
if (!
|
|
1940
|
+
if (!ValidatedMFAEndpoints)
|
|
1925
1941
|
return jsxRuntime.jsx(ErrorFallback, { message: "Invalid MFA Configuration." });
|
|
1926
1942
|
if (context.authMode !== "MSAL")
|
|
1927
1943
|
return jsxRuntime.jsx(jsxRuntime.Fragment, { children: children });
|
|
@@ -1929,12 +1945,12 @@ var MFAGate = function (_a) {
|
|
|
1929
1945
|
case "Loading":
|
|
1930
1946
|
return fallback;
|
|
1931
1947
|
case "MFA_Required":
|
|
1932
|
-
return (jsxRuntime.jsx(MFAOptions, { MFAEndpoints:
|
|
1948
|
+
return (jsxRuntime.jsx(MFAOptions, { MFAEndpoints: ValidatedMFAEndpoints, usePassKey: usePassKey, onComplete: handleComplete, onAuthFailed: handleAuthFailed }));
|
|
1933
1949
|
case "Authenticated":
|
|
1934
1950
|
return jsxRuntime.jsx(jsxRuntime.Fragment, { children: children });
|
|
1935
1951
|
case "Unauthenticated":
|
|
1936
1952
|
default:
|
|
1937
|
-
return (jsxRuntime.jsx(DefaultLoginPage, { usePassKey: usePassKey, useADLogin: useADLogin, MFAEndpoints:
|
|
1953
|
+
return (jsxRuntime.jsx(DefaultLoginPage, { usePassKey: usePassKey, useADLogin: useADLogin, MFAEndpoints: ValidatedMFAEndpoints, PassKeysRegisterProps: PassKeysRegisterProps, CredentialsAuthEndpoint: CredentialsAuthEndpoint }));
|
|
1938
1954
|
}
|
|
1939
1955
|
};
|
|
1940
1956
|
|