@nibssplc/cams-sdk-react 1.0.0-rc.82 → 1.0.0-rc.84
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 +44 -28
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +45 -29
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -8,7 +8,7 @@ import { toast } from 'sonner';
|
|
|
8
8
|
import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
|
|
9
9
|
import z$1, { z } from 'zod';
|
|
10
10
|
import { OTPInput, OTPInputContext, REGEXP_ONLY_DIGITS } from 'input-otp';
|
|
11
|
-
import { RectangleEllipsis, XIcon, CheckCircle, Shield, KeyIcon, ShieldCheck, ShieldClose, Loader2 } from 'lucide-react';
|
|
11
|
+
import { RectangleEllipsis, XIcon, CheckCircle, Shield, KeyIcon, ShieldCheck, ShieldClose, EyeOff, Eye, Loader2 } from 'lucide-react';
|
|
12
12
|
import { appendErrors, FormProvider, Controller, useFormContext, useFormState, useForm } from 'react-hook-form';
|
|
13
13
|
import { validateFieldsNatively, toNestErrors } from '@hookform/resolvers';
|
|
14
14
|
import { clsx } from 'clsx';
|
|
@@ -420,11 +420,10 @@ function useCAMSMSALAuth(options) {
|
|
|
420
420
|
var _d = useState(""), idToken = _d[0], setIdToken = _d[1];
|
|
421
421
|
var _e = useState(""), accessToken = _e[0], setAccessToken = _e[1];
|
|
422
422
|
var _f = useState(""), email = _f[0], setEmail = _f[1];
|
|
423
|
-
// const [mfaAuthenticator, setMfaAuthenticator] =
|
|
424
|
-
// useState<CAMSMFAAuthenticator | null>(null);
|
|
425
423
|
var _g = useState(false), requiresMFA = _g[0], setRequiresMFA = _g[1];
|
|
426
|
-
var
|
|
427
|
-
var
|
|
424
|
+
var _h = useState(false), isFetchingMFAConfig = _h[0], setIsFetchingMFAConfig = _h[1];
|
|
425
|
+
var isLoading = inProgress !== InteractionStatus.None || isFetchingMFAConfig;
|
|
426
|
+
var isAuthenticated = !!account && !!accessToken;
|
|
428
427
|
var scopes = optScopes || ["openid", "profile", "email"];
|
|
429
428
|
var isTokenValid = function (token) {
|
|
430
429
|
try {
|
|
@@ -492,9 +491,11 @@ function useCAMSMSALAuth(options) {
|
|
|
492
491
|
APIAuthEndpoint: ValidateUserEndpoint,
|
|
493
492
|
};
|
|
494
493
|
authenticator = new CAMSMFAAuthenticator();
|
|
494
|
+
setIsFetchingMFAConfig(true);
|
|
495
495
|
return [4 /*yield*/, authenticator.GetUserMFAConfig(mfaConfig)];
|
|
496
496
|
case 3:
|
|
497
497
|
userConfig = _b.sent();
|
|
498
|
+
setIsFetchingMFAConfig(false);
|
|
498
499
|
console.log("CAMS MFA Authenticator initialized:", {
|
|
499
500
|
mfaConfig: mfaConfig,
|
|
500
501
|
userConfig: userConfig,
|
|
@@ -521,6 +522,7 @@ function useCAMSMSALAuth(options) {
|
|
|
521
522
|
camsError = new CAMSError(CAMSErrorType.API_VALIDATION_ERROR, "Login failed: " + userConfig.message);
|
|
522
523
|
toast.error("Login failed");
|
|
523
524
|
setError(camsError);
|
|
525
|
+
setIsFetchingMFAConfig(false);
|
|
524
526
|
}
|
|
525
527
|
return [3 /*break*/, 5];
|
|
526
528
|
case 4:
|
|
@@ -545,6 +547,7 @@ function useCAMSMSALAuth(options) {
|
|
|
545
547
|
}
|
|
546
548
|
camsError = new CAMSError(CAMSErrorType.API_VALIDATION_ERROR, "Login failed: " + err_1.message || err_1);
|
|
547
549
|
setError(camsError);
|
|
550
|
+
setIsFetchingMFAConfig(false);
|
|
548
551
|
return [3 /*break*/, 5];
|
|
549
552
|
case 5: return [2 /*return*/];
|
|
550
553
|
}
|
|
@@ -1642,12 +1645,13 @@ var credentialsSchema = z.object({
|
|
|
1642
1645
|
});
|
|
1643
1646
|
var ADLoginModal = function (_a) {
|
|
1644
1647
|
var open = _a.open, isLoading = _a.isLoading, setIsLoading = _a.setIsLoading, onOpenChange = _a.onOpenChange, onLogin = _a.onLogin;
|
|
1645
|
-
var _b = useState("
|
|
1646
|
-
var _c = useState(
|
|
1648
|
+
var _b = useState("Credentials"), step = _b[0], setStep = _b[1];
|
|
1649
|
+
var _c = useState(false), showPassword = _c[0], setShowPassword = _c[1];
|
|
1650
|
+
var _d = useState({
|
|
1647
1651
|
username: "",
|
|
1648
1652
|
password: "",
|
|
1649
|
-
}), credentials =
|
|
1650
|
-
var
|
|
1653
|
+
}), credentials = _d[0], setCredentials = _d[1];
|
|
1654
|
+
var _e = useState(""), MFACode = _e[0], setMFACode = _e[1];
|
|
1651
1655
|
var form = useForm({
|
|
1652
1656
|
resolver: a$1(credentialsSchema),
|
|
1653
1657
|
defaultValues: { username: "", password: "" },
|
|
@@ -1655,7 +1659,7 @@ var ADLoginModal = function (_a) {
|
|
|
1655
1659
|
var handleCredentialsSubmit = function (values) { return __awaiter$1(void 0, void 0, void 0, function () {
|
|
1656
1660
|
return __generator$1(this, function (_a) {
|
|
1657
1661
|
setCredentials(values);
|
|
1658
|
-
setStep("
|
|
1662
|
+
setStep("MFA");
|
|
1659
1663
|
return [2 /*return*/];
|
|
1660
1664
|
});
|
|
1661
1665
|
}); };
|
|
@@ -1677,9 +1681,9 @@ var ADLoginModal = function (_a) {
|
|
|
1677
1681
|
case 2:
|
|
1678
1682
|
_a.sent();
|
|
1679
1683
|
onOpenChange(false);
|
|
1680
|
-
setStep("
|
|
1684
|
+
setStep("Credentials");
|
|
1681
1685
|
form.reset();
|
|
1682
|
-
|
|
1686
|
+
setMFACode("");
|
|
1683
1687
|
return [3 /*break*/, 5];
|
|
1684
1688
|
case 3:
|
|
1685
1689
|
error_1 = _a.sent();
|
|
@@ -1694,17 +1698,18 @@ var ADLoginModal = function (_a) {
|
|
|
1694
1698
|
}); };
|
|
1695
1699
|
var handleClose = function () {
|
|
1696
1700
|
onOpenChange(false);
|
|
1697
|
-
setStep("
|
|
1701
|
+
setStep("Credentials");
|
|
1698
1702
|
form.reset();
|
|
1699
|
-
|
|
1703
|
+
setMFACode("");
|
|
1704
|
+
setShowPassword(false);
|
|
1700
1705
|
};
|
|
1701
|
-
return (jsx(Dialog, { open: open, onOpenChange: handleClose, children: jsxs(DialogContent, { className: "min-w-[50vw] max-w-[70vw]", children: [jsx(DialogHeader, { children: jsxs("div", { className: "flex items-center gap-4", children: [jsx(KeyIcon, { className: "w-8 h-8 text-[#506f4a]" }), jsx(DialogTitle, { className: "text-xl", children: "Sign in with AD Credentials" })] }) }), step === "
|
|
1706
|
+
return (jsx(Dialog, { open: open, onOpenChange: handleClose, children: jsxs(DialogContent, { className: "min-w-[50vw] max-w-[70vw]", children: [jsx(DialogHeader, { children: jsxs("div", { className: "flex items-center gap-4", children: [jsx(KeyIcon, { className: "w-8 h-8 text-[#506f4a]" }), jsx(DialogTitle, { className: "text-xl", children: "Sign in with AD Credentials" })] }) }), step === "Credentials" ? (jsx(Form, __assign({}, form, { children: jsxs("form", { onSubmit: form.handleSubmit(handleCredentialsSubmit), className: "space-y-6", children: [jsx(FormField, { control: form.control, name: "username", render: function (_a) {
|
|
1702
1707
|
var field = _a.field;
|
|
1703
1708
|
return (jsxs(FormItem, { children: [jsx(FormLabel, { children: "Username" }), jsx(FormControl, { children: jsx(Input, __assign({ className: "h-12", placeholder: "Enter your username" }, field)) }), jsx(FormMessage, {})] }));
|
|
1704
1709
|
} }), jsx(FormField, { control: form.control, name: "password", render: function (_a) {
|
|
1705
1710
|
var field = _a.field;
|
|
1706
|
-
return (jsxs(FormItem, { children: [jsx(FormLabel, { children: "Password" }), jsx(FormControl, { children: jsx(Input, __assign({ className: "h-12", type: "password", placeholder: "Enter your password" }, field)) }), jsx(FormMessage, {})] }));
|
|
1707
|
-
} }), jsx(Button, { type: "submit", className: "py-3 w-full bg-[#506f4a] hover:bg-[#506f4a]/90", children: "Continue" })] }) }))) : (jsxs("div", { className: "space-y-4", children: [jsx(GenericOTPVerifier, { value:
|
|
1711
|
+
return (jsxs(FormItem, { children: [jsx(FormLabel, { children: "Password" }), jsx(FormControl, { children: jsxs("div", { className: "relative", children: [jsx(Input, __assign({ className: "h-12 pr-10", type: "password", placeholder: "Enter your password" }, field)), 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 ? (jsx(EyeOff, { className: "w-5 h-5" })) : (jsx(Eye, { className: "w-5 h-5" })) })] }) }), jsx(FormMessage, {})] }));
|
|
1712
|
+
} }), jsx(Button, { type: "submit", className: "py-3 w-full bg-[#506f4a] hover:bg-[#506f4a]/90", children: "Continue" })] }) }))) : (jsxs("div", { className: "space-y-4", children: [jsx(GenericOTPVerifier, { value: MFACode, setValue: setMFACode, setLoading: setIsLoading, isDisabled: isLoading, onChangeOTP: handleMFASubmit, fieldName: "AuthenticatorCode" }), isLoading && (jsxs("div", { className: "flex items-center justify-center gap-2 text-sm text-muted-foreground", children: [jsx(Loader2, { className: "w-4 h-4 animate-spin" }), jsx("span", { children: "Verifying..." })] }))] }))] }) }));
|
|
1708
1713
|
};
|
|
1709
1714
|
|
|
1710
1715
|
var DefaultLoginPage = function (_a) {
|
|
@@ -1729,6 +1734,12 @@ var DefaultLoginPage = function (_a) {
|
|
|
1729
1734
|
console.log(data);
|
|
1730
1735
|
if (state && data && data.isValid) {
|
|
1731
1736
|
context.isAuthenticated = true;
|
|
1737
|
+
localStorage.setItem(context.storageKey, JSON.stringify({
|
|
1738
|
+
isAuthenticated: false,
|
|
1739
|
+
requiresMFA: false,
|
|
1740
|
+
accessToken: "Credentials",
|
|
1741
|
+
idToken: "Credentials",
|
|
1742
|
+
}));
|
|
1732
1743
|
context.requiresMFA = false;
|
|
1733
1744
|
context.setUserProfile({
|
|
1734
1745
|
state: "AUTH_SUCCESS",
|
|
@@ -1744,7 +1755,7 @@ var DefaultLoginPage = function (_a) {
|
|
|
1744
1755
|
});
|
|
1745
1756
|
}
|
|
1746
1757
|
else {
|
|
1747
|
-
toast.error("\u274C AD Login failed. ".concat((data === null || data === void 0 ? void 0 : data.message) ||
|
|
1758
|
+
toast.error("\u274C AD Login failed. ".concat((data === null || data === void 0 ? void 0 : data.message) || "Unknown error"));
|
|
1748
1759
|
}
|
|
1749
1760
|
return [2 /*return*/];
|
|
1750
1761
|
});
|
|
@@ -1776,7 +1787,12 @@ var DefaultLoginPage = function (_a) {
|
|
|
1776
1787
|
return __generator$1(this, function (_c) {
|
|
1777
1788
|
// Implement your AD login logic here
|
|
1778
1789
|
console.log("AD Login:", { username: username, MFACode: MFACode });
|
|
1779
|
-
handleSubmitCredentials(CredentialsAuthEndpoint, {
|
|
1790
|
+
handleSubmitCredentials(CredentialsAuthEndpoint, {
|
|
1791
|
+
username: username,
|
|
1792
|
+
password: password,
|
|
1793
|
+
MFACode: MFACode,
|
|
1794
|
+
appCode: context.appCode,
|
|
1795
|
+
});
|
|
1780
1796
|
return [2 /*return*/];
|
|
1781
1797
|
});
|
|
1782
1798
|
}); } })] }));
|
|
@@ -1802,7 +1818,7 @@ var MFAGate = function (_a) {
|
|
|
1802
1818
|
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;
|
|
1803
1819
|
var context = useCAMSContext();
|
|
1804
1820
|
var _e = useState("Loading"), authState = _e[0], setAuthState = _e[1];
|
|
1805
|
-
var
|
|
1821
|
+
var ValidatedMFAEndpoints = useMemo(function () {
|
|
1806
1822
|
var parsed = MFAEndpointsSchema.safeParse(MFAEndpoints);
|
|
1807
1823
|
if (!parsed.success) {
|
|
1808
1824
|
Logger.error("Invalid MFAEndpoint", parsed.error);
|
|
@@ -1860,20 +1876,19 @@ var MFAGate = function (_a) {
|
|
|
1860
1876
|
setAuthState("Loading");
|
|
1861
1877
|
return;
|
|
1862
1878
|
}
|
|
1863
|
-
if (
|
|
1879
|
+
// Check if user has accessToken (MSAL authenticated)
|
|
1880
|
+
if (!contextAccessToken) {
|
|
1864
1881
|
setAuthState("Unauthenticated");
|
|
1865
1882
|
return;
|
|
1866
1883
|
}
|
|
1867
|
-
//
|
|
1884
|
+
// User has accessToken, determine if MFA is required
|
|
1868
1885
|
var shouldRequireMFA = requiresMFA !== null && requiresMFA !== void 0 ? requiresMFA : contextRequiresMFA;
|
|
1869
1886
|
console.log("MFA decision:", {
|
|
1870
1887
|
shouldRequireMFA: shouldRequireMFA,
|
|
1871
1888
|
hasAccessToken: !!contextAccessToken,
|
|
1872
|
-
finalState: shouldRequireMFA
|
|
1873
|
-
? "MFA_Required"
|
|
1874
|
-
: "Authenticated",
|
|
1889
|
+
finalState: shouldRequireMFA ? "MFA_Required" : "Authenticated",
|
|
1875
1890
|
});
|
|
1876
|
-
if (shouldRequireMFA
|
|
1891
|
+
if (shouldRequireMFA) {
|
|
1877
1892
|
setAuthState("MFA_Required");
|
|
1878
1893
|
}
|
|
1879
1894
|
else {
|
|
@@ -1885,6 +1900,7 @@ var MFAGate = function (_a) {
|
|
|
1885
1900
|
contextRequiresMFA, // Now this will trigger re-evaluation when requiresMFA changes
|
|
1886
1901
|
contextAccessToken, // And this when accessToken changes
|
|
1887
1902
|
requiresMFA,
|
|
1903
|
+
context.authMode,
|
|
1888
1904
|
]);
|
|
1889
1905
|
// Debug useEffect
|
|
1890
1906
|
useEffect(function () {
|
|
@@ -1905,7 +1921,7 @@ var MFAGate = function (_a) {
|
|
|
1905
1921
|
]);
|
|
1906
1922
|
if (useADLogin && !CredentialsAuthEndpoint)
|
|
1907
1923
|
return jsx(ErrorFallback, { message: "Invalid AD Login Configuration." });
|
|
1908
|
-
if (!
|
|
1924
|
+
if (!ValidatedMFAEndpoints)
|
|
1909
1925
|
return jsx(ErrorFallback, { message: "Invalid MFA Configuration." });
|
|
1910
1926
|
if (context.authMode !== "MSAL")
|
|
1911
1927
|
return jsx(Fragment, { children: children });
|
|
@@ -1913,12 +1929,12 @@ var MFAGate = function (_a) {
|
|
|
1913
1929
|
case "Loading":
|
|
1914
1930
|
return fallback;
|
|
1915
1931
|
case "MFA_Required":
|
|
1916
|
-
return (jsx(MFAOptions, { MFAEndpoints:
|
|
1932
|
+
return (jsx(MFAOptions, { MFAEndpoints: ValidatedMFAEndpoints, usePassKey: usePassKey, onComplete: handleComplete, onAuthFailed: handleAuthFailed }));
|
|
1917
1933
|
case "Authenticated":
|
|
1918
1934
|
return jsx(Fragment, { children: children });
|
|
1919
1935
|
case "Unauthenticated":
|
|
1920
1936
|
default:
|
|
1921
|
-
return (jsx(DefaultLoginPage, { usePassKey: usePassKey, useADLogin: useADLogin, MFAEndpoints:
|
|
1937
|
+
return (jsx(DefaultLoginPage, { usePassKey: usePassKey, useADLogin: useADLogin, MFAEndpoints: ValidatedMFAEndpoints, PassKeysRegisterProps: PassKeysRegisterProps, CredentialsAuthEndpoint: CredentialsAuthEndpoint }));
|
|
1922
1938
|
}
|
|
1923
1939
|
};
|
|
1924
1940
|
|