@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
|
@@ -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
|
@@ -18,6 +18,7 @@ var DialogPrimitive = require('@radix-ui/react-dialog');
|
|
|
18
18
|
var sonner = require('sonner');
|
|
19
19
|
var framerMotion = require('framer-motion');
|
|
20
20
|
var axios = require('axios');
|
|
21
|
+
var https = require('https');
|
|
21
22
|
|
|
22
23
|
function _interopNamespaceDefault(e) {
|
|
23
24
|
var n = Object.create(null);
|
|
@@ -332,7 +333,6 @@ function useCAMSMSALAuth(options) {
|
|
|
332
333
|
setMfaAuthenticator(authenticator);
|
|
333
334
|
setRequiresMFA(true);
|
|
334
335
|
}
|
|
335
|
-
camsSdk.Logger.debug("App Code", { ">>>": options.appCode });
|
|
336
336
|
}
|
|
337
337
|
else {
|
|
338
338
|
localStorage.removeItem(storageKey);
|
|
@@ -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
|
}
|
|
@@ -1715,7 +1723,7 @@ styleInject(css_248z);
|
|
|
1715
1723
|
|
|
1716
1724
|
var LoadingSpinner = function (_a) {
|
|
1717
1725
|
var loadingText = _a.loadingText;
|
|
1718
|
-
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..." }))] }));
|
|
1726
|
+
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..." }))] }));
|
|
1719
1727
|
};
|
|
1720
1728
|
|
|
1721
1729
|
var AuthSuccessAnimation = function (_a) {
|
|
@@ -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,31 @@ 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
|
+
};
|
|
1777
|
+
|
|
1778
|
+
// Creates an Axios instance with a base URL determined by the environment (production or development).
|
|
1779
|
+
var axiosInstance = axios.create({
|
|
1780
|
+
httpsAgent: new https.Agent({ rejectUnauthorized: false }),
|
|
1781
|
+
headers: __assign({ "Content-Type": "application/json" }, APIHeaders),
|
|
1782
|
+
});
|
|
1783
|
+
// Intercepts outgoing requests to add authorization token, version header, and timeout settings.
|
|
1784
|
+
axiosInstance.interceptors.request.use(function (config) {
|
|
1785
|
+
var _a;
|
|
1786
|
+
config.timeout = Number((_a = process.env.NEXT_PUBLIC_API_TIMEOUT) !== null && _a !== void 0 ? _a : 605000);
|
|
1787
|
+
config.timeoutErrorMessage = "Operation Timed Out"; // Custom error message for timeouts.
|
|
1788
|
+
return config; // Returns the modified request configuration.
|
|
1789
|
+
}, function (axiosError) {
|
|
1790
|
+
var _a, _b;
|
|
1791
|
+
// Handles request errors.
|
|
1792
|
+
return {
|
|
1793
|
+
status: (_a = axiosError.response) === null || _a === void 0 ? void 0 : _a.status, // Extracts HTTP status from the error response.
|
|
1794
|
+
message: axiosError.message, // Extracts the error message.
|
|
1795
|
+
data: (_b = axiosError.response) === null || _b === void 0 ? void 0 : _b.data, // Extracts response data from the error.
|
|
1796
|
+
};
|
|
1797
|
+
});
|
|
1765
1798
|
|
|
1766
1799
|
var MAX_ATTEMPTS = 3;
|
|
1767
1800
|
var useOTPHandler = function (_a) {
|
|
@@ -1788,18 +1821,13 @@ var useOTPHandler = function (_a) {
|
|
|
1788
1821
|
setAttemptCount(currentAttempt);
|
|
1789
1822
|
if (authenticationType === null)
|
|
1790
1823
|
return [2 /*return*/, false];
|
|
1791
|
-
return [4 /*yield*/,
|
|
1824
|
+
return [4 /*yield*/, axiosInstance.post(MFAEndpoint || "/api/auth/verify-mfa", {
|
|
1792
1825
|
provider: provider,
|
|
1793
1826
|
accessToken: accessToken,
|
|
1794
1827
|
idToken: idToken,
|
|
1795
1828
|
authenticationType: authenticationType,
|
|
1796
1829
|
MFACode: authenticationValue,
|
|
1797
1830
|
appCode: appCode,
|
|
1798
|
-
}, {
|
|
1799
|
-
headers: {
|
|
1800
|
-
"X-Device-ID": GenerateDeviceId(),
|
|
1801
|
-
},
|
|
1802
|
-
timeout: 605000,
|
|
1803
1831
|
})];
|
|
1804
1832
|
case 2:
|
|
1805
1833
|
response = (_a.sent()).data;
|
|
@@ -1861,6 +1889,75 @@ var useOTPHandler = function (_a) {
|
|
|
1861
1889
|
remainingAttempts: MAX_ATTEMPTS - attemptCount,
|
|
1862
1890
|
};
|
|
1863
1891
|
};
|
|
1892
|
+
var useCredentialsHandler = function (onAuthComplete) {
|
|
1893
|
+
var _a = React.useState(false), loading = _a[0], setLoading = _a[1];
|
|
1894
|
+
var _b = React.useState(0), attemptCount = _b[0], setAttemptCount = _b[1];
|
|
1895
|
+
var _c = React.useState(false), isMaxAttemptsReached = _c[0], setIsMaxAttemptsReached = _c[1];
|
|
1896
|
+
var handleSubmitCredentials = React.useMemo(function () {
|
|
1897
|
+
return function (CredAuthEndpoint, credentials, appCode) { return __awaiter(void 0, void 0, void 0, function () {
|
|
1898
|
+
var currentAttempt, response, error_2, currentAttempt;
|
|
1899
|
+
return __generator(this, function (_a) {
|
|
1900
|
+
switch (_a.label) {
|
|
1901
|
+
case 0:
|
|
1902
|
+
_a.trys.push([0, 2, 3, 4]);
|
|
1903
|
+
setLoading(true);
|
|
1904
|
+
currentAttempt = attemptCount + 1;
|
|
1905
|
+
setAttemptCount(currentAttempt);
|
|
1906
|
+
return [4 /*yield*/, axiosInstance.post(CredAuthEndpoint, {
|
|
1907
|
+
username: credentials.username,
|
|
1908
|
+
password: credentials.password,
|
|
1909
|
+
MFACode: credentials.MFACode,
|
|
1910
|
+
appCode: appCode,
|
|
1911
|
+
})];
|
|
1912
|
+
case 1:
|
|
1913
|
+
response = (_a.sent()).data;
|
|
1914
|
+
if (response) {
|
|
1915
|
+
onAuthComplete(true, response);
|
|
1916
|
+
return [2 /*return*/, true];
|
|
1917
|
+
}
|
|
1918
|
+
else {
|
|
1919
|
+
if (currentAttempt >= MAX_ATTEMPTS) {
|
|
1920
|
+
setIsMaxAttemptsReached(true);
|
|
1921
|
+
onAuthComplete(false, {
|
|
1922
|
+
message: "Maximum attempts reached",
|
|
1923
|
+
});
|
|
1924
|
+
}
|
|
1925
|
+
else {
|
|
1926
|
+
onAuthComplete(false, response.response.data);
|
|
1927
|
+
}
|
|
1928
|
+
return [2 /*return*/, false];
|
|
1929
|
+
}
|
|
1930
|
+
case 2:
|
|
1931
|
+
error_2 = _a.sent();
|
|
1932
|
+
console.error(error_2);
|
|
1933
|
+
currentAttempt = attemptCount + 1;
|
|
1934
|
+
if (currentAttempt >= MAX_ATTEMPTS) {
|
|
1935
|
+
setIsMaxAttemptsReached(true);
|
|
1936
|
+
onAuthComplete(false, error_2.response.data);
|
|
1937
|
+
}
|
|
1938
|
+
else {
|
|
1939
|
+
onAuthComplete(false, error_2.response.data);
|
|
1940
|
+
}
|
|
1941
|
+
onAuthComplete(false, error_2.response.data);
|
|
1942
|
+
return [2 /*return*/, false];
|
|
1943
|
+
case 3:
|
|
1944
|
+
setLoading(false);
|
|
1945
|
+
return [7 /*endfinally*/];
|
|
1946
|
+
case 4: return [2 /*return*/];
|
|
1947
|
+
}
|
|
1948
|
+
});
|
|
1949
|
+
}); };
|
|
1950
|
+
}, []);
|
|
1951
|
+
return {
|
|
1952
|
+
handleSubmitCredentials: handleSubmitCredentials,
|
|
1953
|
+
loading: loading,
|
|
1954
|
+
setLoading: setLoading,
|
|
1955
|
+
attemptCount: attemptCount,
|
|
1956
|
+
isMaxAttemptsReached: isMaxAttemptsReached,
|
|
1957
|
+
// resetAttempts,
|
|
1958
|
+
remainingAttempts: MAX_ATTEMPTS - attemptCount,
|
|
1959
|
+
};
|
|
1960
|
+
};
|
|
1864
1961
|
|
|
1865
1962
|
var MFAOptions = function (_a) {
|
|
1866
1963
|
var onComplete = _a.onComplete, onAuthFailed = _a.onAuthFailed, MFAEndpoints = _a.MFAEndpoints, usePassKey = _a.usePassKey;
|
|
@@ -1879,50 +1976,31 @@ var MFAOptions = function (_a) {
|
|
|
1879
1976
|
var authenticate = useWebAuthn().authenticate;
|
|
1880
1977
|
var handleFIDOLogin = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
1881
1978
|
var options, assertionResponse, error_1;
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
switch (_o.label) {
|
|
1979
|
+
return __generator(this, function (_a) {
|
|
1980
|
+
switch (_a.label) {
|
|
1885
1981
|
case 0:
|
|
1886
|
-
|
|
1982
|
+
_a.trys.push([0, 4, , 5]);
|
|
1887
1983
|
// 1. Fetch authentication challenge from your server
|
|
1888
1984
|
console.log("Requesting authentication challenge from server...");
|
|
1889
|
-
return [4 /*yield*/,
|
|
1890
|
-
headers: {
|
|
1891
|
-
"X-DEVICE-ID": GenerateDeviceId(),
|
|
1892
|
-
"X-API-VERSION": "1.0",
|
|
1893
|
-
},
|
|
1894
|
-
})];
|
|
1985
|
+
return [4 /*yield*/, axiosInstance.post(MFAEndpoints.RetrieveAuthChallenge, {})];
|
|
1895
1986
|
case 1:
|
|
1896
|
-
options = (
|
|
1987
|
+
options = (_a.sent()).data;
|
|
1897
1988
|
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
1989
|
// 2. Call the SDK to trigger the browser's passkey authentication UI
|
|
1903
1990
|
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" }) }))];
|
|
1991
|
+
return [4 /*yield*/, authenticate(__assign(__assign({}, options), { userVerification: "discouraged" }))];
|
|
1908
1992
|
case 2:
|
|
1909
|
-
assertionResponse =
|
|
1993
|
+
assertionResponse = _a.sent();
|
|
1910
1994
|
console.log("Authentication assertion received from client:", assertionResponse);
|
|
1911
1995
|
// 3. Send the assertion back to the server for verification
|
|
1912
1996
|
console.log("Sending assertion to server for verification...");
|
|
1913
|
-
return [4 /*yield*/,
|
|
1914
|
-
headers: {
|
|
1915
|
-
"X-DEVICE-ID": GenerateDeviceId(),
|
|
1916
|
-
"X-API-VERSION": "1.0",
|
|
1917
|
-
},
|
|
1918
|
-
withCredentials: true, // credentials: 'include'
|
|
1919
|
-
})];
|
|
1997
|
+
return [4 /*yield*/, axiosInstance.post(MFAEndpoints.AuthChallengeVerify, assertionResponse)];
|
|
1920
1998
|
case 3:
|
|
1921
|
-
|
|
1999
|
+
_a.sent();
|
|
1922
2000
|
sonner.toast.success("🔑 Sign-in successful!");
|
|
1923
2001
|
return [3 /*break*/, 5];
|
|
1924
2002
|
case 4:
|
|
1925
|
-
error_1 =
|
|
2003
|
+
error_1 = _a.sent();
|
|
1926
2004
|
console.error("Authentication failed:", error_1);
|
|
1927
2005
|
sonner.toast.error("❌ Could not sign in.");
|
|
1928
2006
|
return [3 /*break*/, 5];
|
|
@@ -1983,7 +2061,7 @@ var MFAOptions = function (_a) {
|
|
|
1983
2061
|
return __generator(this, function (_a) {
|
|
1984
2062
|
switch (_a.label) {
|
|
1985
2063
|
case 0:
|
|
1986
|
-
resetAttempts();
|
|
2064
|
+
// resetAttempts();
|
|
1987
2065
|
setAuthType("EmailOTP");
|
|
1988
2066
|
setOtpVisible(true);
|
|
1989
2067
|
if (!sendEmailOTP) return [3 /*break*/, 2];
|
|
@@ -2000,7 +2078,6 @@ var MFAOptions = function (_a) {
|
|
|
2000
2078
|
}
|
|
2001
2079
|
});
|
|
2002
2080
|
}); }, children: [jsxRuntimeExports.jsx(lucideReact.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 () {
|
|
2003
|
-
resetAttempts();
|
|
2004
2081
|
setAuthType("AuthenticatorCode");
|
|
2005
2082
|
setOtpVisible(true);
|
|
2006
2083
|
}, children: [jsxRuntimeExports.jsx("img", { src: MicrosoftAuthenticatorImg, alt: "Authenticator", className: "rounded-full", width: 24, height: 24, onError: function () { return jsxRuntimeExports.jsx(lucideReact.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",
|
|
@@ -2009,7 +2086,7 @@ var MFAOptions = function (_a) {
|
|
|
2009
2086
|
// setAuthType("AuthenticatorCode");
|
|
2010
2087
|
// setOtpVisible(true);
|
|
2011
2088
|
// }}
|
|
2012
|
-
onClick: handleFIDOLogin, disabled: context.isLoading, children: [jsxRuntimeExports.jsx(
|
|
2089
|
+
onClick: handleFIDOLogin, disabled: context.isLoading, children: [jsxRuntimeExports.jsx(lucideReact.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" })] })] }))] })] }));
|
|
2013
2090
|
}
|
|
2014
2091
|
else if (authType === "EmailOTP") {
|
|
2015
2092
|
content = (jsxRuntimeExports.jsx(Dialog, { open: otpVisible, onOpenChange: function () {
|
|
@@ -2041,14 +2118,13 @@ var credentialsSchema = z.z.object({
|
|
|
2041
2118
|
password: z.z.string().min(1, "Password is required"),
|
|
2042
2119
|
});
|
|
2043
2120
|
var ADLoginModal = function (_a) {
|
|
2044
|
-
var open = _a.open, onOpenChange = _a.onOpenChange, onLogin = _a.onLogin;
|
|
2121
|
+
var open = _a.open, isLoading = _a.isLoading, setIsLoading = _a.setIsLoading, onOpenChange = _a.onOpenChange, onLogin = _a.onLogin;
|
|
2045
2122
|
var _b = React.useState("credentials"), step = _b[0], setStep = _b[1];
|
|
2046
2123
|
var _c = React.useState({
|
|
2047
2124
|
username: "",
|
|
2048
2125
|
password: "",
|
|
2049
2126
|
}), credentials = _c[0], setCredentials = _c[1];
|
|
2050
2127
|
var _d = React.useState(""), mfaCode = _d[0], setMfaCode = _d[1];
|
|
2051
|
-
var _e = React.useState(false), isLoading = _e[0], setIsLoading = _e[1];
|
|
2052
2128
|
var form = reactHookForm.useForm({
|
|
2053
2129
|
resolver: a$1(credentialsSchema),
|
|
2054
2130
|
defaultValues: { username: "", password: "" },
|
|
@@ -2098,21 +2174,45 @@ var ADLoginModal = function (_a) {
|
|
|
2098
2174
|
form.reset();
|
|
2099
2175
|
setMfaCode("");
|
|
2100
2176
|
};
|
|
2101
|
-
return (jsxRuntimeExports.jsx(Dialog, { open: open, onOpenChange: handleClose, children: jsxRuntimeExports.jsxs(DialogContent, { className: "
|
|
2177
|
+
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) {
|
|
2102
2178
|
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, {})] }));
|
|
2179
|
+
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
2180
|
} }), jsxRuntimeExports.jsx(FormField, { control: form.control, name: "password", render: function (_a) {
|
|
2105
2181
|
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, {})] }));
|
|
2182
|
+
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
2183
|
} }), 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
2184
|
};
|
|
2109
2185
|
|
|
2110
2186
|
var DefaultLoginPage = function (_a) {
|
|
2111
|
-
var usePassKey = _a.usePassKey, MFAEndpoints = _a.MFAEndpoints, PassKeysRegisterProps = _a.PassKeysRegisterProps;
|
|
2187
|
+
var usePassKey = _a.usePassKey, useADLogin = _a.useADLogin, MFAEndpoints = _a.MFAEndpoints, CredentialsAuthEndpoint = _a.CredentialsAuthEndpoint, PassKeysRegisterProps = _a.PassKeysRegisterProps;
|
|
2188
|
+
var cardVariants = {
|
|
2189
|
+
hidden: { opacity: 0, scale: 0.8, y: 50 },
|
|
2190
|
+
visible: {
|
|
2191
|
+
opacity: 1,
|
|
2192
|
+
scale: 1,
|
|
2193
|
+
y: 0,
|
|
2194
|
+
transition: { type: "spring", duration: 0.6 },
|
|
2195
|
+
},
|
|
2196
|
+
exit: { opacity: 0, scale: 0.8, y: -50, transition: { duration: 0.3 } },
|
|
2197
|
+
};
|
|
2112
2198
|
var context = useCAMSContext();
|
|
2113
2199
|
var login = context.login, isLoading = context.isLoading, authMode = context.authMode;
|
|
2114
2200
|
var _b = React.useState(false), showADModal = _b[0], setShowADModal = _b[1];
|
|
2115
2201
|
var register = useWebAuthn().register;
|
|
2202
|
+
var _c = useCredentialsHandler(function (state, data) { return __awaiter(void 0, void 0, void 0, function () {
|
|
2203
|
+
return __generator(this, function (_a) {
|
|
2204
|
+
console.log(data);
|
|
2205
|
+
if (state && data) {
|
|
2206
|
+
context.isAuthenticated = true;
|
|
2207
|
+
context.requiresMFA = false;
|
|
2208
|
+
context.setUserProfile({
|
|
2209
|
+
type: "AUTH_SUCCESS",
|
|
2210
|
+
userProfile: __assign({}, data),
|
|
2211
|
+
});
|
|
2212
|
+
}
|
|
2213
|
+
return [2 /*return*/];
|
|
2214
|
+
});
|
|
2215
|
+
}); }), handleSubmitCredentials = _c.handleSubmitCredentials, isCredAuthLoading = _c.loading, setIsCredAuthLoading = _c.setLoading;
|
|
2116
2216
|
var handleMSALLogin = function () {
|
|
2117
2217
|
if (authMode === "MSAL") {
|
|
2118
2218
|
login();
|
|
@@ -2122,16 +2222,6 @@ var DefaultLoginPage = function (_a) {
|
|
|
2122
2222
|
console.warn("Regular CAMS login requires configuration");
|
|
2123
2223
|
}
|
|
2124
2224
|
};
|
|
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
2225
|
var handleRegister = function (data) { return __awaiter(void 0, void 0, void 0, function () {
|
|
2136
2226
|
var options, attestationResponse, error_1;
|
|
2137
2227
|
return __generator(this, function (_a) {
|
|
@@ -2140,12 +2230,7 @@ var DefaultLoginPage = function (_a) {
|
|
|
2140
2230
|
_a.trys.push([0, 4, , 5]);
|
|
2141
2231
|
// 1. Fetch challenge from your server
|
|
2142
2232
|
console.log("Requesting registration challenge from server...");
|
|
2143
|
-
return [4 /*yield*/,
|
|
2144
|
-
headers: {
|
|
2145
|
-
"X-DEVICE-ID": GenerateDeviceId(),
|
|
2146
|
-
"X-API-VERSION": "1.0",
|
|
2147
|
-
},
|
|
2148
|
-
})];
|
|
2233
|
+
return [4 /*yield*/, axiosInstance.post(MFAEndpoints.RegisterNewChallenge, __assign({}, data))];
|
|
2149
2234
|
case 1:
|
|
2150
2235
|
options = (_a.sent()).data;
|
|
2151
2236
|
console.log("Received challenge:", options);
|
|
@@ -2157,13 +2242,7 @@ var DefaultLoginPage = function (_a) {
|
|
|
2157
2242
|
console.log("Passkey created on client:", attestationResponse);
|
|
2158
2243
|
// 3. Send the response back to the server for verification
|
|
2159
2244
|
console.log("Sending attestation to server for verification...");
|
|
2160
|
-
return [4 /*yield*/,
|
|
2161
|
-
headers: {
|
|
2162
|
-
"X-DEVICE-ID": GenerateDeviceId(),
|
|
2163
|
-
"X-API-VERSION": "1.0",
|
|
2164
|
-
},
|
|
2165
|
-
withCredentials: true, // credentials: 'include'
|
|
2166
|
-
})];
|
|
2245
|
+
return [4 /*yield*/, axiosInstance.post(MFAEndpoints.RegisterVerify + "?username=".concat(data.username), attestationResponse)];
|
|
2167
2246
|
case 3:
|
|
2168
2247
|
_a.sent();
|
|
2169
2248
|
sonner.toast.success("✅ Registration successful! Passkey created.");
|
|
@@ -2181,11 +2260,15 @@ var DefaultLoginPage = function (_a) {
|
|
|
2181
2260
|
// variant="outline"
|
|
2182
2261
|
, {
|
|
2183
2262
|
// 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" })] }),
|
|
2263
|
+
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
|
|
2264
|
+
? "Logging in..."
|
|
2265
|
+
: "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
2266
|
var username = _b.username, password = _b.password, MFACode = _b.MFACode;
|
|
2186
2267
|
return __generator(this, function (_c) {
|
|
2187
2268
|
// Implement your AD login logic here
|
|
2188
2269
|
console.log("AD Login:", { username: username, password: password, MFACode: MFACode });
|
|
2270
|
+
// Example: await adLoginService(username, password, mfaCode);
|
|
2271
|
+
handleSubmitCredentials(CredentialsAuthEndpoint !== null && CredentialsAuthEndpoint !== void 0 ? CredentialsAuthEndpoint : "/api/auth/validate", { username: username, password: password, MFACode: MFACode }, context.appCode);
|
|
2189
2272
|
return [2 /*return*/];
|
|
2190
2273
|
});
|
|
2191
2274
|
}); } })] }));
|
|
@@ -2208,7 +2291,7 @@ var MFAGate = function (_a) {
|
|
|
2208
2291
|
// loginComponent: LoginComponent = DefaultLoginPage,
|
|
2209
2292
|
_c = _a.usePassKey,
|
|
2210
2293
|
// loginComponent: LoginComponent = DefaultLoginPage,
|
|
2211
|
-
usePassKey = _c === void 0 ? false : _c, PassKeysRegisterProps = _a.PassKeysRegisterProps, MFAEndpoints = _a.MFAEndpoints;
|
|
2294
|
+
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
2295
|
var context = useCAMSContext();
|
|
2213
2296
|
var validatedMFAEndpoints = React.useMemo(function () {
|
|
2214
2297
|
var parsed = MFAEndpointsSchema.safeParse(MFAEndpoints);
|
|
@@ -2232,9 +2315,10 @@ var MFAGate = function (_a) {
|
|
|
2232
2315
|
}
|
|
2233
2316
|
});
|
|
2234
2317
|
}); }, [context.logout]);
|
|
2235
|
-
|
|
2318
|
+
if (useADLogin && !CredentialsAuthEndpoint)
|
|
2319
|
+
return jsxRuntimeExports.jsx(ErrorFallback, { message: "Invalid AD Login Configuration." });
|
|
2236
2320
|
if (!validatedMFAEndpoints)
|
|
2237
|
-
return jsxRuntimeExports.jsx(ErrorFallback, { message: "Invalid MFA
|
|
2321
|
+
return jsxRuntimeExports.jsx(ErrorFallback, { message: "Invalid MFA Configuration." });
|
|
2238
2322
|
if (context.authMode !== "MSAL")
|
|
2239
2323
|
return jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: children });
|
|
2240
2324
|
if (context.isLoading)
|
|
@@ -2243,7 +2327,7 @@ var MFAGate = function (_a) {
|
|
|
2243
2327
|
return (jsxRuntimeExports.jsx(MFAOptions, { MFAEndpoints: validatedMFAEndpoints, usePassKey: usePassKey, onComplete: handleComplete, onAuthFailed: handleAuthFailed }));
|
|
2244
2328
|
}
|
|
2245
2329
|
if (!context.isAuthenticated) {
|
|
2246
|
-
return (jsxRuntimeExports.jsx(DefaultLoginPage, { usePassKey: usePassKey, MFAEndpoints: MFAEndpoints, PassKeysRegisterProps: PassKeysRegisterProps }));
|
|
2330
|
+
return (jsxRuntimeExports.jsx(DefaultLoginPage, { usePassKey: usePassKey, useADLogin: useADLogin, MFAEndpoints: MFAEndpoints, PassKeysRegisterProps: PassKeysRegisterProps, CredentialsAuthEndpoint: CredentialsAuthEndpoint }));
|
|
2247
2331
|
}
|
|
2248
2332
|
return jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: children });
|
|
2249
2333
|
};
|