@nibssplc/cams-sdk-react 0.0.1-beta.99 → 1.0.0-rc.3
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 +3 -1
- package/dist/components/DefaultLoginPage.d.ts +3 -1
- package/dist/components/MFAGate.d.ts +3 -1
- package/dist/hooks/useOTPHandler.d.ts +2 -7
- package/dist/index.cjs.js +137 -64
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +137 -64
- package/dist/index.esm.js.map +1 -1
- package/dist/utils/DeviceID.d.ts +4 -1
- package/package.json +1 -1
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
interface ADLoginModalProps {
|
|
2
2
|
open: boolean;
|
|
3
|
+
isLoading: boolean;
|
|
4
|
+
setIsLoading: React.Dispatch<React.SetStateAction<boolean>>;
|
|
3
5
|
onOpenChange: (open: boolean) => void;
|
|
4
6
|
onLogin: (credentials: Credentials) => Promise<void>;
|
|
5
7
|
}
|
|
6
|
-
export declare const ADLoginModal: ({ open, onOpenChange, onLogin, }: ADLoginModalProps) => import("react/jsx-runtime").JSX.Element;
|
|
8
|
+
export declare const ADLoginModal: ({ open, isLoading, setIsLoading, onOpenChange, onLogin, }: ADLoginModalProps) => import("react/jsx-runtime").JSX.Element;
|
|
7
9
|
export {};
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { MFAEndpoints } from "./MFAGate";
|
|
2
2
|
interface LoginPageProps {
|
|
3
3
|
usePassKey?: boolean;
|
|
4
|
+
CredentialsAuthEndpoint?: string;
|
|
5
|
+
useADLogin?: boolean;
|
|
4
6
|
MFAEndpoints: MFAEndpoints;
|
|
5
7
|
PassKeysRegisterProps?: Record<string, unknown>;
|
|
6
8
|
}
|
|
7
|
-
declare const DefaultLoginPage: ({ usePassKey, MFAEndpoints, PassKeysRegisterProps, }: LoginPageProps) => import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
declare const DefaultLoginPage: ({ usePassKey, useADLogin, MFAEndpoints, CredentialsAuthEndpoint, PassKeysRegisterProps, }: LoginPageProps) => import("react/jsx-runtime").JSX.Element;
|
|
8
10
|
export default DefaultLoginPage;
|
|
@@ -11,8 +11,10 @@ interface MFAGateProps {
|
|
|
11
11
|
children: React.ReactNode;
|
|
12
12
|
fallback?: React.ReactNode;
|
|
13
13
|
usePassKey?: boolean;
|
|
14
|
+
useADLogin?: boolean;
|
|
15
|
+
CredentialsAuthEndpoint?: string;
|
|
14
16
|
PassKeysRegisterProps?: Record<string, unknown>;
|
|
15
17
|
MFAEndpoints?: MFAEndpoints;
|
|
16
18
|
}
|
|
17
|
-
declare const MFAGate: ({ children, fallback, usePassKey, PassKeysRegisterProps, MFAEndpoints, }: MFAGateProps) => string | number | bigint | boolean | Iterable<import("react").ReactNode> | Promise<string | number | bigint | boolean | import("react").ReactPortal | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<import("react").ReactNode> | null | undefined> | import("react/jsx-runtime").JSX.Element | null;
|
|
19
|
+
declare const MFAGate: ({ children, fallback, usePassKey, useADLogin, CredentialsAuthEndpoint, PassKeysRegisterProps, MFAEndpoints, }: MFAGateProps) => string | number | bigint | boolean | Iterable<import("react").ReactNode> | Promise<string | number | bigint | boolean | import("react").ReactPortal | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<import("react").ReactNode> | null | undefined> | import("react/jsx-runtime").JSX.Element | null;
|
|
18
20
|
export default MFAGate;
|
|
@@ -15,13 +15,8 @@ export declare const useOTPHandler: ({ provider, accessToken, idToken, appCode,
|
|
|
15
15
|
resetAttempts: () => void;
|
|
16
16
|
remainingAttempts: number;
|
|
17
17
|
};
|
|
18
|
-
export declare const useCredentialsHandler: (
|
|
19
|
-
handleSubmitCredentials: (
|
|
20
|
-
username: string;
|
|
21
|
-
password: string;
|
|
22
|
-
MFACode: string;
|
|
23
|
-
appCode: string;
|
|
24
|
-
}) => Promise<boolean>;
|
|
18
|
+
export declare const useCredentialsHandler: (onAuthComplete: (state: boolean, data: UserValidatedResponse | null) => void) => {
|
|
19
|
+
handleSubmitCredentials: (CredAuthEndpoint: string, credentials: Credentials, appCode: string) => Promise<boolean>;
|
|
25
20
|
loading: boolean;
|
|
26
21
|
setLoading: import("react").Dispatch<import("react").SetStateAction<boolean>>;
|
|
27
22
|
attemptCount: number;
|
package/dist/index.cjs.js
CHANGED
|
@@ -582,21 +582,13 @@ function register(options) {
|
|
|
582
582
|
case 0:
|
|
583
583
|
_k.trys.push([0, 2, , 3]);
|
|
584
584
|
createOptions = __assign(__assign({}, options), { challenge: base64urlToArrayBuffer(options.challenge), user: __assign(__assign({}, options.user), { id: base64urlToArrayBuffer(options.user.id) }) });
|
|
585
|
-
console.log("Creating credential with options:", createOptions, "...\n\n\n", options);
|
|
586
585
|
return [4 /*yield*/, navigator.credentials.create({
|
|
587
|
-
publicKey: __assign(__assign({},
|
|
586
|
+
publicKey: __assign(__assign({}, createOptions), { pubKeyCredParams: (_a = options.pubKeyCredParams) === null || _a === void 0 ? void 0 : _a.map(function (param) { return ({
|
|
588
587
|
type: "public-key",
|
|
589
588
|
alg: param.alg,
|
|
590
|
-
}); }), attestation: (((_b = options.attestation) === null || _b === void 0 ? void 0 : _b.toLowerCase()) || "none"), authenticatorSelection: __assign(__assign({}, options.authenticatorSelection), {
|
|
591
|
-
// authenticatorAttachment:
|
|
592
|
-
// (options.authenticatorSelection?.authenticatorAttachment?.toLowerCase() ||
|
|
593
|
-
// "platform") as AuthenticatorAttachment,
|
|
594
|
-
// requireResidentKey:
|
|
595
|
-
// (options.authenticatorSelection?.requireResidentKey?.toLowerCase() ||
|
|
596
|
-
// "false") === "true",
|
|
597
|
-
residentKey: (((_d = (_c = options.authenticatorSelection) === null || _c === void 0 ? void 0 : _c.residentKey) === null || _d === void 0 ? void 0 : _d.toLowerCase()) ||
|
|
589
|
+
}); }), attestation: (((_b = options.attestation) === null || _b === void 0 ? void 0 : _b.toLowerCase()) || "none"), authenticatorSelection: __assign(__assign({}, options.authenticatorSelection), { residentKey: (((_d = (_c = options.authenticatorSelection) === null || _c === void 0 ? void 0 : _c.residentKey) === null || _d === void 0 ? void 0 : _d.toLowerCase()) ||
|
|
598
590
|
"discouraged"), userVerification: (((_f = (_e = options.authenticatorSelection) === null || _e === void 0 ? void 0 : _e.userVerification) === null || _f === void 0 ? void 0 : _f.toLowerCase()) ||
|
|
599
|
-
"
|
|
591
|
+
"discouraged") }) }),
|
|
600
592
|
})];
|
|
601
593
|
case 1:
|
|
602
594
|
credential = _k.sent();
|
|
@@ -617,12 +609,16 @@ function register(options) {
|
|
|
617
609
|
}];
|
|
618
610
|
case 2:
|
|
619
611
|
err_1 = _k.sent();
|
|
612
|
+
console.error("Error during registration:", err_1);
|
|
620
613
|
if (err_1.name === "NotAllowedError") {
|
|
621
|
-
throw new Error("
|
|
614
|
+
throw new Error("Face ID/Touch ID cancelled or failed. Please try again.");
|
|
622
615
|
}
|
|
623
616
|
if (err_1.name === "InvalidStateError") {
|
|
624
617
|
throw new Error("Passkey already registered for this user.");
|
|
625
618
|
}
|
|
619
|
+
if (err_1.name === "NotSupportedError") {
|
|
620
|
+
throw new Error("Passkeys not supported on this device.");
|
|
621
|
+
}
|
|
626
622
|
throw err_1;
|
|
627
623
|
case 3: return [2 /*return*/];
|
|
628
624
|
}
|
|
@@ -1744,7 +1740,7 @@ var GenerateDeviceId = function () {
|
|
|
1744
1740
|
var userAgent = window.navigator.userAgent;
|
|
1745
1741
|
var deviceId = "";
|
|
1746
1742
|
// Parse browser, version, OS, and device type
|
|
1747
|
-
var browserMatch = Array.from(userAgent.matchAll(/(Chrome|Firefox|Safari|Edge|Opera)\/([\d.]+)/
|
|
1743
|
+
var browserMatch = Array.from(userAgent.matchAll(/(Chrome|Firefox|Safari|Edge|Opera)\/([\d.]+)/gi));
|
|
1748
1744
|
var osMatch = Array.from(userAgent.matchAll(/\(([^)]+)\)/g));
|
|
1749
1745
|
var isMobile = /Mobile|Android|iPhone|iPad/i.test(userAgent);
|
|
1750
1746
|
// Browser info
|
|
@@ -1774,6 +1770,10 @@ var GenerateDeviceId = function () {
|
|
|
1774
1770
|
deviceId += "_".concat(hash);
|
|
1775
1771
|
return (_a = deviceId.replace(/[^a-zA-Z0-9-_]/g, "_")) !== null && _a !== void 0 ? _a : "unknown-device";
|
|
1776
1772
|
};
|
|
1773
|
+
var APIHeaders = {
|
|
1774
|
+
"X-DEVICE-ID": GenerateDeviceId(),
|
|
1775
|
+
"X-API-VERSION": "1.0",
|
|
1776
|
+
};
|
|
1777
1777
|
|
|
1778
1778
|
var MAX_ATTEMPTS = 3;
|
|
1779
1779
|
var useOTPHandler = function (_a) {
|
|
@@ -1808,9 +1808,7 @@ var useOTPHandler = function (_a) {
|
|
|
1808
1808
|
MFACode: authenticationValue,
|
|
1809
1809
|
appCode: appCode,
|
|
1810
1810
|
}, {
|
|
1811
|
-
headers:
|
|
1812
|
-
"X-Device-ID": GenerateDeviceId(),
|
|
1813
|
-
},
|
|
1811
|
+
headers: APIHeaders,
|
|
1814
1812
|
timeout: 605000,
|
|
1815
1813
|
})];
|
|
1816
1814
|
case 2:
|
|
@@ -1873,6 +1871,78 @@ var useOTPHandler = function (_a) {
|
|
|
1873
1871
|
remainingAttempts: MAX_ATTEMPTS - attemptCount,
|
|
1874
1872
|
};
|
|
1875
1873
|
};
|
|
1874
|
+
var useCredentialsHandler = function (onAuthComplete) {
|
|
1875
|
+
var _a = React.useState(false), loading = _a[0], setLoading = _a[1];
|
|
1876
|
+
var _b = React.useState(0), attemptCount = _b[0], setAttemptCount = _b[1];
|
|
1877
|
+
var _c = React.useState(false), isMaxAttemptsReached = _c[0], setIsMaxAttemptsReached = _c[1];
|
|
1878
|
+
var handleSubmitCredentials = React.useMemo(function () {
|
|
1879
|
+
return function (CredAuthEndpoint, credentials, appCode) { return __awaiter(void 0, void 0, void 0, function () {
|
|
1880
|
+
var currentAttempt, response, error_2, currentAttempt;
|
|
1881
|
+
return __generator(this, function (_a) {
|
|
1882
|
+
switch (_a.label) {
|
|
1883
|
+
case 0:
|
|
1884
|
+
_a.trys.push([0, 2, 3, 4]);
|
|
1885
|
+
setLoading(true);
|
|
1886
|
+
currentAttempt = attemptCount + 1;
|
|
1887
|
+
setAttemptCount(currentAttempt);
|
|
1888
|
+
return [4 /*yield*/, axios.post(CredAuthEndpoint, {
|
|
1889
|
+
username: credentials.username,
|
|
1890
|
+
password: credentials.password,
|
|
1891
|
+
MFACode: credentials.MFACode,
|
|
1892
|
+
appCode: appCode,
|
|
1893
|
+
}, {
|
|
1894
|
+
headers: APIHeaders,
|
|
1895
|
+
timeout: 605000,
|
|
1896
|
+
})];
|
|
1897
|
+
case 1:
|
|
1898
|
+
response = (_a.sent()).data;
|
|
1899
|
+
if (response) {
|
|
1900
|
+
onAuthComplete(true, response);
|
|
1901
|
+
return [2 /*return*/, true];
|
|
1902
|
+
}
|
|
1903
|
+
else {
|
|
1904
|
+
if (currentAttempt >= MAX_ATTEMPTS) {
|
|
1905
|
+
setIsMaxAttemptsReached(true);
|
|
1906
|
+
onAuthComplete(false, {
|
|
1907
|
+
message: "Maximum attempts reached",
|
|
1908
|
+
});
|
|
1909
|
+
}
|
|
1910
|
+
else {
|
|
1911
|
+
onAuthComplete(false, response.response.data);
|
|
1912
|
+
}
|
|
1913
|
+
return [2 /*return*/, false];
|
|
1914
|
+
}
|
|
1915
|
+
case 2:
|
|
1916
|
+
error_2 = _a.sent();
|
|
1917
|
+
console.error(error_2);
|
|
1918
|
+
currentAttempt = attemptCount + 1;
|
|
1919
|
+
if (currentAttempt >= MAX_ATTEMPTS) {
|
|
1920
|
+
setIsMaxAttemptsReached(true);
|
|
1921
|
+
onAuthComplete(false, error_2.response.data);
|
|
1922
|
+
}
|
|
1923
|
+
else {
|
|
1924
|
+
onAuthComplete(false, error_2.response.data);
|
|
1925
|
+
}
|
|
1926
|
+
onAuthComplete(false, error_2.response.data);
|
|
1927
|
+
return [2 /*return*/, false];
|
|
1928
|
+
case 3:
|
|
1929
|
+
setLoading(false);
|
|
1930
|
+
return [7 /*endfinally*/];
|
|
1931
|
+
case 4: return [2 /*return*/];
|
|
1932
|
+
}
|
|
1933
|
+
});
|
|
1934
|
+
}); };
|
|
1935
|
+
}, []);
|
|
1936
|
+
return {
|
|
1937
|
+
handleSubmitCredentials: handleSubmitCredentials,
|
|
1938
|
+
loading: loading,
|
|
1939
|
+
setLoading: setLoading,
|
|
1940
|
+
attemptCount: attemptCount,
|
|
1941
|
+
isMaxAttemptsReached: isMaxAttemptsReached,
|
|
1942
|
+
// resetAttempts,
|
|
1943
|
+
remainingAttempts: MAX_ATTEMPTS - attemptCount,
|
|
1944
|
+
};
|
|
1945
|
+
};
|
|
1876
1946
|
|
|
1877
1947
|
var MFAOptions = function (_a) {
|
|
1878
1948
|
var onComplete = _a.onComplete, onAuthFailed = _a.onAuthFailed, MFAEndpoints = _a.MFAEndpoints, usePassKey = _a.usePassKey;
|
|
@@ -1891,46 +1961,36 @@ var MFAOptions = function (_a) {
|
|
|
1891
1961
|
var authenticate = useWebAuthn().authenticate;
|
|
1892
1962
|
var handleFIDOLogin = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
1893
1963
|
var options, assertionResponse, error_1;
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
switch (_g.label) {
|
|
1964
|
+
return __generator(this, function (_a) {
|
|
1965
|
+
switch (_a.label) {
|
|
1897
1966
|
case 0:
|
|
1898
|
-
|
|
1967
|
+
_a.trys.push([0, 4, , 5]);
|
|
1899
1968
|
// 1. Fetch authentication challenge from your server
|
|
1900
1969
|
console.log("Requesting authentication challenge from server...");
|
|
1901
1970
|
return [4 /*yield*/, axios.post(MFAEndpoints.RetrieveAuthChallenge, {}, {
|
|
1902
|
-
headers:
|
|
1903
|
-
"X-DEVICE-ID": GenerateDeviceId(),
|
|
1904
|
-
"X-API-VERSION": "1.0",
|
|
1905
|
-
},
|
|
1971
|
+
headers: APIHeaders,
|
|
1906
1972
|
})];
|
|
1907
1973
|
case 1:
|
|
1908
|
-
options = (
|
|
1974
|
+
options = (_a.sent()).data;
|
|
1909
1975
|
console.log("Received challenge:", options);
|
|
1910
1976
|
// 2. Call the SDK to trigger the browser's passkey authentication UI
|
|
1911
1977
|
console.log("Calling SDK authenticate function...");
|
|
1912
|
-
return [4 /*yield*/, authenticate(__assign(__assign({}, options), {
|
|
1913
|
-
type: "public-key",
|
|
1914
|
-
alg: param.alg
|
|
1915
|
-
}); }), attestation: ((_b = options.attestation) === null || _b === void 0 ? void 0 : _b.toLowerCase()) || "none", authenticatorSelection: __assign(__assign({}, options.authenticatorSelection), { residentKey: ((_d = (_c = options.authenticatorSelection) === null || _c === void 0 ? void 0 : _c.residentKey) === null || _d === void 0 ? void 0 : _d.toLowerCase()) || "discouraged", userVerification: ((_f = (_e = options.authenticatorSelection) === null || _e === void 0 ? void 0 : _e.userVerification) === null || _f === void 0 ? void 0 : _f.toLowerCase()) || "preferred" }) }))];
|
|
1978
|
+
return [4 /*yield*/, authenticate(__assign(__assign({}, options), { userVerification: "discouraged" }))];
|
|
1916
1979
|
case 2:
|
|
1917
|
-
assertionResponse =
|
|
1980
|
+
assertionResponse = _a.sent();
|
|
1918
1981
|
console.log("Authentication assertion received from client:", assertionResponse);
|
|
1919
1982
|
// 3. Send the assertion back to the server for verification
|
|
1920
1983
|
console.log("Sending assertion to server for verification...");
|
|
1921
1984
|
return [4 /*yield*/, axios.post(MFAEndpoints.AuthChallengeVerify, assertionResponse, {
|
|
1922
|
-
headers:
|
|
1923
|
-
"X-DEVICE-ID": GenerateDeviceId(),
|
|
1924
|
-
"X-API-VERSION": "1.0",
|
|
1925
|
-
},
|
|
1985
|
+
headers: APIHeaders,
|
|
1926
1986
|
withCredentials: true, // credentials: 'include'
|
|
1927
1987
|
})];
|
|
1928
1988
|
case 3:
|
|
1929
|
-
|
|
1989
|
+
_a.sent();
|
|
1930
1990
|
sonner.toast.success("🔑 Sign-in successful!");
|
|
1931
1991
|
return [3 /*break*/, 5];
|
|
1932
1992
|
case 4:
|
|
1933
|
-
error_1 =
|
|
1993
|
+
error_1 = _a.sent();
|
|
1934
1994
|
console.error("Authentication failed:", error_1);
|
|
1935
1995
|
sonner.toast.error("❌ Could not sign in.");
|
|
1936
1996
|
return [3 /*break*/, 5];
|
|
@@ -2049,14 +2109,13 @@ var credentialsSchema = z.z.object({
|
|
|
2049
2109
|
password: z.z.string().min(1, "Password is required"),
|
|
2050
2110
|
});
|
|
2051
2111
|
var ADLoginModal = function (_a) {
|
|
2052
|
-
var open = _a.open, onOpenChange = _a.onOpenChange, onLogin = _a.onLogin;
|
|
2112
|
+
var open = _a.open, isLoading = _a.isLoading, setIsLoading = _a.setIsLoading, onOpenChange = _a.onOpenChange, onLogin = _a.onLogin;
|
|
2053
2113
|
var _b = React.useState("credentials"), step = _b[0], setStep = _b[1];
|
|
2054
2114
|
var _c = React.useState({
|
|
2055
2115
|
username: "",
|
|
2056
2116
|
password: "",
|
|
2057
2117
|
}), credentials = _c[0], setCredentials = _c[1];
|
|
2058
2118
|
var _d = React.useState(""), mfaCode = _d[0], setMfaCode = _d[1];
|
|
2059
|
-
var _e = React.useState(false), isLoading = _e[0], setIsLoading = _e[1];
|
|
2060
2119
|
var form = reactHookForm.useForm({
|
|
2061
2120
|
resolver: a$1(credentialsSchema),
|
|
2062
2121
|
defaultValues: { username: "", password: "" },
|
|
@@ -2106,21 +2165,45 @@ var ADLoginModal = function (_a) {
|
|
|
2106
2165
|
form.reset();
|
|
2107
2166
|
setMfaCode("");
|
|
2108
2167
|
};
|
|
2109
|
-
return (jsxRuntimeExports.jsx(Dialog, { open: open, onOpenChange: handleClose, children: jsxRuntimeExports.jsxs(DialogContent, { className: "
|
|
2168
|
+
return (jsxRuntimeExports.jsx(Dialog, { open: open, onOpenChange: handleClose, children: jsxRuntimeExports.jsxs(DialogContent, { className: "min-w-[50vw] max-w-[70vw]", children: [jsxRuntimeExports.jsx(DialogHeader, { children: jsxRuntimeExports.jsxs("div", { className: "flex items-center gap-2", children: [jsxRuntimeExports.jsx(lucideReact.KeyIcon, { className: "w-8 h-8 text-[#506f4a]" }), jsxRuntimeExports.jsx(DialogTitle, { className: "text-2xl", children: "Sign in with AD" })] }) }), step === "credentials" ? (jsxRuntimeExports.jsx(Form, __assign({}, form, { children: jsxRuntimeExports.jsxs("form", { onSubmit: form.handleSubmit(handleCredentialsSubmit), className: "space-y-4", children: [jsxRuntimeExports.jsx(FormField, { control: form.control, name: "username", render: function (_a) {
|
|
2110
2169
|
var field = _a.field;
|
|
2111
|
-
return (jsxRuntimeExports.jsxs(FormItem, { children: [jsxRuntimeExports.jsx(FormLabel, { children: "Username" }), jsxRuntimeExports.jsx(FormControl, { children: jsxRuntimeExports.jsx(Input, __assign({ placeholder: "Enter your username" }, field)) }), jsxRuntimeExports.jsx(FormMessage, {})] }));
|
|
2170
|
+
return (jsxRuntimeExports.jsxs(FormItem, { children: [jsxRuntimeExports.jsx(FormLabel, { children: "Username" }), jsxRuntimeExports.jsx(FormControl, { children: jsxRuntimeExports.jsx(Input, __assign({ className: "h-12", placeholder: "Enter your username" }, field)) }), jsxRuntimeExports.jsx(FormMessage, {})] }));
|
|
2112
2171
|
} }), jsxRuntimeExports.jsx(FormField, { control: form.control, name: "password", render: function (_a) {
|
|
2113
2172
|
var field = _a.field;
|
|
2114
|
-
return (jsxRuntimeExports.jsxs(FormItem, { children: [jsxRuntimeExports.jsx(FormLabel, { children: "Password" }), jsxRuntimeExports.jsx(FormControl, { children: jsxRuntimeExports.jsx(Input, __assign({ type: "password", placeholder: "Enter your password" }, field)) }), jsxRuntimeExports.jsx(FormMessage, {})] }));
|
|
2173
|
+
return (jsxRuntimeExports.jsxs(FormItem, { children: [jsxRuntimeExports.jsx(FormLabel, { children: "Password" }), jsxRuntimeExports.jsx(FormControl, { children: jsxRuntimeExports.jsx(Input, __assign({ className: "h-12", type: "password", placeholder: "Enter your password" }, field)) }), jsxRuntimeExports.jsx(FormMessage, {})] }));
|
|
2115
2174
|
} }), jsxRuntimeExports.jsx(Button, { type: "submit", className: "w-full bg-[#506f4a] hover:bg-[#506f4a]/90", children: "Continue" })] }) }))) : (jsxRuntimeExports.jsxs("div", { className: "space-y-4", children: [jsxRuntimeExports.jsx(GenericOTPVerifier, { value: mfaCode, setValue: setMfaCode, setLoading: setIsLoading, isDisabled: isLoading, onChangeOTP: handleMFASubmit, fieldName: "AuthenticatorCode" }), isLoading && (jsxRuntimeExports.jsxs("div", { className: "flex items-center justify-center gap-2 text-sm text-muted-foreground", children: [jsxRuntimeExports.jsx(lucideReact.Loader2, { className: "w-4 h-4 animate-spin" }), jsxRuntimeExports.jsx("span", { children: "Verifying..." })] }))] }))] }) }));
|
|
2116
2175
|
};
|
|
2117
2176
|
|
|
2118
2177
|
var DefaultLoginPage = function (_a) {
|
|
2119
|
-
var usePassKey = _a.usePassKey, MFAEndpoints = _a.MFAEndpoints, PassKeysRegisterProps = _a.PassKeysRegisterProps;
|
|
2178
|
+
var usePassKey = _a.usePassKey, useADLogin = _a.useADLogin, MFAEndpoints = _a.MFAEndpoints, CredentialsAuthEndpoint = _a.CredentialsAuthEndpoint, PassKeysRegisterProps = _a.PassKeysRegisterProps;
|
|
2179
|
+
var cardVariants = {
|
|
2180
|
+
hidden: { opacity: 0, scale: 0.8, y: 50 },
|
|
2181
|
+
visible: {
|
|
2182
|
+
opacity: 1,
|
|
2183
|
+
scale: 1,
|
|
2184
|
+
y: 0,
|
|
2185
|
+
transition: { type: "spring", duration: 0.6 },
|
|
2186
|
+
},
|
|
2187
|
+
exit: { opacity: 0, scale: 0.8, y: -50, transition: { duration: 0.3 } },
|
|
2188
|
+
};
|
|
2120
2189
|
var context = useCAMSContext();
|
|
2121
2190
|
var login = context.login, isLoading = context.isLoading, authMode = context.authMode;
|
|
2122
2191
|
var _b = React.useState(false), showADModal = _b[0], setShowADModal = _b[1];
|
|
2123
2192
|
var register = useWebAuthn().register;
|
|
2193
|
+
var _c = useCredentialsHandler(function (state, data) { return __awaiter(void 0, void 0, void 0, function () {
|
|
2194
|
+
return __generator(this, function (_a) {
|
|
2195
|
+
console.log(data);
|
|
2196
|
+
if (state && data) {
|
|
2197
|
+
context.isAuthenticated = true;
|
|
2198
|
+
context.requiresMFA = false;
|
|
2199
|
+
context.setUserProfile({
|
|
2200
|
+
type: "AUTH_SUCCESS",
|
|
2201
|
+
userProfile: __assign({}, data),
|
|
2202
|
+
});
|
|
2203
|
+
}
|
|
2204
|
+
return [2 /*return*/];
|
|
2205
|
+
});
|
|
2206
|
+
}); }), handleSubmitCredentials = _c.handleSubmitCredentials, isCredAuthLoading = _c.loading, setIsCredAuthLoading = _c.setLoading;
|
|
2124
2207
|
var handleMSALLogin = function () {
|
|
2125
2208
|
if (authMode === "MSAL") {
|
|
2126
2209
|
login();
|
|
@@ -2130,16 +2213,6 @@ var DefaultLoginPage = function (_a) {
|
|
|
2130
2213
|
console.warn("Regular CAMS login requires configuration");
|
|
2131
2214
|
}
|
|
2132
2215
|
};
|
|
2133
|
-
var cardVariants = {
|
|
2134
|
-
hidden: { opacity: 0, scale: 0.8, y: 50 },
|
|
2135
|
-
visible: {
|
|
2136
|
-
opacity: 1,
|
|
2137
|
-
scale: 1,
|
|
2138
|
-
y: 0,
|
|
2139
|
-
transition: { type: "spring", duration: 0.6 },
|
|
2140
|
-
},
|
|
2141
|
-
exit: { opacity: 0, scale: 0.8, y: -50, transition: { duration: 0.3 } },
|
|
2142
|
-
};
|
|
2143
2216
|
var handleRegister = function (data) { return __awaiter(void 0, void 0, void 0, function () {
|
|
2144
2217
|
var options, attestationResponse, error_1;
|
|
2145
2218
|
return __generator(this, function (_a) {
|
|
@@ -2149,10 +2222,7 @@ var DefaultLoginPage = function (_a) {
|
|
|
2149
2222
|
// 1. Fetch challenge from your server
|
|
2150
2223
|
console.log("Requesting registration challenge from server...");
|
|
2151
2224
|
return [4 /*yield*/, axios.post(MFAEndpoints.RegisterNewChallenge, __assign({}, data), {
|
|
2152
|
-
headers:
|
|
2153
|
-
"X-DEVICE-ID": GenerateDeviceId(),
|
|
2154
|
-
"X-API-VERSION": "1.0",
|
|
2155
|
-
},
|
|
2225
|
+
headers: APIHeaders,
|
|
2156
2226
|
})];
|
|
2157
2227
|
case 1:
|
|
2158
2228
|
options = (_a.sent()).data;
|
|
@@ -2166,10 +2236,7 @@ var DefaultLoginPage = function (_a) {
|
|
|
2166
2236
|
// 3. Send the response back to the server for verification
|
|
2167
2237
|
console.log("Sending attestation to server for verification...");
|
|
2168
2238
|
return [4 /*yield*/, axios.post(MFAEndpoints.RegisterVerify, attestationResponse, {
|
|
2169
|
-
headers:
|
|
2170
|
-
"X-DEVICE-ID": GenerateDeviceId(),
|
|
2171
|
-
"X-API-VERSION": "1.0",
|
|
2172
|
-
},
|
|
2239
|
+
headers: APIHeaders,
|
|
2173
2240
|
withCredentials: true, // credentials: 'include'
|
|
2174
2241
|
})];
|
|
2175
2242
|
case 3:
|
|
@@ -2189,11 +2256,15 @@ var DefaultLoginPage = function (_a) {
|
|
|
2189
2256
|
// variant="outline"
|
|
2190
2257
|
, {
|
|
2191
2258
|
// variant="outline"
|
|
2192
|
-
className: "w-full flex items-center justify-center cursor-pointer bg-[#506f4a] hover:bg-[#506f4a] rounded-lg border border-transparent px-5 py-8 text-base font-medium transition-colors duration-250", onClick: handleMSALLogin, disabled: isLoading, children: [jsxRuntimeExports.jsx("img", { src: MicrosoftLogo, alt: "Microsoft Logo", width: 35, height: 35 }), jsxRuntimeExports.jsx("span", { className: "ml-2", children: isLoading ? "Logging in..." : "Sign in with Microsoft" })] }),
|
|
2259
|
+
className: "w-full flex items-center justify-center cursor-pointer bg-[#506f4a] hover:bg-[#506f4a] rounded-lg border border-transparent px-5 py-8 text-base font-medium transition-colors duration-250", onClick: handleMSALLogin, disabled: isLoading, children: [jsxRuntimeExports.jsx("img", { src: MicrosoftLogo, alt: "Microsoft Logo", width: 35, height: 35 }), jsxRuntimeExports.jsx("span", { className: "ml-2", children: isLoading ? "Logging in..." : "Sign in with Microsoft" })] }), useADLogin && (jsxRuntimeExports.jsxs(Button, { className: "w-full flex items-center justify-center cursor-pointer bg-[#506f4a] hover:bg-[#506f4a] rounded-lg border border-transparent px-5 py-8 text-base font-medium transition-colors duration-250", onClick: function () { return setShowADModal(true); }, disabled: isLoading, children: [jsxRuntimeExports.jsx(lucideReact.KeyIcon, { className: "text-[#506f4a]", size: 64 }), jsxRuntimeExports.jsx("span", { children: isLoading
|
|
2260
|
+
? "Logging in..."
|
|
2261
|
+
: "Sign in with ActiveDirectory" })] })), usePassKey && (jsxRuntimeExports.jsxs(Button, { className: "w-full flex items-center justify-center cursor-pointer bg-[#506f4a] hover:bg-[#506f4a] rounded-lg border border-transparent px-5 py-8 text-base font-medium transition-colors duration-250", onClick: function () { return handleRegister(PassKeysRegisterProps); }, disabled: isLoading, children: [jsxRuntimeExports.jsx(lucideReact.KeyIcon, { className: "text-[#506f4a]", size: 64 }), jsxRuntimeExports.jsx("span", { children: "Create a Passkey" })] }))] }), jsxRuntimeExports.jsxs(CardFooter, { className: "flex items-center justify-center mt-6 space-x-2 text-gray-400 text-sm", children: [jsxRuntimeExports.jsx(lucideReact.ShieldCheck, { className: "w-4 h-4 text-[#506f4a] pulse-glow" }), jsxRuntimeExports.jsx("span", { children: "Powered By NIBSS" })] })] }) }) }, "landing"), jsxRuntimeExports.jsx(ADLoginModal, { open: showADModal, onOpenChange: setShowADModal, isLoading: isCredAuthLoading, setIsLoading: setIsCredAuthLoading, onLogin: function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
|
|
2193
2262
|
var username = _b.username, password = _b.password, MFACode = _b.MFACode;
|
|
2194
2263
|
return __generator(this, function (_c) {
|
|
2195
2264
|
// Implement your AD login logic here
|
|
2196
2265
|
console.log("AD Login:", { username: username, password: password, MFACode: MFACode });
|
|
2266
|
+
// Example: await adLoginService(username, password, mfaCode);
|
|
2267
|
+
handleSubmitCredentials(CredentialsAuthEndpoint !== null && CredentialsAuthEndpoint !== void 0 ? CredentialsAuthEndpoint : "/api/auth/validate", { username: username, password: password, MFACode: MFACode }, context.appCode);
|
|
2197
2268
|
return [2 /*return*/];
|
|
2198
2269
|
});
|
|
2199
2270
|
}); } })] }));
|
|
@@ -2216,7 +2287,7 @@ var MFAGate = function (_a) {
|
|
|
2216
2287
|
// loginComponent: LoginComponent = DefaultLoginPage,
|
|
2217
2288
|
_c = _a.usePassKey,
|
|
2218
2289
|
// loginComponent: LoginComponent = DefaultLoginPage,
|
|
2219
|
-
usePassKey = _c === void 0 ? false : _c, PassKeysRegisterProps = _a.PassKeysRegisterProps, MFAEndpoints = _a.MFAEndpoints;
|
|
2290
|
+
usePassKey = _c === void 0 ? false : _c, _d = _a.useADLogin, useADLogin = _d === void 0 ? false : _d, CredentialsAuthEndpoint = _a.CredentialsAuthEndpoint, PassKeysRegisterProps = _a.PassKeysRegisterProps, MFAEndpoints = _a.MFAEndpoints;
|
|
2220
2291
|
var context = useCAMSContext();
|
|
2221
2292
|
var validatedMFAEndpoints = React.useMemo(function () {
|
|
2222
2293
|
var parsed = MFAEndpointsSchema.safeParse(MFAEndpoints);
|
|
@@ -2241,8 +2312,10 @@ var MFAGate = function (_a) {
|
|
|
2241
2312
|
});
|
|
2242
2313
|
}); }, [context.logout]);
|
|
2243
2314
|
camsSdk.Logger.debug("MFA Endpoint >>>", { MFAEndpoints: MFAEndpoints });
|
|
2315
|
+
if (useADLogin && !CredentialsAuthEndpoint)
|
|
2316
|
+
return jsxRuntimeExports.jsx(ErrorFallback, { message: "Invalid AD Login Configuration." });
|
|
2244
2317
|
if (!validatedMFAEndpoints)
|
|
2245
|
-
return jsxRuntimeExports.jsx(ErrorFallback, { message: "Invalid MFA
|
|
2318
|
+
return jsxRuntimeExports.jsx(ErrorFallback, { message: "Invalid MFA Configuration." });
|
|
2246
2319
|
if (context.authMode !== "MSAL")
|
|
2247
2320
|
return jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: children });
|
|
2248
2321
|
if (context.isLoading)
|
|
@@ -2251,7 +2324,7 @@ var MFAGate = function (_a) {
|
|
|
2251
2324
|
return (jsxRuntimeExports.jsx(MFAOptions, { MFAEndpoints: validatedMFAEndpoints, usePassKey: usePassKey, onComplete: handleComplete, onAuthFailed: handleAuthFailed }));
|
|
2252
2325
|
}
|
|
2253
2326
|
if (!context.isAuthenticated) {
|
|
2254
|
-
return (jsxRuntimeExports.jsx(DefaultLoginPage, { usePassKey: usePassKey, MFAEndpoints: MFAEndpoints, PassKeysRegisterProps: PassKeysRegisterProps }));
|
|
2327
|
+
return (jsxRuntimeExports.jsx(DefaultLoginPage, { usePassKey: usePassKey, useADLogin: useADLogin, MFAEndpoints: MFAEndpoints, PassKeysRegisterProps: PassKeysRegisterProps, CredentialsAuthEndpoint: CredentialsAuthEndpoint }));
|
|
2255
2328
|
}
|
|
2256
2329
|
return jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: children });
|
|
2257
2330
|
};
|