@nibssplc/cams-sdk-react 0.0.1-beta.99 → 1.0.0-rc.11
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/CAMSMSALProvider.d.ts +1 -0
- package/dist/components/DefaultLoginPage.d.ts +4 -1
- package/dist/components/MFAGate.d.ts +3 -1
- package/dist/components/UnifiedCAMSProvider.d.ts +1 -0
- package/dist/hooks/useCAMSMSALAuth.d.ts +1 -0
- package/dist/hooks/useOTPHandler.d.ts +2 -7
- package/dist/index.cjs.js +222 -121
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.esm.js +222 -121
- 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,28 @@ 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';
|
|
22
|
+
|
|
23
|
+
var _a;
|
|
24
|
+
// Crypto polyfill for environments where crypto is not available
|
|
25
|
+
if (typeof window !== 'undefined' && !window.crypto) {
|
|
26
|
+
var crypto_1 = require('crypto');
|
|
27
|
+
// @ts-ignore
|
|
28
|
+
window.crypto = {
|
|
29
|
+
getRandomValues: function (arr) {
|
|
30
|
+
var bytes = crypto_1.randomBytes(arr.length);
|
|
31
|
+
for (var i = 0; i < arr.length; i++) {
|
|
32
|
+
arr[i] = bytes[i];
|
|
33
|
+
}
|
|
34
|
+
return arr;
|
|
35
|
+
},
|
|
36
|
+
subtle: ((_a = crypto_1.webcrypto) === null || _a === void 0 ? void 0 : _a.subtle) || {
|
|
37
|
+
digest: function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
38
|
+
throw new Error('crypto.subtle not available');
|
|
39
|
+
}); }); }
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
}
|
|
21
43
|
|
|
22
44
|
/******************************************************************************
|
|
23
45
|
Copyright (c) Microsoft Corporation.
|
|
@@ -59,7 +81,7 @@ function __rest(s, e) {
|
|
|
59
81
|
return t;
|
|
60
82
|
}
|
|
61
83
|
|
|
62
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
84
|
+
function __awaiter$1(thisArg, _arguments, P, generator) {
|
|
63
85
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
64
86
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
65
87
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
@@ -69,7 +91,7 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
69
91
|
});
|
|
70
92
|
}
|
|
71
93
|
|
|
72
|
-
function __generator(thisArg, body) {
|
|
94
|
+
function __generator$1(thisArg, body) {
|
|
73
95
|
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
74
96
|
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
75
97
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
@@ -166,10 +188,10 @@ function useCAMSAuth(options) {
|
|
|
166
188
|
}
|
|
167
189
|
}
|
|
168
190
|
}, [options.storageKey]);
|
|
169
|
-
var login = useCallback(function (config) { return __awaiter(_this, void 0, void 0, function () {
|
|
191
|
+
var login = useCallback(function (config) { return __awaiter$1(_this, void 0, void 0, function () {
|
|
170
192
|
var loginConfig, userProfile, err_1, e, isPopupClosedError, restoredToken, userProfile;
|
|
171
193
|
var _a, _b, _c;
|
|
172
|
-
return __generator(this, function (_d) {
|
|
194
|
+
return __generator$1(this, function (_d) {
|
|
173
195
|
switch (_d.label) {
|
|
174
196
|
case 0:
|
|
175
197
|
if (!sessionManagerRef.current)
|
|
@@ -217,8 +239,8 @@ function useCAMSAuth(options) {
|
|
|
217
239
|
}
|
|
218
240
|
});
|
|
219
241
|
}); }, [options.idleTimeout]);
|
|
220
|
-
var logout = useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
221
|
-
return __generator(this, function (_a) {
|
|
242
|
+
var logout = useCallback(function () { return __awaiter$1(_this, void 0, void 0, function () {
|
|
243
|
+
return __generator$1(this, function (_a) {
|
|
222
244
|
switch (_a.label) {
|
|
223
245
|
case 0:
|
|
224
246
|
if (!sessionManagerRef.current)
|
|
@@ -311,7 +333,6 @@ function useCAMSMSALAuth(options) {
|
|
|
311
333
|
setMfaAuthenticator(authenticator);
|
|
312
334
|
setRequiresMFA(true);
|
|
313
335
|
}
|
|
314
|
-
Logger.debug("App Code", { ">>>": options.appCode });
|
|
315
336
|
}
|
|
316
337
|
else {
|
|
317
338
|
localStorage.removeItem(storageKey);
|
|
@@ -353,10 +374,10 @@ function useCAMSMSALAuth(options) {
|
|
|
353
374
|
// };
|
|
354
375
|
// handleRedirect();
|
|
355
376
|
// }, []);
|
|
356
|
-
var login = useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
377
|
+
var login = useCallback(function () { return __awaiter$1(_this, void 0, void 0, function () {
|
|
357
378
|
var response, mfaConfig, authenticator, err_1, camsError_1, camsError;
|
|
358
379
|
var _a, _b, _c, _d;
|
|
359
|
-
return __generator(this, function (_e) {
|
|
380
|
+
return __generator$1(this, function (_e) {
|
|
360
381
|
switch (_e.label) {
|
|
361
382
|
case 0:
|
|
362
383
|
setError(null);
|
|
@@ -420,8 +441,8 @@ function useCAMSMSALAuth(options) {
|
|
|
420
441
|
}
|
|
421
442
|
});
|
|
422
443
|
}); }, [instance, scopes, options]);
|
|
423
|
-
var completeMFA = useCallback(function (data) { return __awaiter(_this, void 0, void 0, function () {
|
|
424
|
-
return __generator(this, function (_a) {
|
|
444
|
+
var completeMFA = useCallback(function (data) { return __awaiter$1(_this, void 0, void 0, function () {
|
|
445
|
+
return __generator$1(this, function (_a) {
|
|
425
446
|
if (!mfaAuthenticator) {
|
|
426
447
|
throw new CAMSError(CAMSErrorType.API_VALIDATION_ERROR, "MFA Authenticator not initialized");
|
|
427
448
|
}
|
|
@@ -455,8 +476,8 @@ function useCAMSMSALAuth(options) {
|
|
|
455
476
|
return [2 /*return*/];
|
|
456
477
|
});
|
|
457
478
|
}); }, [mfaAuthenticator, accessToken, idToken, storageKey]);
|
|
458
|
-
var sendEmailOTP = useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
459
|
-
return __generator(this, function (_a) {
|
|
479
|
+
var sendEmailOTP = useCallback(function () { return __awaiter$1(_this, void 0, void 0, function () {
|
|
480
|
+
return __generator$1(this, function (_a) {
|
|
460
481
|
switch (_a.label) {
|
|
461
482
|
case 0:
|
|
462
483
|
if (!mfaAuthenticator) {
|
|
@@ -467,9 +488,9 @@ function useCAMSMSALAuth(options) {
|
|
|
467
488
|
}
|
|
468
489
|
});
|
|
469
490
|
}); }, [mfaAuthenticator]);
|
|
470
|
-
var logout = useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
491
|
+
var logout = useCallback(function () { return __awaiter$1(_this, void 0, void 0, function () {
|
|
471
492
|
var err_2, camsError;
|
|
472
|
-
return __generator(this, function (_a) {
|
|
493
|
+
return __generator$1(this, function (_a) {
|
|
473
494
|
switch (_a.label) {
|
|
474
495
|
case 0:
|
|
475
496
|
_a.trys.push([0, 2, , 3]);
|
|
@@ -553,29 +574,21 @@ function arrayBufferToBase64url(buffer) {
|
|
|
553
574
|
* @returns A promise that resolves to a JSON-serializable representation of the PublicKeyCredential.
|
|
554
575
|
*/
|
|
555
576
|
function register(options) {
|
|
556
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
577
|
+
return __awaiter$1(this, void 0, void 0, function () {
|
|
557
578
|
var createOptions, credential, publicKeyCredential, attestationResponse, transports, err_1;
|
|
558
579
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
559
|
-
return __generator(this, function (_k) {
|
|
580
|
+
return __generator$1(this, function (_k) {
|
|
560
581
|
switch (_k.label) {
|
|
561
582
|
case 0:
|
|
562
583
|
_k.trys.push([0, 2, , 3]);
|
|
563
584
|
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
585
|
return [4 /*yield*/, navigator.credentials.create({
|
|
566
|
-
publicKey: __assign(__assign({},
|
|
586
|
+
publicKey: __assign(__assign({}, createOptions), { pubKeyCredParams: (_a = options.pubKeyCredParams) === null || _a === void 0 ? void 0 : _a.map(function (param) { return ({
|
|
567
587
|
type: "public-key",
|
|
568
588
|
alg: param.alg,
|
|
569
|
-
}); }), attestation: (((_b = options.attestation) === null || _b === void 0 ? void 0 : _b.toLowerCase()) || "none"), authenticatorSelection: __assign(__assign({}, options.authenticatorSelection), {
|
|
570
|
-
// authenticatorAttachment:
|
|
571
|
-
// (options.authenticatorSelection?.authenticatorAttachment?.toLowerCase() ||
|
|
572
|
-
// "platform") as AuthenticatorAttachment,
|
|
573
|
-
// requireResidentKey:
|
|
574
|
-
// (options.authenticatorSelection?.requireResidentKey?.toLowerCase() ||
|
|
575
|
-
// "false") === "true",
|
|
576
|
-
residentKey: (((_d = (_c = options.authenticatorSelection) === null || _c === void 0 ? void 0 : _c.residentKey) === null || _d === void 0 ? void 0 : _d.toLowerCase()) ||
|
|
589
|
+
}); }), attestation: (((_b = options.attestation) === null || _b === void 0 ? void 0 : _b.toLowerCase()) || "none"), authenticatorSelection: __assign(__assign({}, options.authenticatorSelection), { residentKey: (((_d = (_c = options.authenticatorSelection) === null || _c === void 0 ? void 0 : _c.residentKey) === null || _d === void 0 ? void 0 : _d.toLowerCase()) ||
|
|
577
590
|
"discouraged"), userVerification: (((_f = (_e = options.authenticatorSelection) === null || _e === void 0 ? void 0 : _e.userVerification) === null || _f === void 0 ? void 0 : _f.toLowerCase()) ||
|
|
578
|
-
"
|
|
591
|
+
"discouraged") }) }),
|
|
579
592
|
})];
|
|
580
593
|
case 1:
|
|
581
594
|
credential = _k.sent();
|
|
@@ -596,12 +609,16 @@ function register(options) {
|
|
|
596
609
|
}];
|
|
597
610
|
case 2:
|
|
598
611
|
err_1 = _k.sent();
|
|
612
|
+
console.error("Error during registration:", err_1);
|
|
599
613
|
if (err_1.name === "NotAllowedError") {
|
|
600
|
-
throw new Error("
|
|
614
|
+
throw new Error("Face ID/Touch ID cancelled or failed. Please try again.");
|
|
601
615
|
}
|
|
602
616
|
if (err_1.name === "InvalidStateError") {
|
|
603
617
|
throw new Error("Passkey already registered for this user.");
|
|
604
618
|
}
|
|
619
|
+
if (err_1.name === "NotSupportedError") {
|
|
620
|
+
throw new Error("Passkeys not supported on this device.");
|
|
621
|
+
}
|
|
605
622
|
throw err_1;
|
|
606
623
|
case 3: return [2 /*return*/];
|
|
607
624
|
}
|
|
@@ -618,10 +635,10 @@ function register(options) {
|
|
|
618
635
|
* @returns A promise that resolves to a JSON-serializable representation of the PublicKeyCredential.
|
|
619
636
|
*/
|
|
620
637
|
function authenticate(options) {
|
|
621
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
638
|
+
return __awaiter$1(this, void 0, void 0, function () {
|
|
622
639
|
var getOptions, credential, publicKeyCredential, assertionResponse;
|
|
623
640
|
var _a;
|
|
624
|
-
return __generator(this, function (_b) {
|
|
641
|
+
return __generator$1(this, function (_b) {
|
|
625
642
|
switch (_b.label) {
|
|
626
643
|
case 0:
|
|
627
644
|
getOptions = __assign(__assign({}, options), { challenge: base64urlToArrayBuffer(options.challenge), allowCredentials: (_a = options.allowCredentials) === null || _a === void 0 ? void 0 : _a.map(function (cred) { return (__assign(__assign({}, cred), { id: base64urlToArrayBuffer(cred.id) })); }) });
|
|
@@ -1189,8 +1206,8 @@ function CAMSMSALProviderInner(_a) {
|
|
|
1189
1206
|
}
|
|
1190
1207
|
}, [userProfile, profileStorageKey]);
|
|
1191
1208
|
// Enhanced logout that also clears profile
|
|
1192
|
-
var enhancedLogout = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
1193
|
-
return __generator(this, function (_a) {
|
|
1209
|
+
var enhancedLogout = function () { return __awaiter$1(_this, void 0, void 0, function () {
|
|
1210
|
+
return __generator$1(this, function (_a) {
|
|
1194
1211
|
switch (_a.label) {
|
|
1195
1212
|
case 0: return [4 /*yield*/, auth.logout()];
|
|
1196
1213
|
case 1:
|
|
@@ -1286,8 +1303,8 @@ function CAMSProviderCore(props) {
|
|
|
1286
1303
|
}
|
|
1287
1304
|
}
|
|
1288
1305
|
}, [userProfile, profileStorageKey]);
|
|
1289
|
-
var enhancedLogout = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
1290
|
-
return __generator(this, function (_a) {
|
|
1306
|
+
var enhancedLogout = function () { return __awaiter$1(_this, void 0, void 0, function () {
|
|
1307
|
+
return __generator$1(this, function (_a) {
|
|
1291
1308
|
switch (_a.label) {
|
|
1292
1309
|
case 0: return [4 /*yield*/, auth.logout()];
|
|
1293
1310
|
case 1:
|
|
@@ -1706,7 +1723,7 @@ styleInject(css_248z);
|
|
|
1706
1723
|
|
|
1707
1724
|
var LoadingSpinner = function (_a) {
|
|
1708
1725
|
var loadingText = _a.loadingText;
|
|
1709
|
-
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..." }))] }));
|
|
1710
1727
|
};
|
|
1711
1728
|
|
|
1712
1729
|
var AuthSuccessAnimation = function (_a) {
|
|
@@ -1723,7 +1740,7 @@ var GenerateDeviceId = function () {
|
|
|
1723
1740
|
var userAgent = window.navigator.userAgent;
|
|
1724
1741
|
var deviceId = "";
|
|
1725
1742
|
// Parse browser, version, OS, and device type
|
|
1726
|
-
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));
|
|
1727
1744
|
var osMatch = Array.from(userAgent.matchAll(/\(([^)]+)\)/g));
|
|
1728
1745
|
var isMobile = /Mobile|Android|iPhone|iPad/i.test(userAgent);
|
|
1729
1746
|
// Browser info
|
|
@@ -1753,6 +1770,31 @@ var GenerateDeviceId = function () {
|
|
|
1753
1770
|
deviceId += "_".concat(hash);
|
|
1754
1771
|
return (_a = deviceId.replace(/[^a-zA-Z0-9-_]/g, "_")) !== null && _a !== void 0 ? _a : "unknown-device";
|
|
1755
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
|
+
});
|
|
1756
1798
|
|
|
1757
1799
|
var MAX_ATTEMPTS = 3;
|
|
1758
1800
|
var useOTPHandler = function (_a) {
|
|
@@ -1760,9 +1802,9 @@ var useOTPHandler = function (_a) {
|
|
|
1760
1802
|
var _b = useState(false), loading = _b[0], setLoading = _b[1];
|
|
1761
1803
|
var _c = useState(0), attemptCount = _c[0], setAttemptCount = _c[1];
|
|
1762
1804
|
var _d = useState(false), isMaxAttemptsReached = _d[0], setIsMaxAttemptsReached = _d[1];
|
|
1763
|
-
var handleSubmitOTP = useMemo(function () { return function (authenticationValue) { return __awaiter(void 0, void 0, void 0, function () {
|
|
1805
|
+
var handleSubmitOTP = useMemo(function () { return function (authenticationValue) { return __awaiter$1(void 0, void 0, void 0, function () {
|
|
1764
1806
|
var currentAttempt, response, error_1, currentAttempt;
|
|
1765
|
-
return __generator(this, function (_a) {
|
|
1807
|
+
return __generator$1(this, function (_a) {
|
|
1766
1808
|
switch (_a.label) {
|
|
1767
1809
|
case 0:
|
|
1768
1810
|
if (isMaxAttemptsReached) {
|
|
@@ -1779,18 +1821,13 @@ var useOTPHandler = function (_a) {
|
|
|
1779
1821
|
setAttemptCount(currentAttempt);
|
|
1780
1822
|
if (authenticationType === null)
|
|
1781
1823
|
return [2 /*return*/, false];
|
|
1782
|
-
return [4 /*yield*/,
|
|
1824
|
+
return [4 /*yield*/, axiosInstance.post(MFAEndpoint || "/api/auth/verify-mfa", {
|
|
1783
1825
|
provider: provider,
|
|
1784
1826
|
accessToken: accessToken,
|
|
1785
1827
|
idToken: idToken,
|
|
1786
1828
|
authenticationType: authenticationType,
|
|
1787
1829
|
MFACode: authenticationValue,
|
|
1788
1830
|
appCode: appCode,
|
|
1789
|
-
}, {
|
|
1790
|
-
headers: {
|
|
1791
|
-
"X-Device-ID": GenerateDeviceId(),
|
|
1792
|
-
},
|
|
1793
|
-
timeout: 605000,
|
|
1794
1831
|
})];
|
|
1795
1832
|
case 2:
|
|
1796
1833
|
response = (_a.sent()).data;
|
|
@@ -1852,6 +1889,75 @@ var useOTPHandler = function (_a) {
|
|
|
1852
1889
|
remainingAttempts: MAX_ATTEMPTS - attemptCount,
|
|
1853
1890
|
};
|
|
1854
1891
|
};
|
|
1892
|
+
var useCredentialsHandler = function (onAuthComplete) {
|
|
1893
|
+
var _a = useState(false), loading = _a[0], setLoading = _a[1];
|
|
1894
|
+
var _b = useState(0), attemptCount = _b[0], setAttemptCount = _b[1];
|
|
1895
|
+
var _c = useState(false), isMaxAttemptsReached = _c[0], setIsMaxAttemptsReached = _c[1];
|
|
1896
|
+
var handleSubmitCredentials = useMemo(function () {
|
|
1897
|
+
return function (CredAuthEndpoint, credentials, appCode) { return __awaiter$1(void 0, void 0, void 0, function () {
|
|
1898
|
+
var currentAttempt, response, error_2, currentAttempt;
|
|
1899
|
+
return __generator$1(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
|
+
};
|
|
1855
1961
|
|
|
1856
1962
|
var MFAOptions = function (_a) {
|
|
1857
1963
|
var onComplete = _a.onComplete, onAuthFailed = _a.onAuthFailed, MFAEndpoints = _a.MFAEndpoints, usePassKey = _a.usePassKey;
|
|
@@ -1862,54 +1968,39 @@ var MFAOptions = function (_a) {
|
|
|
1862
1968
|
var context = useCAMSContext();
|
|
1863
1969
|
var _f = context.authMode === "MSAL" && "sendEmailOTP" in context
|
|
1864
1970
|
? context
|
|
1865
|
-
: { sendEmailOTP: null, completeMFA: null, logout: function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
1971
|
+
: { sendEmailOTP: null, completeMFA: null, logout: function () { return __awaiter$1(void 0, void 0, void 0, function () { return __generator$1(this, function (_a) {
|
|
1866
1972
|
return [2 /*return*/];
|
|
1867
1973
|
}); }); } }, sendEmailOTP = _f.sendEmailOTP, completeMFA = _f.completeMFA, logout = _f.logout;
|
|
1868
1974
|
var accessToken = context.authMode === "MSAL" ? context.accessToken : "";
|
|
1869
1975
|
var idToken = context.authMode === "MSAL" ? context.idToken : "";
|
|
1870
1976
|
var authenticate = useWebAuthn().authenticate;
|
|
1871
|
-
var handleFIDOLogin = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
1977
|
+
var handleFIDOLogin = function () { return __awaiter$1(void 0, void 0, void 0, function () {
|
|
1872
1978
|
var options, assertionResponse, error_1;
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
switch (_g.label) {
|
|
1979
|
+
return __generator$1(this, function (_a) {
|
|
1980
|
+
switch (_a.label) {
|
|
1876
1981
|
case 0:
|
|
1877
|
-
|
|
1982
|
+
_a.trys.push([0, 4, , 5]);
|
|
1878
1983
|
// 1. Fetch authentication challenge from your server
|
|
1879
1984
|
console.log("Requesting authentication challenge from server...");
|
|
1880
|
-
return [4 /*yield*/,
|
|
1881
|
-
headers: {
|
|
1882
|
-
"X-DEVICE-ID": GenerateDeviceId(),
|
|
1883
|
-
"X-API-VERSION": "1.0",
|
|
1884
|
-
},
|
|
1885
|
-
})];
|
|
1985
|
+
return [4 /*yield*/, axiosInstance.post(MFAEndpoints.RetrieveAuthChallenge, {})];
|
|
1886
1986
|
case 1:
|
|
1887
|
-
options = (
|
|
1987
|
+
options = (_a.sent()).data;
|
|
1888
1988
|
console.log("Received challenge:", options);
|
|
1889
1989
|
// 2. Call the SDK to trigger the browser's passkey authentication UI
|
|
1890
1990
|
console.log("Calling SDK authenticate function...");
|
|
1891
|
-
return [4 /*yield*/, authenticate(__assign(__assign({}, options), {
|
|
1892
|
-
type: "public-key",
|
|
1893
|
-
alg: param.alg
|
|
1894
|
-
}); }), 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" }) }))];
|
|
1991
|
+
return [4 /*yield*/, authenticate(__assign(__assign({}, options), { userVerification: "discouraged" }))];
|
|
1895
1992
|
case 2:
|
|
1896
|
-
assertionResponse =
|
|
1993
|
+
assertionResponse = _a.sent();
|
|
1897
1994
|
console.log("Authentication assertion received from client:", assertionResponse);
|
|
1898
1995
|
// 3. Send the assertion back to the server for verification
|
|
1899
1996
|
console.log("Sending assertion to server for verification...");
|
|
1900
|
-
return [4 /*yield*/,
|
|
1901
|
-
headers: {
|
|
1902
|
-
"X-DEVICE-ID": GenerateDeviceId(),
|
|
1903
|
-
"X-API-VERSION": "1.0",
|
|
1904
|
-
},
|
|
1905
|
-
withCredentials: true, // credentials: 'include'
|
|
1906
|
-
})];
|
|
1997
|
+
return [4 /*yield*/, axiosInstance.post(MFAEndpoints.AuthChallengeVerify, assertionResponse)];
|
|
1907
1998
|
case 3:
|
|
1908
|
-
|
|
1999
|
+
_a.sent();
|
|
1909
2000
|
toast.success("🔑 Sign-in successful!");
|
|
1910
2001
|
return [3 /*break*/, 5];
|
|
1911
2002
|
case 4:
|
|
1912
|
-
error_1 =
|
|
2003
|
+
error_1 = _a.sent();
|
|
1913
2004
|
console.error("Authentication failed:", error_1);
|
|
1914
2005
|
toast.error("❌ Could not sign in.");
|
|
1915
2006
|
return [3 /*break*/, 5];
|
|
@@ -1965,12 +2056,12 @@ var MFAOptions = function (_a) {
|
|
|
1965
2056
|
}
|
|
1966
2057
|
var content = jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, {});
|
|
1967
2058
|
if (!authType) {
|
|
1968
|
-
content = (jsxRuntimeExports.jsxs("div", { className: "space-y-4", children: [jsxRuntimeExports.jsx("p", { className: "text-sm text-gray-600 text-center mb-6", children: "Choose your preferred authentication method:" }), jsxRuntimeExports.jsxs("div", { className: "flex flex-col gap-3", children: [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 () { return __awaiter(void 0, void 0, void 0, function () {
|
|
2059
|
+
content = (jsxRuntimeExports.jsxs("div", { className: "space-y-4", children: [jsxRuntimeExports.jsx("p", { className: "text-sm text-gray-600 text-center mb-6", children: "Choose your preferred authentication method:" }), jsxRuntimeExports.jsxs("div", { className: "flex flex-col gap-3", children: [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 () { return __awaiter$1(void 0, void 0, void 0, function () {
|
|
1969
2060
|
var success;
|
|
1970
|
-
return __generator(this, function (_a) {
|
|
2061
|
+
return __generator$1(this, function (_a) {
|
|
1971
2062
|
switch (_a.label) {
|
|
1972
2063
|
case 0:
|
|
1973
|
-
resetAttempts();
|
|
2064
|
+
// resetAttempts();
|
|
1974
2065
|
setAuthType("EmailOTP");
|
|
1975
2066
|
setOtpVisible(true);
|
|
1976
2067
|
if (!sendEmailOTP) return [3 /*break*/, 2];
|
|
@@ -1987,7 +2078,6 @@ var MFAOptions = function (_a) {
|
|
|
1987
2078
|
}
|
|
1988
2079
|
});
|
|
1989
2080
|
}); }, 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 () {
|
|
1990
|
-
resetAttempts();
|
|
1991
2081
|
setAuthType("AuthenticatorCode");
|
|
1992
2082
|
setOtpVisible(true);
|
|
1993
2083
|
}, 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",
|
|
@@ -1996,7 +2086,7 @@ var MFAOptions = function (_a) {
|
|
|
1996
2086
|
// setAuthType("AuthenticatorCode");
|
|
1997
2087
|
// setOtpVisible(true);
|
|
1998
2088
|
// }}
|
|
1999
|
-
onClick: handleFIDOLogin, disabled: context.isLoading, children: [jsxRuntimeExports.jsx(
|
|
2089
|
+
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" })] })] }))] })] }));
|
|
2000
2090
|
}
|
|
2001
2091
|
else if (authType === "EmailOTP") {
|
|
2002
2092
|
content = (jsxRuntimeExports.jsx(Dialog, { open: otpVisible, onOpenChange: function () {
|
|
@@ -2028,28 +2118,27 @@ var credentialsSchema = z.object({
|
|
|
2028
2118
|
password: z.string().min(1, "Password is required"),
|
|
2029
2119
|
});
|
|
2030
2120
|
var ADLoginModal = function (_a) {
|
|
2031
|
-
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;
|
|
2032
2122
|
var _b = useState("credentials"), step = _b[0], setStep = _b[1];
|
|
2033
2123
|
var _c = useState({
|
|
2034
2124
|
username: "",
|
|
2035
2125
|
password: "",
|
|
2036
2126
|
}), credentials = _c[0], setCredentials = _c[1];
|
|
2037
2127
|
var _d = useState(""), mfaCode = _d[0], setMfaCode = _d[1];
|
|
2038
|
-
var _e = useState(false), isLoading = _e[0], setIsLoading = _e[1];
|
|
2039
2128
|
var form = useForm({
|
|
2040
2129
|
resolver: a$1(credentialsSchema),
|
|
2041
2130
|
defaultValues: { username: "", password: "" },
|
|
2042
2131
|
});
|
|
2043
|
-
var handleCredentialsSubmit = function (values) { return __awaiter(void 0, void 0, void 0, function () {
|
|
2044
|
-
return __generator(this, function (_a) {
|
|
2132
|
+
var handleCredentialsSubmit = function (values) { return __awaiter$1(void 0, void 0, void 0, function () {
|
|
2133
|
+
return __generator$1(this, function (_a) {
|
|
2045
2134
|
setCredentials(values);
|
|
2046
2135
|
setStep("mfa");
|
|
2047
2136
|
return [2 /*return*/];
|
|
2048
2137
|
});
|
|
2049
2138
|
}); };
|
|
2050
|
-
var handleMFASubmit = function (code) { return __awaiter(void 0, void 0, void 0, function () {
|
|
2139
|
+
var handleMFASubmit = function (code) { return __awaiter$1(void 0, void 0, void 0, function () {
|
|
2051
2140
|
var error_1;
|
|
2052
|
-
return __generator(this, function (_a) {
|
|
2141
|
+
return __generator$1(this, function (_a) {
|
|
2053
2142
|
switch (_a.label) {
|
|
2054
2143
|
case 0:
|
|
2055
2144
|
setIsLoading(true);
|
|
@@ -2085,22 +2174,50 @@ var ADLoginModal = function (_a) {
|
|
|
2085
2174
|
form.reset();
|
|
2086
2175
|
setMfaCode("");
|
|
2087
2176
|
};
|
|
2088
|
-
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(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) {
|
|
2089
2178
|
var field = _a.field;
|
|
2090
|
-
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, {})] }));
|
|
2091
2180
|
} }), jsxRuntimeExports.jsx(FormField, { control: form.control, name: "password", render: function (_a) {
|
|
2092
2181
|
var field = _a.field;
|
|
2093
|
-
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, {})] }));
|
|
2094
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(Loader2, { className: "w-4 h-4 animate-spin" }), jsxRuntimeExports.jsx("span", { children: "Verifying..." })] }))] }))] }) }));
|
|
2095
2184
|
};
|
|
2096
2185
|
|
|
2097
2186
|
var DefaultLoginPage = function (_a) {
|
|
2098
|
-
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
|
+
};
|
|
2099
2198
|
var context = useCAMSContext();
|
|
2100
2199
|
var login = context.login, isLoading = context.isLoading, authMode = context.authMode;
|
|
2101
2200
|
var _b = useState(false), showADModal = _b[0], setShowADModal = _b[1];
|
|
2102
2201
|
var register = useWebAuthn().register;
|
|
2202
|
+
var _c = useCredentialsHandler(function (state, data) { return __awaiter$1(void 0, void 0, void 0, function () {
|
|
2203
|
+
return __generator$1(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;
|
|
2103
2216
|
var handleMSALLogin = function () {
|
|
2217
|
+
if (typeof window !== "undefined" && !window.crypto) {
|
|
2218
|
+
toast.error("Crypto API not available. Please use a modern browser.");
|
|
2219
|
+
return;
|
|
2220
|
+
}
|
|
2104
2221
|
if (authMode === "MSAL") {
|
|
2105
2222
|
login();
|
|
2106
2223
|
}
|
|
@@ -2109,30 +2226,15 @@ var DefaultLoginPage = function (_a) {
|
|
|
2109
2226
|
console.warn("Regular CAMS login requires configuration");
|
|
2110
2227
|
}
|
|
2111
2228
|
};
|
|
2112
|
-
var
|
|
2113
|
-
hidden: { opacity: 0, scale: 0.8, y: 50 },
|
|
2114
|
-
visible: {
|
|
2115
|
-
opacity: 1,
|
|
2116
|
-
scale: 1,
|
|
2117
|
-
y: 0,
|
|
2118
|
-
transition: { type: "spring", duration: 0.6 },
|
|
2119
|
-
},
|
|
2120
|
-
exit: { opacity: 0, scale: 0.8, y: -50, transition: { duration: 0.3 } },
|
|
2121
|
-
};
|
|
2122
|
-
var handleRegister = function (data) { return __awaiter(void 0, void 0, void 0, function () {
|
|
2229
|
+
var handleRegister = function (data) { return __awaiter$1(void 0, void 0, void 0, function () {
|
|
2123
2230
|
var options, attestationResponse, error_1;
|
|
2124
|
-
return __generator(this, function (_a) {
|
|
2231
|
+
return __generator$1(this, function (_a) {
|
|
2125
2232
|
switch (_a.label) {
|
|
2126
2233
|
case 0:
|
|
2127
2234
|
_a.trys.push([0, 4, , 5]);
|
|
2128
2235
|
// 1. Fetch challenge from your server
|
|
2129
2236
|
console.log("Requesting registration challenge from server...");
|
|
2130
|
-
return [4 /*yield*/,
|
|
2131
|
-
headers: {
|
|
2132
|
-
"X-DEVICE-ID": GenerateDeviceId(),
|
|
2133
|
-
"X-API-VERSION": "1.0",
|
|
2134
|
-
},
|
|
2135
|
-
})];
|
|
2237
|
+
return [4 /*yield*/, axiosInstance.post(MFAEndpoints.RegisterNewChallenge, __assign({}, data))];
|
|
2136
2238
|
case 1:
|
|
2137
2239
|
options = (_a.sent()).data;
|
|
2138
2240
|
console.log("Received challenge:", options);
|
|
@@ -2144,13 +2246,7 @@ var DefaultLoginPage = function (_a) {
|
|
|
2144
2246
|
console.log("Passkey created on client:", attestationResponse);
|
|
2145
2247
|
// 3. Send the response back to the server for verification
|
|
2146
2248
|
console.log("Sending attestation to server for verification...");
|
|
2147
|
-
return [4 /*yield*/,
|
|
2148
|
-
headers: {
|
|
2149
|
-
"X-DEVICE-ID": GenerateDeviceId(),
|
|
2150
|
-
"X-API-VERSION": "1.0",
|
|
2151
|
-
},
|
|
2152
|
-
withCredentials: true, // credentials: 'include'
|
|
2153
|
-
})];
|
|
2249
|
+
return [4 /*yield*/, axiosInstance.post(MFAEndpoints.RegisterVerify + "?username=".concat(data.username), attestationResponse)];
|
|
2154
2250
|
case 3:
|
|
2155
2251
|
_a.sent();
|
|
2156
2252
|
toast.success("✅ Registration successful! Passkey created.");
|
|
@@ -2164,15 +2260,19 @@ var DefaultLoginPage = function (_a) {
|
|
|
2164
2260
|
}
|
|
2165
2261
|
});
|
|
2166
2262
|
}); };
|
|
2167
|
-
return (jsxRuntimeExports.jsxs("main", { className: "min-h-screen bg-gray-50", children: [jsxRuntimeExports.jsx(motion.div, { initial: { opacity: 0 }, animate: { opacity: 1 }, exit: { opacity: 0 }, transition: { duration: 0.5 }, children: jsxRuntimeExports.jsx("div", { className: "flex h-screen items-center justify-center", children: jsxRuntimeExports.jsxs(motion.div, { variants: cardVariants, initial: "hidden", animate: "visible", exit: "exit", className: "w-full max-w-md p-6 space-y-4 bg-gray-50 rounded-2xl shadow-2xl --dark:bg-gray-800", children: [jsxRuntimeExports.jsxs(CardHeader, { className: "text-center space-y-3", children: [jsxRuntimeExports.jsx("div", { className: "w-full flex items-center justify-center", children: jsxRuntimeExports.jsx("img", { src: NIBSSLogo, alt: "NIBSS Logo", width: 265, height: 265 }) }), jsxRuntimeExports.jsx(CardTitle, { className: "text-3xl font-bold --text-gray-900 --dark:text-white", children: "NIBSS CAMS" }), jsxRuntimeExports.jsx(CardTitle, { className: "text-gray-500 dark:text-gray-400 font-bold text-lg", children: "Centralized Authentication" })] }), jsxRuntimeExports.jsxs(CardAction, { className: "w-full flex flex-col items-center justify-center text-center text-gray-500 dark:text-gray-400 mb-
|
|
2263
|
+
return (jsxRuntimeExports.jsxs("main", { className: "min-h-screen bg-gray-50", children: [jsxRuntimeExports.jsx(motion.div, { initial: { opacity: 0 }, animate: { opacity: 1 }, exit: { opacity: 0 }, transition: { duration: 0.5 }, children: jsxRuntimeExports.jsx("div", { className: "flex h-screen items-center justify-center", children: jsxRuntimeExports.jsxs(motion.div, { variants: cardVariants, initial: "hidden", animate: "visible", exit: "exit", className: "w-full max-w-md p-6 space-y-4 bg-gray-50 rounded-2xl shadow-2xl --dark:bg-gray-800", children: [jsxRuntimeExports.jsxs(CardHeader, { className: "text-center space-y-3", children: [jsxRuntimeExports.jsx("div", { className: "w-full flex items-center justify-center", children: jsxRuntimeExports.jsx("img", { src: NIBSSLogo, alt: "NIBSS Logo", width: 265, height: 265 }) }), jsxRuntimeExports.jsx(CardTitle, { className: "text-3xl font-bold --text-gray-900 --dark:text-white", children: "NIBSS CAMS" }), jsxRuntimeExports.jsx(CardTitle, { className: "text-gray-500 dark:text-gray-400 font-bold text-lg", children: "Centralized Authentication" })] }), jsxRuntimeExports.jsxs(CardAction, { className: "w-full flex flex-col items-center justify-center text-center text-gray-500 dark:text-gray-400 mb-8", children: [jsxRuntimeExports.jsx("img", { src: AuthLogo, alt: "Auth Logo", width: 365, height: 365 }), "Use Below Identity Providers To Authenticate"] }), jsxRuntimeExports.jsxs("div", { className: "space-y-4", children: [jsxRuntimeExports.jsxs(Button
|
|
2168
2264
|
// variant="outline"
|
|
2169
2265
|
, {
|
|
2170
2266
|
// variant="outline"
|
|
2171
|
-
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" })] }),
|
|
2267
|
+
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
|
|
2268
|
+
? "Logging in..."
|
|
2269
|
+
: "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$1(void 0, [_a], void 0, function (_b) {
|
|
2172
2270
|
var username = _b.username, password = _b.password, MFACode = _b.MFACode;
|
|
2173
|
-
return __generator(this, function (_c) {
|
|
2271
|
+
return __generator$1(this, function (_c) {
|
|
2174
2272
|
// Implement your AD login logic here
|
|
2175
2273
|
console.log("AD Login:", { username: username, password: password, MFACode: MFACode });
|
|
2274
|
+
// Example: await adLoginService(username, password, mfaCode);
|
|
2275
|
+
handleSubmitCredentials(CredentialsAuthEndpoint !== null && CredentialsAuthEndpoint !== void 0 ? CredentialsAuthEndpoint : "/api/auth/validate", { username: username, password: password, MFACode: MFACode }, context.appCode);
|
|
2176
2276
|
return [2 /*return*/];
|
|
2177
2277
|
});
|
|
2178
2278
|
}); } })] }));
|
|
@@ -2195,7 +2295,7 @@ var MFAGate = function (_a) {
|
|
|
2195
2295
|
// loginComponent: LoginComponent = DefaultLoginPage,
|
|
2196
2296
|
_c = _a.usePassKey,
|
|
2197
2297
|
// loginComponent: LoginComponent = DefaultLoginPage,
|
|
2198
|
-
usePassKey = _c === void 0 ? false : _c, PassKeysRegisterProps = _a.PassKeysRegisterProps, MFAEndpoints = _a.MFAEndpoints;
|
|
2298
|
+
usePassKey = _c === void 0 ? false : _c, _d = _a.useADLogin, useADLogin = _d === void 0 ? false : _d, CredentialsAuthEndpoint = _a.CredentialsAuthEndpoint, PassKeysRegisterProps = _a.PassKeysRegisterProps, MFAEndpoints = _a.MFAEndpoints;
|
|
2199
2299
|
var context = useCAMSContext();
|
|
2200
2300
|
var validatedMFAEndpoints = useMemo(function () {
|
|
2201
2301
|
var parsed = MFAEndpointsSchema.safeParse(MFAEndpoints);
|
|
@@ -2209,8 +2309,8 @@ var MFAGate = function (_a) {
|
|
|
2209
2309
|
if (!success)
|
|
2210
2310
|
Logger.error("MFA authentication failed");
|
|
2211
2311
|
}, []);
|
|
2212
|
-
var handleAuthFailed = useCallback(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
2213
|
-
return __generator(this, function (_a) {
|
|
2312
|
+
var handleAuthFailed = useCallback(function () { return __awaiter$1(void 0, void 0, void 0, function () {
|
|
2313
|
+
return __generator$1(this, function (_a) {
|
|
2214
2314
|
switch (_a.label) {
|
|
2215
2315
|
case 0: return [4 /*yield*/, context.logout()];
|
|
2216
2316
|
case 1:
|
|
@@ -2219,9 +2319,10 @@ var MFAGate = function (_a) {
|
|
|
2219
2319
|
}
|
|
2220
2320
|
});
|
|
2221
2321
|
}); }, [context.logout]);
|
|
2222
|
-
|
|
2322
|
+
if (useADLogin && !CredentialsAuthEndpoint)
|
|
2323
|
+
return jsxRuntimeExports.jsx(ErrorFallback, { message: "Invalid AD Login Configuration." });
|
|
2223
2324
|
if (!validatedMFAEndpoints)
|
|
2224
|
-
return jsxRuntimeExports.jsx(ErrorFallback, { message: "Invalid MFA
|
|
2325
|
+
return jsxRuntimeExports.jsx(ErrorFallback, { message: "Invalid MFA Configuration." });
|
|
2225
2326
|
if (context.authMode !== "MSAL")
|
|
2226
2327
|
return jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: children });
|
|
2227
2328
|
if (context.isLoading)
|
|
@@ -2230,7 +2331,7 @@ var MFAGate = function (_a) {
|
|
|
2230
2331
|
return (jsxRuntimeExports.jsx(MFAOptions, { MFAEndpoints: validatedMFAEndpoints, usePassKey: usePassKey, onComplete: handleComplete, onAuthFailed: handleAuthFailed }));
|
|
2231
2332
|
}
|
|
2232
2333
|
if (!context.isAuthenticated) {
|
|
2233
|
-
return (jsxRuntimeExports.jsx(DefaultLoginPage, { usePassKey: usePassKey, MFAEndpoints: MFAEndpoints, PassKeysRegisterProps: PassKeysRegisterProps }));
|
|
2334
|
+
return (jsxRuntimeExports.jsx(DefaultLoginPage, { usePassKey: usePassKey, useADLogin: useADLogin, MFAEndpoints: MFAEndpoints, PassKeysRegisterProps: PassKeysRegisterProps, CredentialsAuthEndpoint: CredentialsAuthEndpoint }));
|
|
2234
2335
|
}
|
|
2235
2336
|
return jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: children });
|
|
2236
2337
|
};
|