@nibssplc/cams-sdk-react 0.0.1-beta.98 → 1.0.0-rc.2
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 +147 -66
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +147 -66
- 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
|
@@ -576,23 +576,27 @@ function arrayBufferToBase64url(buffer) {
|
|
|
576
576
|
function register(options) {
|
|
577
577
|
return __awaiter(this, void 0, void 0, function () {
|
|
578
578
|
var createOptions, credential, publicKeyCredential, attestationResponse, transports, err_1;
|
|
579
|
-
var _a, _b, _c;
|
|
580
|
-
return __generator(this, function (
|
|
581
|
-
switch (
|
|
579
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
580
|
+
return __generator(this, function (_k) {
|
|
581
|
+
switch (_k.label) {
|
|
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: createOptions,
|
|
586
|
+
publicKey: __assign(__assign({}, createOptions), { pubKeyCredParams: (_a = options.pubKeyCredParams) === null || _a === void 0 ? void 0 : _a.map(function (param) { return ({
|
|
587
|
+
type: "public-key",
|
|
588
|
+
alg: param.alg,
|
|
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()) ||
|
|
590
|
+
"discouraged"), userVerification: (((_f = (_e = options.authenticatorSelection) === null || _e === void 0 ? void 0 : _e.userVerification) === null || _f === void 0 ? void 0 : _f.toLowerCase()) ||
|
|
591
|
+
"discouraged") }) }),
|
|
588
592
|
})];
|
|
589
593
|
case 1:
|
|
590
|
-
credential =
|
|
594
|
+
credential = _k.sent();
|
|
591
595
|
if (!credential)
|
|
592
596
|
throw new Error("No credential created.");
|
|
593
597
|
publicKeyCredential = credential;
|
|
594
598
|
attestationResponse = publicKeyCredential.response;
|
|
595
|
-
transports = (
|
|
599
|
+
transports = (_j = (_h = (_g = publicKeyCredential.response).getTransports) === null || _h === void 0 ? void 0 : _h.call(_g)) !== null && _j !== void 0 ? _j : [];
|
|
596
600
|
return [2 /*return*/, {
|
|
597
601
|
id: publicKeyCredential.id,
|
|
598
602
|
rawId: arrayBufferToBase64url(publicKeyCredential.rawId),
|
|
@@ -604,13 +608,17 @@ function register(options) {
|
|
|
604
608
|
},
|
|
605
609
|
}];
|
|
606
610
|
case 2:
|
|
607
|
-
err_1 =
|
|
611
|
+
err_1 = _k.sent();
|
|
612
|
+
console.error("Error during registration:", err_1);
|
|
608
613
|
if (err_1.name === "NotAllowedError") {
|
|
609
|
-
throw new Error("
|
|
614
|
+
throw new Error("Face ID/Touch ID cancelled or failed. Please try again.");
|
|
610
615
|
}
|
|
611
616
|
if (err_1.name === "InvalidStateError") {
|
|
612
617
|
throw new Error("Passkey already registered for this user.");
|
|
613
618
|
}
|
|
619
|
+
if (err_1.name === "NotSupportedError") {
|
|
620
|
+
throw new Error("Passkeys not supported on this device.");
|
|
621
|
+
}
|
|
614
622
|
throw err_1;
|
|
615
623
|
case 3: return [2 /*return*/];
|
|
616
624
|
}
|
|
@@ -1732,7 +1740,7 @@ var GenerateDeviceId = function () {
|
|
|
1732
1740
|
var userAgent = window.navigator.userAgent;
|
|
1733
1741
|
var deviceId = "";
|
|
1734
1742
|
// Parse browser, version, OS, and device type
|
|
1735
|
-
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));
|
|
1736
1744
|
var osMatch = Array.from(userAgent.matchAll(/\(([^)]+)\)/g));
|
|
1737
1745
|
var isMobile = /Mobile|Android|iPhone|iPad/i.test(userAgent);
|
|
1738
1746
|
// Browser info
|
|
@@ -1762,6 +1770,10 @@ var GenerateDeviceId = function () {
|
|
|
1762
1770
|
deviceId += "_".concat(hash);
|
|
1763
1771
|
return (_a = deviceId.replace(/[^a-zA-Z0-9-_]/g, "_")) !== null && _a !== void 0 ? _a : "unknown-device";
|
|
1764
1772
|
};
|
|
1773
|
+
var APIHeaders = {
|
|
1774
|
+
"X-DEVICE-ID": GenerateDeviceId(),
|
|
1775
|
+
"X-API-VERSION": "1.0",
|
|
1776
|
+
};
|
|
1765
1777
|
|
|
1766
1778
|
var MAX_ATTEMPTS = 3;
|
|
1767
1779
|
var useOTPHandler = function (_a) {
|
|
@@ -1796,9 +1808,7 @@ var useOTPHandler = function (_a) {
|
|
|
1796
1808
|
MFACode: authenticationValue,
|
|
1797
1809
|
appCode: appCode,
|
|
1798
1810
|
}, {
|
|
1799
|
-
headers:
|
|
1800
|
-
"X-Device-ID": GenerateDeviceId(),
|
|
1801
|
-
},
|
|
1811
|
+
headers: APIHeaders,
|
|
1802
1812
|
timeout: 605000,
|
|
1803
1813
|
})];
|
|
1804
1814
|
case 2:
|
|
@@ -1861,6 +1871,78 @@ var useOTPHandler = function (_a) {
|
|
|
1861
1871
|
remainingAttempts: MAX_ATTEMPTS - attemptCount,
|
|
1862
1872
|
};
|
|
1863
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
|
+
};
|
|
1864
1946
|
|
|
1865
1947
|
var MFAOptions = function (_a) {
|
|
1866
1948
|
var onComplete = _a.onComplete, onAuthFailed = _a.onAuthFailed, MFAEndpoints = _a.MFAEndpoints, usePassKey = _a.usePassKey;
|
|
@@ -1879,50 +1961,36 @@ var MFAOptions = function (_a) {
|
|
|
1879
1961
|
var authenticate = useWebAuthn().authenticate;
|
|
1880
1962
|
var handleFIDOLogin = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
1881
1963
|
var options, assertionResponse, error_1;
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
switch (_o.label) {
|
|
1964
|
+
return __generator(this, function (_a) {
|
|
1965
|
+
switch (_a.label) {
|
|
1885
1966
|
case 0:
|
|
1886
|
-
|
|
1967
|
+
_a.trys.push([0, 4, , 5]);
|
|
1887
1968
|
// 1. Fetch authentication challenge from your server
|
|
1888
1969
|
console.log("Requesting authentication challenge from server...");
|
|
1889
1970
|
return [4 /*yield*/, axios.post(MFAEndpoints.RetrieveAuthChallenge, {}, {
|
|
1890
|
-
headers:
|
|
1891
|
-
"X-DEVICE-ID": GenerateDeviceId(),
|
|
1892
|
-
"X-API-VERSION": "1.0",
|
|
1893
|
-
},
|
|
1971
|
+
headers: APIHeaders,
|
|
1894
1972
|
})];
|
|
1895
1973
|
case 1:
|
|
1896
|
-
options = (
|
|
1974
|
+
options = (_a.sent()).data;
|
|
1897
1975
|
console.log("Received challenge:", options);
|
|
1898
|
-
__assign(__assign({}, options), { pubKeyCredParams: (_a = options.pubKeyCredParams) === null || _a === void 0 ? void 0 : _a.map(function (param) { return ({
|
|
1899
|
-
type: "public-key",
|
|
1900
|
-
alg: param.alg
|
|
1901
|
-
}); }), 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" }) });
|
|
1902
1976
|
// 2. Call the SDK to trigger the browser's passkey authentication UI
|
|
1903
1977
|
console.log("Calling SDK authenticate function...");
|
|
1904
|
-
return [4 /*yield*/, authenticate(__assign(__assign({}, options), {
|
|
1905
|
-
type: "public-key",
|
|
1906
|
-
alg: param.alg
|
|
1907
|
-
}); }), attestation: ((_h = options.attestation) === null || _h === void 0 ? void 0 : _h.toLowerCase()) || "none", authenticatorSelection: __assign(__assign({}, options.authenticatorSelection), { residentKey: ((_k = (_j = options.authenticatorSelection) === null || _j === void 0 ? void 0 : _j.residentKey) === null || _k === void 0 ? void 0 : _k.toLowerCase()) || "discouraged", userVerification: ((_m = (_l = options.authenticatorSelection) === null || _l === void 0 ? void 0 : _l.userVerification) === null || _m === void 0 ? void 0 : _m.toLowerCase()) || "preferred" }) }))];
|
|
1978
|
+
return [4 /*yield*/, authenticate(__assign(__assign({}, options), { userVerification: "discouraged" }))];
|
|
1908
1979
|
case 2:
|
|
1909
|
-
assertionResponse =
|
|
1980
|
+
assertionResponse = _a.sent();
|
|
1910
1981
|
console.log("Authentication assertion received from client:", assertionResponse);
|
|
1911
1982
|
// 3. Send the assertion back to the server for verification
|
|
1912
1983
|
console.log("Sending assertion to server for verification...");
|
|
1913
1984
|
return [4 /*yield*/, axios.post(MFAEndpoints.AuthChallengeVerify, assertionResponse, {
|
|
1914
|
-
headers:
|
|
1915
|
-
"X-DEVICE-ID": GenerateDeviceId(),
|
|
1916
|
-
"X-API-VERSION": "1.0",
|
|
1917
|
-
},
|
|
1985
|
+
headers: APIHeaders,
|
|
1918
1986
|
withCredentials: true, // credentials: 'include'
|
|
1919
1987
|
})];
|
|
1920
1988
|
case 3:
|
|
1921
|
-
|
|
1989
|
+
_a.sent();
|
|
1922
1990
|
sonner.toast.success("🔑 Sign-in successful!");
|
|
1923
1991
|
return [3 /*break*/, 5];
|
|
1924
1992
|
case 4:
|
|
1925
|
-
error_1 =
|
|
1993
|
+
error_1 = _a.sent();
|
|
1926
1994
|
console.error("Authentication failed:", error_1);
|
|
1927
1995
|
sonner.toast.error("❌ Could not sign in.");
|
|
1928
1996
|
return [3 /*break*/, 5];
|
|
@@ -2041,14 +2109,13 @@ var credentialsSchema = z.z.object({
|
|
|
2041
2109
|
password: z.z.string().min(1, "Password is required"),
|
|
2042
2110
|
});
|
|
2043
2111
|
var ADLoginModal = function (_a) {
|
|
2044
|
-
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;
|
|
2045
2113
|
var _b = React.useState("credentials"), step = _b[0], setStep = _b[1];
|
|
2046
2114
|
var _c = React.useState({
|
|
2047
2115
|
username: "",
|
|
2048
2116
|
password: "",
|
|
2049
2117
|
}), credentials = _c[0], setCredentials = _c[1];
|
|
2050
2118
|
var _d = React.useState(""), mfaCode = _d[0], setMfaCode = _d[1];
|
|
2051
|
-
var _e = React.useState(false), isLoading = _e[0], setIsLoading = _e[1];
|
|
2052
2119
|
var form = reactHookForm.useForm({
|
|
2053
2120
|
resolver: a$1(credentialsSchema),
|
|
2054
2121
|
defaultValues: { username: "", password: "" },
|
|
@@ -2098,21 +2165,45 @@ var ADLoginModal = function (_a) {
|
|
|
2098
2165
|
form.reset();
|
|
2099
2166
|
setMfaCode("");
|
|
2100
2167
|
};
|
|
2101
|
-
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: "w-[70vw] min-w-[250px] max-w-[350px]", 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) {
|
|
2102
2169
|
var field = _a.field;
|
|
2103
|
-
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, {})] }));
|
|
2104
2171
|
} }), jsxRuntimeExports.jsx(FormField, { control: form.control, name: "password", render: function (_a) {
|
|
2105
2172
|
var field = _a.field;
|
|
2106
|
-
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, {})] }));
|
|
2107
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..." })] }))] }))] }) }));
|
|
2108
2175
|
};
|
|
2109
2176
|
|
|
2110
2177
|
var DefaultLoginPage = function (_a) {
|
|
2111
|
-
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
|
+
};
|
|
2112
2189
|
var context = useCAMSContext();
|
|
2113
2190
|
var login = context.login, isLoading = context.isLoading, authMode = context.authMode;
|
|
2114
2191
|
var _b = React.useState(false), showADModal = _b[0], setShowADModal = _b[1];
|
|
2115
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;
|
|
2116
2207
|
var handleMSALLogin = function () {
|
|
2117
2208
|
if (authMode === "MSAL") {
|
|
2118
2209
|
login();
|
|
@@ -2122,16 +2213,6 @@ var DefaultLoginPage = function (_a) {
|
|
|
2122
2213
|
console.warn("Regular CAMS login requires configuration");
|
|
2123
2214
|
}
|
|
2124
2215
|
};
|
|
2125
|
-
var cardVariants = {
|
|
2126
|
-
hidden: { opacity: 0, scale: 0.8, y: 50 },
|
|
2127
|
-
visible: {
|
|
2128
|
-
opacity: 1,
|
|
2129
|
-
scale: 1,
|
|
2130
|
-
y: 0,
|
|
2131
|
-
transition: { type: "spring", duration: 0.6 },
|
|
2132
|
-
},
|
|
2133
|
-
exit: { opacity: 0, scale: 0.8, y: -50, transition: { duration: 0.3 } },
|
|
2134
|
-
};
|
|
2135
2216
|
var handleRegister = function (data) { return __awaiter(void 0, void 0, void 0, function () {
|
|
2136
2217
|
var options, attestationResponse, error_1;
|
|
2137
2218
|
return __generator(this, function (_a) {
|
|
@@ -2141,10 +2222,7 @@ var DefaultLoginPage = function (_a) {
|
|
|
2141
2222
|
// 1. Fetch challenge from your server
|
|
2142
2223
|
console.log("Requesting registration challenge from server...");
|
|
2143
2224
|
return [4 /*yield*/, axios.post(MFAEndpoints.RegisterNewChallenge, __assign({}, data), {
|
|
2144
|
-
headers:
|
|
2145
|
-
"X-DEVICE-ID": GenerateDeviceId(),
|
|
2146
|
-
"X-API-VERSION": "1.0",
|
|
2147
|
-
},
|
|
2225
|
+
headers: APIHeaders,
|
|
2148
2226
|
})];
|
|
2149
2227
|
case 1:
|
|
2150
2228
|
options = (_a.sent()).data;
|
|
@@ -2158,10 +2236,7 @@ var DefaultLoginPage = function (_a) {
|
|
|
2158
2236
|
// 3. Send the response back to the server for verification
|
|
2159
2237
|
console.log("Sending attestation to server for verification...");
|
|
2160
2238
|
return [4 /*yield*/, axios.post(MFAEndpoints.RegisterVerify, attestationResponse, {
|
|
2161
|
-
headers:
|
|
2162
|
-
"X-DEVICE-ID": GenerateDeviceId(),
|
|
2163
|
-
"X-API-VERSION": "1.0",
|
|
2164
|
-
},
|
|
2239
|
+
headers: APIHeaders,
|
|
2165
2240
|
withCredentials: true, // credentials: 'include'
|
|
2166
2241
|
})];
|
|
2167
2242
|
case 3:
|
|
@@ -2181,11 +2256,15 @@ var DefaultLoginPage = function (_a) {
|
|
|
2181
2256
|
// variant="outline"
|
|
2182
2257
|
, {
|
|
2183
2258
|
// variant="outline"
|
|
2184
|
-
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) {
|
|
2185
2262
|
var username = _b.username, password = _b.password, MFACode = _b.MFACode;
|
|
2186
2263
|
return __generator(this, function (_c) {
|
|
2187
2264
|
// Implement your AD login logic here
|
|
2188
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);
|
|
2189
2268
|
return [2 /*return*/];
|
|
2190
2269
|
});
|
|
2191
2270
|
}); } })] }));
|
|
@@ -2208,7 +2287,7 @@ var MFAGate = function (_a) {
|
|
|
2208
2287
|
// loginComponent: LoginComponent = DefaultLoginPage,
|
|
2209
2288
|
_c = _a.usePassKey,
|
|
2210
2289
|
// loginComponent: LoginComponent = DefaultLoginPage,
|
|
2211
|
-
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;
|
|
2212
2291
|
var context = useCAMSContext();
|
|
2213
2292
|
var validatedMFAEndpoints = React.useMemo(function () {
|
|
2214
2293
|
var parsed = MFAEndpointsSchema.safeParse(MFAEndpoints);
|
|
@@ -2233,8 +2312,10 @@ var MFAGate = function (_a) {
|
|
|
2233
2312
|
});
|
|
2234
2313
|
}); }, [context.logout]);
|
|
2235
2314
|
camsSdk.Logger.debug("MFA Endpoint >>>", { MFAEndpoints: MFAEndpoints });
|
|
2315
|
+
if (useADLogin && !CredentialsAuthEndpoint)
|
|
2316
|
+
return jsxRuntimeExports.jsx(ErrorFallback, { message: "Invalid AD Login Configuration." });
|
|
2236
2317
|
if (!validatedMFAEndpoints)
|
|
2237
|
-
return jsxRuntimeExports.jsx(ErrorFallback, { message: "Invalid MFA
|
|
2318
|
+
return jsxRuntimeExports.jsx(ErrorFallback, { message: "Invalid MFA Configuration." });
|
|
2238
2319
|
if (context.authMode !== "MSAL")
|
|
2239
2320
|
return jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: children });
|
|
2240
2321
|
if (context.isLoading)
|
|
@@ -2243,7 +2324,7 @@ var MFAGate = function (_a) {
|
|
|
2243
2324
|
return (jsxRuntimeExports.jsx(MFAOptions, { MFAEndpoints: validatedMFAEndpoints, usePassKey: usePassKey, onComplete: handleComplete, onAuthFailed: handleAuthFailed }));
|
|
2244
2325
|
}
|
|
2245
2326
|
if (!context.isAuthenticated) {
|
|
2246
|
-
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 }));
|
|
2247
2328
|
}
|
|
2248
2329
|
return jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: children });
|
|
2249
2330
|
};
|