@nibssplc/cams-sdk-react 0.0.1-beta.98 → 1.0.0-rc.10
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 +169 -85
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +169 -85
- package/dist/index.esm.js.map +1 -1
- package/dist/lib/actions/Axiosinstance.d.ts +1 -0
- package/dist/utils/DeviceID.d.ts +4 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -18,6 +18,7 @@ import * as DialogPrimitive from '@radix-ui/react-dialog';
|
|
|
18
18
|
import { toast } from 'sonner';
|
|
19
19
|
import { motion } from 'framer-motion';
|
|
20
20
|
import axios from 'axios';
|
|
21
|
+
import https from 'https';
|
|
21
22
|
|
|
22
23
|
/******************************************************************************
|
|
23
24
|
Copyright (c) Microsoft Corporation.
|
|
@@ -311,7 +312,6 @@ function useCAMSMSALAuth(options) {
|
|
|
311
312
|
setMfaAuthenticator(authenticator);
|
|
312
313
|
setRequiresMFA(true);
|
|
313
314
|
}
|
|
314
|
-
Logger.debug("App Code", { ">>>": options.appCode });
|
|
315
315
|
}
|
|
316
316
|
else {
|
|
317
317
|
localStorage.removeItem(storageKey);
|
|
@@ -555,23 +555,27 @@ function arrayBufferToBase64url(buffer) {
|
|
|
555
555
|
function register(options) {
|
|
556
556
|
return __awaiter(this, void 0, void 0, function () {
|
|
557
557
|
var createOptions, credential, publicKeyCredential, attestationResponse, transports, err_1;
|
|
558
|
-
var _a, _b, _c;
|
|
559
|
-
return __generator(this, function (
|
|
560
|
-
switch (
|
|
558
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
559
|
+
return __generator(this, function (_k) {
|
|
560
|
+
switch (_k.label) {
|
|
561
561
|
case 0:
|
|
562
|
-
|
|
562
|
+
_k.trys.push([0, 2, , 3]);
|
|
563
563
|
createOptions = __assign(__assign({}, options), { challenge: base64urlToArrayBuffer(options.challenge), user: __assign(__assign({}, options.user), { id: base64urlToArrayBuffer(options.user.id) }) });
|
|
564
|
-
console.log("Creating credential with options:", createOptions, "...\n\n\n", options);
|
|
565
564
|
return [4 /*yield*/, navigator.credentials.create({
|
|
566
|
-
publicKey: createOptions,
|
|
565
|
+
publicKey: __assign(__assign({}, createOptions), { pubKeyCredParams: (_a = options.pubKeyCredParams) === null || _a === void 0 ? void 0 : _a.map(function (param) { return ({
|
|
566
|
+
type: "public-key",
|
|
567
|
+
alg: param.alg,
|
|
568
|
+
}); }), 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()) ||
|
|
569
|
+
"discouraged"), userVerification: (((_f = (_e = options.authenticatorSelection) === null || _e === void 0 ? void 0 : _e.userVerification) === null || _f === void 0 ? void 0 : _f.toLowerCase()) ||
|
|
570
|
+
"discouraged") }) }),
|
|
567
571
|
})];
|
|
568
572
|
case 1:
|
|
569
|
-
credential =
|
|
573
|
+
credential = _k.sent();
|
|
570
574
|
if (!credential)
|
|
571
575
|
throw new Error("No credential created.");
|
|
572
576
|
publicKeyCredential = credential;
|
|
573
577
|
attestationResponse = publicKeyCredential.response;
|
|
574
|
-
transports = (
|
|
578
|
+
transports = (_j = (_h = (_g = publicKeyCredential.response).getTransports) === null || _h === void 0 ? void 0 : _h.call(_g)) !== null && _j !== void 0 ? _j : [];
|
|
575
579
|
return [2 /*return*/, {
|
|
576
580
|
id: publicKeyCredential.id,
|
|
577
581
|
rawId: arrayBufferToBase64url(publicKeyCredential.rawId),
|
|
@@ -583,13 +587,17 @@ function register(options) {
|
|
|
583
587
|
},
|
|
584
588
|
}];
|
|
585
589
|
case 2:
|
|
586
|
-
err_1 =
|
|
590
|
+
err_1 = _k.sent();
|
|
591
|
+
console.error("Error during registration:", err_1);
|
|
587
592
|
if (err_1.name === "NotAllowedError") {
|
|
588
|
-
throw new Error("
|
|
593
|
+
throw new Error("Face ID/Touch ID cancelled or failed. Please try again.");
|
|
589
594
|
}
|
|
590
595
|
if (err_1.name === "InvalidStateError") {
|
|
591
596
|
throw new Error("Passkey already registered for this user.");
|
|
592
597
|
}
|
|
598
|
+
if (err_1.name === "NotSupportedError") {
|
|
599
|
+
throw new Error("Passkeys not supported on this device.");
|
|
600
|
+
}
|
|
593
601
|
throw err_1;
|
|
594
602
|
case 3: return [2 /*return*/];
|
|
595
603
|
}
|
|
@@ -1694,7 +1702,7 @@ styleInject(css_248z);
|
|
|
1694
1702
|
|
|
1695
1703
|
var LoadingSpinner = function (_a) {
|
|
1696
1704
|
var loadingText = _a.loadingText;
|
|
1697
|
-
return (jsxRuntimeExports.jsxs("div", { className: "flex flex-col justify-center items-center", children: [jsxRuntimeExports.jsx("script", { type: "module", defer: true, src: "https://cdn.jsdelivr.net/npm/ldrs/dist/auto/waveform.js" }), jsxRuntimeExports.jsx(r, { size: "35", stroke: "3.5", speed: "1", color: "green" }), loadingText && (jsxRuntimeExports.jsx("p", { className: "text-center font-semibold mt-3", children: "Loading..." }))] }));
|
|
1705
|
+
return (jsxRuntimeExports.jsxs("div", { className: "flex flex-col justify-center items-center h-full w-full py-10", children: [jsxRuntimeExports.jsx("script", { type: "module", defer: true, src: "https://cdn.jsdelivr.net/npm/ldrs/dist/auto/waveform.js" }), jsxRuntimeExports.jsx(r, { size: "35", stroke: "3.5", speed: "1", color: "green" }), loadingText && (jsxRuntimeExports.jsx("p", { className: "text-center font-semibold mt-3", children: "Loading..." }))] }));
|
|
1698
1706
|
};
|
|
1699
1707
|
|
|
1700
1708
|
var AuthSuccessAnimation = function (_a) {
|
|
@@ -1711,7 +1719,7 @@ var GenerateDeviceId = function () {
|
|
|
1711
1719
|
var userAgent = window.navigator.userAgent;
|
|
1712
1720
|
var deviceId = "";
|
|
1713
1721
|
// Parse browser, version, OS, and device type
|
|
1714
|
-
var browserMatch = Array.from(userAgent.matchAll(/(Chrome|Firefox|Safari|Edge|Opera)\/([\d.]+)/
|
|
1722
|
+
var browserMatch = Array.from(userAgent.matchAll(/(Chrome|Firefox|Safari|Edge|Opera)\/([\d.]+)/gi));
|
|
1715
1723
|
var osMatch = Array.from(userAgent.matchAll(/\(([^)]+)\)/g));
|
|
1716
1724
|
var isMobile = /Mobile|Android|iPhone|iPad/i.test(userAgent);
|
|
1717
1725
|
// Browser info
|
|
@@ -1741,6 +1749,31 @@ var GenerateDeviceId = function () {
|
|
|
1741
1749
|
deviceId += "_".concat(hash);
|
|
1742
1750
|
return (_a = deviceId.replace(/[^a-zA-Z0-9-_]/g, "_")) !== null && _a !== void 0 ? _a : "unknown-device";
|
|
1743
1751
|
};
|
|
1752
|
+
var APIHeaders = {
|
|
1753
|
+
"X-DEVICE-ID": GenerateDeviceId(),
|
|
1754
|
+
"X-API-VERSION": "1.0",
|
|
1755
|
+
};
|
|
1756
|
+
|
|
1757
|
+
// Creates an Axios instance with a base URL determined by the environment (production or development).
|
|
1758
|
+
var axiosInstance = axios.create({
|
|
1759
|
+
httpsAgent: new https.Agent({ rejectUnauthorized: false }),
|
|
1760
|
+
headers: __assign({ "Content-Type": "application/json" }, APIHeaders),
|
|
1761
|
+
});
|
|
1762
|
+
// Intercepts outgoing requests to add authorization token, version header, and timeout settings.
|
|
1763
|
+
axiosInstance.interceptors.request.use(function (config) {
|
|
1764
|
+
var _a;
|
|
1765
|
+
config.timeout = Number((_a = process.env.NEXT_PUBLIC_API_TIMEOUT) !== null && _a !== void 0 ? _a : 605000);
|
|
1766
|
+
config.timeoutErrorMessage = "Operation Timed Out"; // Custom error message for timeouts.
|
|
1767
|
+
return config; // Returns the modified request configuration.
|
|
1768
|
+
}, function (axiosError) {
|
|
1769
|
+
var _a, _b;
|
|
1770
|
+
// Handles request errors.
|
|
1771
|
+
return {
|
|
1772
|
+
status: (_a = axiosError.response) === null || _a === void 0 ? void 0 : _a.status, // Extracts HTTP status from the error response.
|
|
1773
|
+
message: axiosError.message, // Extracts the error message.
|
|
1774
|
+
data: (_b = axiosError.response) === null || _b === void 0 ? void 0 : _b.data, // Extracts response data from the error.
|
|
1775
|
+
};
|
|
1776
|
+
});
|
|
1744
1777
|
|
|
1745
1778
|
var MAX_ATTEMPTS = 3;
|
|
1746
1779
|
var useOTPHandler = function (_a) {
|
|
@@ -1767,18 +1800,13 @@ var useOTPHandler = function (_a) {
|
|
|
1767
1800
|
setAttemptCount(currentAttempt);
|
|
1768
1801
|
if (authenticationType === null)
|
|
1769
1802
|
return [2 /*return*/, false];
|
|
1770
|
-
return [4 /*yield*/,
|
|
1803
|
+
return [4 /*yield*/, axiosInstance.post(MFAEndpoint || "/api/auth/verify-mfa", {
|
|
1771
1804
|
provider: provider,
|
|
1772
1805
|
accessToken: accessToken,
|
|
1773
1806
|
idToken: idToken,
|
|
1774
1807
|
authenticationType: authenticationType,
|
|
1775
1808
|
MFACode: authenticationValue,
|
|
1776
1809
|
appCode: appCode,
|
|
1777
|
-
}, {
|
|
1778
|
-
headers: {
|
|
1779
|
-
"X-Device-ID": GenerateDeviceId(),
|
|
1780
|
-
},
|
|
1781
|
-
timeout: 605000,
|
|
1782
1810
|
})];
|
|
1783
1811
|
case 2:
|
|
1784
1812
|
response = (_a.sent()).data;
|
|
@@ -1840,6 +1868,75 @@ var useOTPHandler = function (_a) {
|
|
|
1840
1868
|
remainingAttempts: MAX_ATTEMPTS - attemptCount,
|
|
1841
1869
|
};
|
|
1842
1870
|
};
|
|
1871
|
+
var useCredentialsHandler = function (onAuthComplete) {
|
|
1872
|
+
var _a = useState(false), loading = _a[0], setLoading = _a[1];
|
|
1873
|
+
var _b = useState(0), attemptCount = _b[0], setAttemptCount = _b[1];
|
|
1874
|
+
var _c = useState(false), isMaxAttemptsReached = _c[0], setIsMaxAttemptsReached = _c[1];
|
|
1875
|
+
var handleSubmitCredentials = useMemo(function () {
|
|
1876
|
+
return function (CredAuthEndpoint, credentials, appCode) { return __awaiter(void 0, void 0, void 0, function () {
|
|
1877
|
+
var currentAttempt, response, error_2, currentAttempt;
|
|
1878
|
+
return __generator(this, function (_a) {
|
|
1879
|
+
switch (_a.label) {
|
|
1880
|
+
case 0:
|
|
1881
|
+
_a.trys.push([0, 2, 3, 4]);
|
|
1882
|
+
setLoading(true);
|
|
1883
|
+
currentAttempt = attemptCount + 1;
|
|
1884
|
+
setAttemptCount(currentAttempt);
|
|
1885
|
+
return [4 /*yield*/, axiosInstance.post(CredAuthEndpoint, {
|
|
1886
|
+
username: credentials.username,
|
|
1887
|
+
password: credentials.password,
|
|
1888
|
+
MFACode: credentials.MFACode,
|
|
1889
|
+
appCode: appCode,
|
|
1890
|
+
})];
|
|
1891
|
+
case 1:
|
|
1892
|
+
response = (_a.sent()).data;
|
|
1893
|
+
if (response) {
|
|
1894
|
+
onAuthComplete(true, response);
|
|
1895
|
+
return [2 /*return*/, true];
|
|
1896
|
+
}
|
|
1897
|
+
else {
|
|
1898
|
+
if (currentAttempt >= MAX_ATTEMPTS) {
|
|
1899
|
+
setIsMaxAttemptsReached(true);
|
|
1900
|
+
onAuthComplete(false, {
|
|
1901
|
+
message: "Maximum attempts reached",
|
|
1902
|
+
});
|
|
1903
|
+
}
|
|
1904
|
+
else {
|
|
1905
|
+
onAuthComplete(false, response.response.data);
|
|
1906
|
+
}
|
|
1907
|
+
return [2 /*return*/, false];
|
|
1908
|
+
}
|
|
1909
|
+
case 2:
|
|
1910
|
+
error_2 = _a.sent();
|
|
1911
|
+
console.error(error_2);
|
|
1912
|
+
currentAttempt = attemptCount + 1;
|
|
1913
|
+
if (currentAttempt >= MAX_ATTEMPTS) {
|
|
1914
|
+
setIsMaxAttemptsReached(true);
|
|
1915
|
+
onAuthComplete(false, error_2.response.data);
|
|
1916
|
+
}
|
|
1917
|
+
else {
|
|
1918
|
+
onAuthComplete(false, error_2.response.data);
|
|
1919
|
+
}
|
|
1920
|
+
onAuthComplete(false, error_2.response.data);
|
|
1921
|
+
return [2 /*return*/, false];
|
|
1922
|
+
case 3:
|
|
1923
|
+
setLoading(false);
|
|
1924
|
+
return [7 /*endfinally*/];
|
|
1925
|
+
case 4: return [2 /*return*/];
|
|
1926
|
+
}
|
|
1927
|
+
});
|
|
1928
|
+
}); };
|
|
1929
|
+
}, []);
|
|
1930
|
+
return {
|
|
1931
|
+
handleSubmitCredentials: handleSubmitCredentials,
|
|
1932
|
+
loading: loading,
|
|
1933
|
+
setLoading: setLoading,
|
|
1934
|
+
attemptCount: attemptCount,
|
|
1935
|
+
isMaxAttemptsReached: isMaxAttemptsReached,
|
|
1936
|
+
// resetAttempts,
|
|
1937
|
+
remainingAttempts: MAX_ATTEMPTS - attemptCount,
|
|
1938
|
+
};
|
|
1939
|
+
};
|
|
1843
1940
|
|
|
1844
1941
|
var MFAOptions = function (_a) {
|
|
1845
1942
|
var onComplete = _a.onComplete, onAuthFailed = _a.onAuthFailed, MFAEndpoints = _a.MFAEndpoints, usePassKey = _a.usePassKey;
|
|
@@ -1858,50 +1955,31 @@ var MFAOptions = function (_a) {
|
|
|
1858
1955
|
var authenticate = useWebAuthn().authenticate;
|
|
1859
1956
|
var handleFIDOLogin = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
1860
1957
|
var options, assertionResponse, error_1;
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
switch (_o.label) {
|
|
1958
|
+
return __generator(this, function (_a) {
|
|
1959
|
+
switch (_a.label) {
|
|
1864
1960
|
case 0:
|
|
1865
|
-
|
|
1961
|
+
_a.trys.push([0, 4, , 5]);
|
|
1866
1962
|
// 1. Fetch authentication challenge from your server
|
|
1867
1963
|
console.log("Requesting authentication challenge from server...");
|
|
1868
|
-
return [4 /*yield*/,
|
|
1869
|
-
headers: {
|
|
1870
|
-
"X-DEVICE-ID": GenerateDeviceId(),
|
|
1871
|
-
"X-API-VERSION": "1.0",
|
|
1872
|
-
},
|
|
1873
|
-
})];
|
|
1964
|
+
return [4 /*yield*/, axiosInstance.post(MFAEndpoints.RetrieveAuthChallenge, {})];
|
|
1874
1965
|
case 1:
|
|
1875
|
-
options = (
|
|
1966
|
+
options = (_a.sent()).data;
|
|
1876
1967
|
console.log("Received challenge:", options);
|
|
1877
|
-
__assign(__assign({}, options), { pubKeyCredParams: (_a = options.pubKeyCredParams) === null || _a === void 0 ? void 0 : _a.map(function (param) { return ({
|
|
1878
|
-
type: "public-key",
|
|
1879
|
-
alg: param.alg
|
|
1880
|
-
}); }), 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" }) });
|
|
1881
1968
|
// 2. Call the SDK to trigger the browser's passkey authentication UI
|
|
1882
1969
|
console.log("Calling SDK authenticate function...");
|
|
1883
|
-
return [4 /*yield*/, authenticate(__assign(__assign({}, options), {
|
|
1884
|
-
type: "public-key",
|
|
1885
|
-
alg: param.alg
|
|
1886
|
-
}); }), 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" }) }))];
|
|
1970
|
+
return [4 /*yield*/, authenticate(__assign(__assign({}, options), { userVerification: "discouraged" }))];
|
|
1887
1971
|
case 2:
|
|
1888
|
-
assertionResponse =
|
|
1972
|
+
assertionResponse = _a.sent();
|
|
1889
1973
|
console.log("Authentication assertion received from client:", assertionResponse);
|
|
1890
1974
|
// 3. Send the assertion back to the server for verification
|
|
1891
1975
|
console.log("Sending assertion to server for verification...");
|
|
1892
|
-
return [4 /*yield*/,
|
|
1893
|
-
headers: {
|
|
1894
|
-
"X-DEVICE-ID": GenerateDeviceId(),
|
|
1895
|
-
"X-API-VERSION": "1.0",
|
|
1896
|
-
},
|
|
1897
|
-
withCredentials: true, // credentials: 'include'
|
|
1898
|
-
})];
|
|
1976
|
+
return [4 /*yield*/, axiosInstance.post(MFAEndpoints.AuthChallengeVerify, assertionResponse)];
|
|
1899
1977
|
case 3:
|
|
1900
|
-
|
|
1978
|
+
_a.sent();
|
|
1901
1979
|
toast.success("🔑 Sign-in successful!");
|
|
1902
1980
|
return [3 /*break*/, 5];
|
|
1903
1981
|
case 4:
|
|
1904
|
-
error_1 =
|
|
1982
|
+
error_1 = _a.sent();
|
|
1905
1983
|
console.error("Authentication failed:", error_1);
|
|
1906
1984
|
toast.error("❌ Could not sign in.");
|
|
1907
1985
|
return [3 /*break*/, 5];
|
|
@@ -1962,7 +2040,7 @@ var MFAOptions = function (_a) {
|
|
|
1962
2040
|
return __generator(this, function (_a) {
|
|
1963
2041
|
switch (_a.label) {
|
|
1964
2042
|
case 0:
|
|
1965
|
-
resetAttempts();
|
|
2043
|
+
// resetAttempts();
|
|
1966
2044
|
setAuthType("EmailOTP");
|
|
1967
2045
|
setOtpVisible(true);
|
|
1968
2046
|
if (!sendEmailOTP) return [3 /*break*/, 2];
|
|
@@ -1979,7 +2057,6 @@ var MFAOptions = function (_a) {
|
|
|
1979
2057
|
}
|
|
1980
2058
|
});
|
|
1981
2059
|
}); }, children: [jsxRuntimeExports.jsx(Mail, { className: "w-5 h-5" }), jsxRuntimeExports.jsxs("div", { className: "text-left", children: [jsxRuntimeExports.jsx("div", { className: "font-medium", children: "Email OTP" }), jsxRuntimeExports.jsx("div", { className: "text-sm text-gray-500", children: "Send code to your email" })] })] }), jsxRuntimeExports.jsxs(Button, { variant: "outline", className: "w-full flex items-center justify-start gap-3 p-4 h-auto border-2 hover:border-[#506f4a] hover:bg-[#506f4a]/5 transition-all", onClick: function () {
|
|
1982
|
-
resetAttempts();
|
|
1983
2060
|
setAuthType("AuthenticatorCode");
|
|
1984
2061
|
setOtpVisible(true);
|
|
1985
2062
|
}, children: [jsxRuntimeExports.jsx("img", { src: MicrosoftAuthenticatorImg, alt: "Authenticator", className: "rounded-full", width: 24, height: 24, onError: function () { return jsxRuntimeExports.jsx(Shield, {}); } }), jsxRuntimeExports.jsxs("div", { className: "text-left", children: [jsxRuntimeExports.jsx("div", { className: "font-medium", children: "Authenticator App" }), jsxRuntimeExports.jsx("div", { className: "text-sm text-gray-500", children: "Use Authenticator App" })] })] }), usePassKey && (jsxRuntimeExports.jsxs(Button, { variant: "outline", className: "w-full flex items-center justify-start gap-3 p-4 h-auto border-2 hover:border-[#506f4a] hover:bg-[#506f4a]/5 transition-all",
|
|
@@ -1988,7 +2065,7 @@ var MFAOptions = function (_a) {
|
|
|
1988
2065
|
// setAuthType("AuthenticatorCode");
|
|
1989
2066
|
// setOtpVisible(true);
|
|
1990
2067
|
// }}
|
|
1991
|
-
onClick: handleFIDOLogin, disabled: context.isLoading, children: [jsxRuntimeExports.jsx(
|
|
2068
|
+
onClick: handleFIDOLogin, disabled: context.isLoading, children: [jsxRuntimeExports.jsx(KeyIcon, { className: "text-[#506f4a]", size: 48 }), jsxRuntimeExports.jsxs("div", { className: "text-left", children: [jsxRuntimeExports.jsx("div", { className: "font-medium", children: "Continue with Passkey" }), jsxRuntimeExports.jsx("div", { className: "text-sm text-gray-500", children: "Passkey" })] })] }))] })] }));
|
|
1992
2069
|
}
|
|
1993
2070
|
else if (authType === "EmailOTP") {
|
|
1994
2071
|
content = (jsxRuntimeExports.jsx(Dialog, { open: otpVisible, onOpenChange: function () {
|
|
@@ -2020,14 +2097,13 @@ var credentialsSchema = z.object({
|
|
|
2020
2097
|
password: z.string().min(1, "Password is required"),
|
|
2021
2098
|
});
|
|
2022
2099
|
var ADLoginModal = function (_a) {
|
|
2023
|
-
var open = _a.open, onOpenChange = _a.onOpenChange, onLogin = _a.onLogin;
|
|
2100
|
+
var open = _a.open, isLoading = _a.isLoading, setIsLoading = _a.setIsLoading, onOpenChange = _a.onOpenChange, onLogin = _a.onLogin;
|
|
2024
2101
|
var _b = useState("credentials"), step = _b[0], setStep = _b[1];
|
|
2025
2102
|
var _c = useState({
|
|
2026
2103
|
username: "",
|
|
2027
2104
|
password: "",
|
|
2028
2105
|
}), credentials = _c[0], setCredentials = _c[1];
|
|
2029
2106
|
var _d = useState(""), mfaCode = _d[0], setMfaCode = _d[1];
|
|
2030
|
-
var _e = useState(false), isLoading = _e[0], setIsLoading = _e[1];
|
|
2031
2107
|
var form = useForm({
|
|
2032
2108
|
resolver: a$1(credentialsSchema),
|
|
2033
2109
|
defaultValues: { username: "", password: "" },
|
|
@@ -2077,21 +2153,45 @@ var ADLoginModal = function (_a) {
|
|
|
2077
2153
|
form.reset();
|
|
2078
2154
|
setMfaCode("");
|
|
2079
2155
|
};
|
|
2080
|
-
return (jsxRuntimeExports.jsx(Dialog, { open: open, onOpenChange: handleClose, children: jsxRuntimeExports.jsxs(DialogContent, { className: "
|
|
2156
|
+
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(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) {
|
|
2081
2157
|
var field = _a.field;
|
|
2082
|
-
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, {})] }));
|
|
2158
|
+
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, {})] }));
|
|
2083
2159
|
} }), jsxRuntimeExports.jsx(FormField, { control: form.control, name: "password", render: function (_a) {
|
|
2084
2160
|
var field = _a.field;
|
|
2085
|
-
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, {})] }));
|
|
2161
|
+
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, {})] }));
|
|
2086
2162
|
} }), 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(Loader2, { className: "w-4 h-4 animate-spin" }), jsxRuntimeExports.jsx("span", { children: "Verifying..." })] }))] }))] }) }));
|
|
2087
2163
|
};
|
|
2088
2164
|
|
|
2089
2165
|
var DefaultLoginPage = function (_a) {
|
|
2090
|
-
var usePassKey = _a.usePassKey, MFAEndpoints = _a.MFAEndpoints, PassKeysRegisterProps = _a.PassKeysRegisterProps;
|
|
2166
|
+
var usePassKey = _a.usePassKey, useADLogin = _a.useADLogin, MFAEndpoints = _a.MFAEndpoints, CredentialsAuthEndpoint = _a.CredentialsAuthEndpoint, PassKeysRegisterProps = _a.PassKeysRegisterProps;
|
|
2167
|
+
var cardVariants = {
|
|
2168
|
+
hidden: { opacity: 0, scale: 0.8, y: 50 },
|
|
2169
|
+
visible: {
|
|
2170
|
+
opacity: 1,
|
|
2171
|
+
scale: 1,
|
|
2172
|
+
y: 0,
|
|
2173
|
+
transition: { type: "spring", duration: 0.6 },
|
|
2174
|
+
},
|
|
2175
|
+
exit: { opacity: 0, scale: 0.8, y: -50, transition: { duration: 0.3 } },
|
|
2176
|
+
};
|
|
2091
2177
|
var context = useCAMSContext();
|
|
2092
2178
|
var login = context.login, isLoading = context.isLoading, authMode = context.authMode;
|
|
2093
2179
|
var _b = useState(false), showADModal = _b[0], setShowADModal = _b[1];
|
|
2094
2180
|
var register = useWebAuthn().register;
|
|
2181
|
+
var _c = useCredentialsHandler(function (state, data) { return __awaiter(void 0, void 0, void 0, function () {
|
|
2182
|
+
return __generator(this, function (_a) {
|
|
2183
|
+
console.log(data);
|
|
2184
|
+
if (state && data) {
|
|
2185
|
+
context.isAuthenticated = true;
|
|
2186
|
+
context.requiresMFA = false;
|
|
2187
|
+
context.setUserProfile({
|
|
2188
|
+
type: "AUTH_SUCCESS",
|
|
2189
|
+
userProfile: __assign({}, data),
|
|
2190
|
+
});
|
|
2191
|
+
}
|
|
2192
|
+
return [2 /*return*/];
|
|
2193
|
+
});
|
|
2194
|
+
}); }), handleSubmitCredentials = _c.handleSubmitCredentials, isCredAuthLoading = _c.loading, setIsCredAuthLoading = _c.setLoading;
|
|
2095
2195
|
var handleMSALLogin = function () {
|
|
2096
2196
|
if (authMode === "MSAL") {
|
|
2097
2197
|
login();
|
|
@@ -2101,16 +2201,6 @@ var DefaultLoginPage = function (_a) {
|
|
|
2101
2201
|
console.warn("Regular CAMS login requires configuration");
|
|
2102
2202
|
}
|
|
2103
2203
|
};
|
|
2104
|
-
var cardVariants = {
|
|
2105
|
-
hidden: { opacity: 0, scale: 0.8, y: 50 },
|
|
2106
|
-
visible: {
|
|
2107
|
-
opacity: 1,
|
|
2108
|
-
scale: 1,
|
|
2109
|
-
y: 0,
|
|
2110
|
-
transition: { type: "spring", duration: 0.6 },
|
|
2111
|
-
},
|
|
2112
|
-
exit: { opacity: 0, scale: 0.8, y: -50, transition: { duration: 0.3 } },
|
|
2113
|
-
};
|
|
2114
2204
|
var handleRegister = function (data) { return __awaiter(void 0, void 0, void 0, function () {
|
|
2115
2205
|
var options, attestationResponse, error_1;
|
|
2116
2206
|
return __generator(this, function (_a) {
|
|
@@ -2119,12 +2209,7 @@ var DefaultLoginPage = function (_a) {
|
|
|
2119
2209
|
_a.trys.push([0, 4, , 5]);
|
|
2120
2210
|
// 1. Fetch challenge from your server
|
|
2121
2211
|
console.log("Requesting registration challenge from server...");
|
|
2122
|
-
return [4 /*yield*/,
|
|
2123
|
-
headers: {
|
|
2124
|
-
"X-DEVICE-ID": GenerateDeviceId(),
|
|
2125
|
-
"X-API-VERSION": "1.0",
|
|
2126
|
-
},
|
|
2127
|
-
})];
|
|
2212
|
+
return [4 /*yield*/, axiosInstance.post(MFAEndpoints.RegisterNewChallenge, __assign({}, data))];
|
|
2128
2213
|
case 1:
|
|
2129
2214
|
options = (_a.sent()).data;
|
|
2130
2215
|
console.log("Received challenge:", options);
|
|
@@ -2136,13 +2221,7 @@ var DefaultLoginPage = function (_a) {
|
|
|
2136
2221
|
console.log("Passkey created on client:", attestationResponse);
|
|
2137
2222
|
// 3. Send the response back to the server for verification
|
|
2138
2223
|
console.log("Sending attestation to server for verification...");
|
|
2139
|
-
return [4 /*yield*/,
|
|
2140
|
-
headers: {
|
|
2141
|
-
"X-DEVICE-ID": GenerateDeviceId(),
|
|
2142
|
-
"X-API-VERSION": "1.0",
|
|
2143
|
-
},
|
|
2144
|
-
withCredentials: true, // credentials: 'include'
|
|
2145
|
-
})];
|
|
2224
|
+
return [4 /*yield*/, axiosInstance.post(MFAEndpoints.RegisterVerify + "?username=".concat(data.username), attestationResponse)];
|
|
2146
2225
|
case 3:
|
|
2147
2226
|
_a.sent();
|
|
2148
2227
|
toast.success("✅ Registration successful! Passkey created.");
|
|
@@ -2160,11 +2239,15 @@ var DefaultLoginPage = function (_a) {
|
|
|
2160
2239
|
// variant="outline"
|
|
2161
2240
|
, {
|
|
2162
2241
|
// variant="outline"
|
|
2163
|
-
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" })] }),
|
|
2242
|
+
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(KeyIcon, { className: "text-[#506f4a]", size: 64 }), jsxRuntimeExports.jsx("span", { children: isLoading
|
|
2243
|
+
? "Logging in..."
|
|
2244
|
+
: "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(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(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) {
|
|
2164
2245
|
var username = _b.username, password = _b.password, MFACode = _b.MFACode;
|
|
2165
2246
|
return __generator(this, function (_c) {
|
|
2166
2247
|
// Implement your AD login logic here
|
|
2167
2248
|
console.log("AD Login:", { username: username, password: password, MFACode: MFACode });
|
|
2249
|
+
// Example: await adLoginService(username, password, mfaCode);
|
|
2250
|
+
handleSubmitCredentials(CredentialsAuthEndpoint !== null && CredentialsAuthEndpoint !== void 0 ? CredentialsAuthEndpoint : "/api/auth/validate", { username: username, password: password, MFACode: MFACode }, context.appCode);
|
|
2168
2251
|
return [2 /*return*/];
|
|
2169
2252
|
});
|
|
2170
2253
|
}); } })] }));
|
|
@@ -2187,7 +2270,7 @@ var MFAGate = function (_a) {
|
|
|
2187
2270
|
// loginComponent: LoginComponent = DefaultLoginPage,
|
|
2188
2271
|
_c = _a.usePassKey,
|
|
2189
2272
|
// loginComponent: LoginComponent = DefaultLoginPage,
|
|
2190
|
-
usePassKey = _c === void 0 ? false : _c, PassKeysRegisterProps = _a.PassKeysRegisterProps, MFAEndpoints = _a.MFAEndpoints;
|
|
2273
|
+
usePassKey = _c === void 0 ? false : _c, _d = _a.useADLogin, useADLogin = _d === void 0 ? false : _d, CredentialsAuthEndpoint = _a.CredentialsAuthEndpoint, PassKeysRegisterProps = _a.PassKeysRegisterProps, MFAEndpoints = _a.MFAEndpoints;
|
|
2191
2274
|
var context = useCAMSContext();
|
|
2192
2275
|
var validatedMFAEndpoints = useMemo(function () {
|
|
2193
2276
|
var parsed = MFAEndpointsSchema.safeParse(MFAEndpoints);
|
|
@@ -2211,9 +2294,10 @@ var MFAGate = function (_a) {
|
|
|
2211
2294
|
}
|
|
2212
2295
|
});
|
|
2213
2296
|
}); }, [context.logout]);
|
|
2214
|
-
|
|
2297
|
+
if (useADLogin && !CredentialsAuthEndpoint)
|
|
2298
|
+
return jsxRuntimeExports.jsx(ErrorFallback, { message: "Invalid AD Login Configuration." });
|
|
2215
2299
|
if (!validatedMFAEndpoints)
|
|
2216
|
-
return jsxRuntimeExports.jsx(ErrorFallback, { message: "Invalid MFA
|
|
2300
|
+
return jsxRuntimeExports.jsx(ErrorFallback, { message: "Invalid MFA Configuration." });
|
|
2217
2301
|
if (context.authMode !== "MSAL")
|
|
2218
2302
|
return jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: children });
|
|
2219
2303
|
if (context.isLoading)
|
|
@@ -2222,7 +2306,7 @@ var MFAGate = function (_a) {
|
|
|
2222
2306
|
return (jsxRuntimeExports.jsx(MFAOptions, { MFAEndpoints: validatedMFAEndpoints, usePassKey: usePassKey, onComplete: handleComplete, onAuthFailed: handleAuthFailed }));
|
|
2223
2307
|
}
|
|
2224
2308
|
if (!context.isAuthenticated) {
|
|
2225
|
-
return (jsxRuntimeExports.jsx(DefaultLoginPage, { usePassKey: usePassKey, MFAEndpoints: MFAEndpoints, PassKeysRegisterProps: PassKeysRegisterProps }));
|
|
2309
|
+
return (jsxRuntimeExports.jsx(DefaultLoginPage, { usePassKey: usePassKey, useADLogin: useADLogin, MFAEndpoints: MFAEndpoints, PassKeysRegisterProps: PassKeysRegisterProps, CredentialsAuthEndpoint: CredentialsAuthEndpoint }));
|
|
2226
2310
|
}
|
|
2227
2311
|
return jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: children });
|
|
2228
2312
|
};
|