@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.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);
|
|
@@ -40,6 +41,27 @@ var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
|
40
41
|
var LabelPrimitive__namespace = /*#__PURE__*/_interopNamespaceDefault(LabelPrimitive);
|
|
41
42
|
var DialogPrimitive__namespace = /*#__PURE__*/_interopNamespaceDefault(DialogPrimitive);
|
|
42
43
|
|
|
44
|
+
var _a;
|
|
45
|
+
// Crypto polyfill for environments where crypto is not available
|
|
46
|
+
if (typeof window !== 'undefined' && !window.crypto) {
|
|
47
|
+
var crypto_1 = require('crypto');
|
|
48
|
+
// @ts-ignore
|
|
49
|
+
window.crypto = {
|
|
50
|
+
getRandomValues: function (arr) {
|
|
51
|
+
var bytes = crypto_1.randomBytes(arr.length);
|
|
52
|
+
for (var i = 0; i < arr.length; i++) {
|
|
53
|
+
arr[i] = bytes[i];
|
|
54
|
+
}
|
|
55
|
+
return arr;
|
|
56
|
+
},
|
|
57
|
+
subtle: ((_a = crypto_1.webcrypto) === null || _a === void 0 ? void 0 : _a.subtle) || {
|
|
58
|
+
digest: function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
59
|
+
throw new Error('crypto.subtle not available');
|
|
60
|
+
}); }); }
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
43
65
|
/******************************************************************************
|
|
44
66
|
Copyright (c) Microsoft Corporation.
|
|
45
67
|
|
|
@@ -80,7 +102,7 @@ function __rest(s, e) {
|
|
|
80
102
|
return t;
|
|
81
103
|
}
|
|
82
104
|
|
|
83
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
105
|
+
function __awaiter$1(thisArg, _arguments, P, generator) {
|
|
84
106
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
85
107
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
86
108
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
@@ -90,7 +112,7 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
90
112
|
});
|
|
91
113
|
}
|
|
92
114
|
|
|
93
|
-
function __generator(thisArg, body) {
|
|
115
|
+
function __generator$1(thisArg, body) {
|
|
94
116
|
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);
|
|
95
117
|
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
96
118
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
@@ -187,10 +209,10 @@ function useCAMSAuth(options) {
|
|
|
187
209
|
}
|
|
188
210
|
}
|
|
189
211
|
}, [options.storageKey]);
|
|
190
|
-
var login = React.useCallback(function (config) { return __awaiter(_this, void 0, void 0, function () {
|
|
212
|
+
var login = React.useCallback(function (config) { return __awaiter$1(_this, void 0, void 0, function () {
|
|
191
213
|
var loginConfig, userProfile, err_1, e, isPopupClosedError, restoredToken, userProfile;
|
|
192
214
|
var _a, _b, _c;
|
|
193
|
-
return __generator(this, function (_d) {
|
|
215
|
+
return __generator$1(this, function (_d) {
|
|
194
216
|
switch (_d.label) {
|
|
195
217
|
case 0:
|
|
196
218
|
if (!sessionManagerRef.current)
|
|
@@ -238,8 +260,8 @@ function useCAMSAuth(options) {
|
|
|
238
260
|
}
|
|
239
261
|
});
|
|
240
262
|
}); }, [options.idleTimeout]);
|
|
241
|
-
var logout = React.useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
242
|
-
return __generator(this, function (_a) {
|
|
263
|
+
var logout = React.useCallback(function () { return __awaiter$1(_this, void 0, void 0, function () {
|
|
264
|
+
return __generator$1(this, function (_a) {
|
|
243
265
|
switch (_a.label) {
|
|
244
266
|
case 0:
|
|
245
267
|
if (!sessionManagerRef.current)
|
|
@@ -332,7 +354,6 @@ function useCAMSMSALAuth(options) {
|
|
|
332
354
|
setMfaAuthenticator(authenticator);
|
|
333
355
|
setRequiresMFA(true);
|
|
334
356
|
}
|
|
335
|
-
camsSdk.Logger.debug("App Code", { ">>>": options.appCode });
|
|
336
357
|
}
|
|
337
358
|
else {
|
|
338
359
|
localStorage.removeItem(storageKey);
|
|
@@ -374,10 +395,10 @@ function useCAMSMSALAuth(options) {
|
|
|
374
395
|
// };
|
|
375
396
|
// handleRedirect();
|
|
376
397
|
// }, []);
|
|
377
|
-
var login = React.useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
398
|
+
var login = React.useCallback(function () { return __awaiter$1(_this, void 0, void 0, function () {
|
|
378
399
|
var response, mfaConfig, authenticator, err_1, camsError_1, camsError;
|
|
379
400
|
var _a, _b, _c, _d;
|
|
380
|
-
return __generator(this, function (_e) {
|
|
401
|
+
return __generator$1(this, function (_e) {
|
|
381
402
|
switch (_e.label) {
|
|
382
403
|
case 0:
|
|
383
404
|
setError(null);
|
|
@@ -441,8 +462,8 @@ function useCAMSMSALAuth(options) {
|
|
|
441
462
|
}
|
|
442
463
|
});
|
|
443
464
|
}); }, [instance, scopes, options]);
|
|
444
|
-
var completeMFA = React.useCallback(function (data) { return __awaiter(_this, void 0, void 0, function () {
|
|
445
|
-
return __generator(this, function (_a) {
|
|
465
|
+
var completeMFA = React.useCallback(function (data) { return __awaiter$1(_this, void 0, void 0, function () {
|
|
466
|
+
return __generator$1(this, function (_a) {
|
|
446
467
|
if (!mfaAuthenticator) {
|
|
447
468
|
throw new camsSdk.CAMSError(camsSdk.CAMSErrorType.API_VALIDATION_ERROR, "MFA Authenticator not initialized");
|
|
448
469
|
}
|
|
@@ -476,8 +497,8 @@ function useCAMSMSALAuth(options) {
|
|
|
476
497
|
return [2 /*return*/];
|
|
477
498
|
});
|
|
478
499
|
}); }, [mfaAuthenticator, accessToken, idToken, storageKey]);
|
|
479
|
-
var sendEmailOTP = React.useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
480
|
-
return __generator(this, function (_a) {
|
|
500
|
+
var sendEmailOTP = React.useCallback(function () { return __awaiter$1(_this, void 0, void 0, function () {
|
|
501
|
+
return __generator$1(this, function (_a) {
|
|
481
502
|
switch (_a.label) {
|
|
482
503
|
case 0:
|
|
483
504
|
if (!mfaAuthenticator) {
|
|
@@ -488,9 +509,9 @@ function useCAMSMSALAuth(options) {
|
|
|
488
509
|
}
|
|
489
510
|
});
|
|
490
511
|
}); }, [mfaAuthenticator]);
|
|
491
|
-
var logout = React.useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
512
|
+
var logout = React.useCallback(function () { return __awaiter$1(_this, void 0, void 0, function () {
|
|
492
513
|
var err_2, camsError;
|
|
493
|
-
return __generator(this, function (_a) {
|
|
514
|
+
return __generator$1(this, function (_a) {
|
|
494
515
|
switch (_a.label) {
|
|
495
516
|
case 0:
|
|
496
517
|
_a.trys.push([0, 2, , 3]);
|
|
@@ -574,29 +595,21 @@ function arrayBufferToBase64url(buffer) {
|
|
|
574
595
|
* @returns A promise that resolves to a JSON-serializable representation of the PublicKeyCredential.
|
|
575
596
|
*/
|
|
576
597
|
function register(options) {
|
|
577
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
598
|
+
return __awaiter$1(this, void 0, void 0, function () {
|
|
578
599
|
var createOptions, credential, publicKeyCredential, attestationResponse, transports, err_1;
|
|
579
600
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
580
|
-
return __generator(this, function (_k) {
|
|
601
|
+
return __generator$1(this, function (_k) {
|
|
581
602
|
switch (_k.label) {
|
|
582
603
|
case 0:
|
|
583
604
|
_k.trys.push([0, 2, , 3]);
|
|
584
605
|
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
606
|
return [4 /*yield*/, navigator.credentials.create({
|
|
587
|
-
publicKey: __assign(__assign({},
|
|
607
|
+
publicKey: __assign(__assign({}, createOptions), { pubKeyCredParams: (_a = options.pubKeyCredParams) === null || _a === void 0 ? void 0 : _a.map(function (param) { return ({
|
|
588
608
|
type: "public-key",
|
|
589
609
|
alg: param.alg,
|
|
590
|
-
}); }), attestation: (((_b = options.attestation) === null || _b === void 0 ? void 0 : _b.toLowerCase()) || "none"), authenticatorSelection: __assign(__assign({}, options.authenticatorSelection), {
|
|
591
|
-
// authenticatorAttachment:
|
|
592
|
-
// (options.authenticatorSelection?.authenticatorAttachment?.toLowerCase() ||
|
|
593
|
-
// "platform") as AuthenticatorAttachment,
|
|
594
|
-
// requireResidentKey:
|
|
595
|
-
// (options.authenticatorSelection?.requireResidentKey?.toLowerCase() ||
|
|
596
|
-
// "false") === "true",
|
|
597
|
-
residentKey: (((_d = (_c = options.authenticatorSelection) === null || _c === void 0 ? void 0 : _c.residentKey) === null || _d === void 0 ? void 0 : _d.toLowerCase()) ||
|
|
610
|
+
}); }), attestation: (((_b = options.attestation) === null || _b === void 0 ? void 0 : _b.toLowerCase()) || "none"), authenticatorSelection: __assign(__assign({}, options.authenticatorSelection), { residentKey: (((_d = (_c = options.authenticatorSelection) === null || _c === void 0 ? void 0 : _c.residentKey) === null || _d === void 0 ? void 0 : _d.toLowerCase()) ||
|
|
598
611
|
"discouraged"), userVerification: (((_f = (_e = options.authenticatorSelection) === null || _e === void 0 ? void 0 : _e.userVerification) === null || _f === void 0 ? void 0 : _f.toLowerCase()) ||
|
|
599
|
-
"
|
|
612
|
+
"discouraged") }) }),
|
|
600
613
|
})];
|
|
601
614
|
case 1:
|
|
602
615
|
credential = _k.sent();
|
|
@@ -617,12 +630,16 @@ function register(options) {
|
|
|
617
630
|
}];
|
|
618
631
|
case 2:
|
|
619
632
|
err_1 = _k.sent();
|
|
633
|
+
console.error("Error during registration:", err_1);
|
|
620
634
|
if (err_1.name === "NotAllowedError") {
|
|
621
|
-
throw new Error("
|
|
635
|
+
throw new Error("Face ID/Touch ID cancelled or failed. Please try again.");
|
|
622
636
|
}
|
|
623
637
|
if (err_1.name === "InvalidStateError") {
|
|
624
638
|
throw new Error("Passkey already registered for this user.");
|
|
625
639
|
}
|
|
640
|
+
if (err_1.name === "NotSupportedError") {
|
|
641
|
+
throw new Error("Passkeys not supported on this device.");
|
|
642
|
+
}
|
|
626
643
|
throw err_1;
|
|
627
644
|
case 3: return [2 /*return*/];
|
|
628
645
|
}
|
|
@@ -639,10 +656,10 @@ function register(options) {
|
|
|
639
656
|
* @returns A promise that resolves to a JSON-serializable representation of the PublicKeyCredential.
|
|
640
657
|
*/
|
|
641
658
|
function authenticate(options) {
|
|
642
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
659
|
+
return __awaiter$1(this, void 0, void 0, function () {
|
|
643
660
|
var getOptions, credential, publicKeyCredential, assertionResponse;
|
|
644
661
|
var _a;
|
|
645
|
-
return __generator(this, function (_b) {
|
|
662
|
+
return __generator$1(this, function (_b) {
|
|
646
663
|
switch (_b.label) {
|
|
647
664
|
case 0:
|
|
648
665
|
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) })); }) });
|
|
@@ -1210,8 +1227,8 @@ function CAMSMSALProviderInner(_a) {
|
|
|
1210
1227
|
}
|
|
1211
1228
|
}, [userProfile, profileStorageKey]);
|
|
1212
1229
|
// Enhanced logout that also clears profile
|
|
1213
|
-
var enhancedLogout = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
1214
|
-
return __generator(this, function (_a) {
|
|
1230
|
+
var enhancedLogout = function () { return __awaiter$1(_this, void 0, void 0, function () {
|
|
1231
|
+
return __generator$1(this, function (_a) {
|
|
1215
1232
|
switch (_a.label) {
|
|
1216
1233
|
case 0: return [4 /*yield*/, auth.logout()];
|
|
1217
1234
|
case 1:
|
|
@@ -1307,8 +1324,8 @@ function CAMSProviderCore(props) {
|
|
|
1307
1324
|
}
|
|
1308
1325
|
}
|
|
1309
1326
|
}, [userProfile, profileStorageKey]);
|
|
1310
|
-
var enhancedLogout = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
1311
|
-
return __generator(this, function (_a) {
|
|
1327
|
+
var enhancedLogout = function () { return __awaiter$1(_this, void 0, void 0, function () {
|
|
1328
|
+
return __generator$1(this, function (_a) {
|
|
1312
1329
|
switch (_a.label) {
|
|
1313
1330
|
case 0: return [4 /*yield*/, auth.logout()];
|
|
1314
1331
|
case 1:
|
|
@@ -1727,7 +1744,7 @@ styleInject(css_248z);
|
|
|
1727
1744
|
|
|
1728
1745
|
var LoadingSpinner = function (_a) {
|
|
1729
1746
|
var loadingText = _a.loadingText;
|
|
1730
|
-
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..." }))] }));
|
|
1747
|
+
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..." }))] }));
|
|
1731
1748
|
};
|
|
1732
1749
|
|
|
1733
1750
|
var AuthSuccessAnimation = function (_a) {
|
|
@@ -1744,7 +1761,7 @@ var GenerateDeviceId = function () {
|
|
|
1744
1761
|
var userAgent = window.navigator.userAgent;
|
|
1745
1762
|
var deviceId = "";
|
|
1746
1763
|
// Parse browser, version, OS, and device type
|
|
1747
|
-
var browserMatch = Array.from(userAgent.matchAll(/(Chrome|Firefox|Safari|Edge|Opera)\/([\d.]+)/
|
|
1764
|
+
var browserMatch = Array.from(userAgent.matchAll(/(Chrome|Firefox|Safari|Edge|Opera)\/([\d.]+)/gi));
|
|
1748
1765
|
var osMatch = Array.from(userAgent.matchAll(/\(([^)]+)\)/g));
|
|
1749
1766
|
var isMobile = /Mobile|Android|iPhone|iPad/i.test(userAgent);
|
|
1750
1767
|
// Browser info
|
|
@@ -1774,6 +1791,31 @@ var GenerateDeviceId = function () {
|
|
|
1774
1791
|
deviceId += "_".concat(hash);
|
|
1775
1792
|
return (_a = deviceId.replace(/[^a-zA-Z0-9-_]/g, "_")) !== null && _a !== void 0 ? _a : "unknown-device";
|
|
1776
1793
|
};
|
|
1794
|
+
var APIHeaders = {
|
|
1795
|
+
"X-DEVICE-ID": GenerateDeviceId(),
|
|
1796
|
+
"X-API-VERSION": "1.0",
|
|
1797
|
+
};
|
|
1798
|
+
|
|
1799
|
+
// Creates an Axios instance with a base URL determined by the environment (production or development).
|
|
1800
|
+
var axiosInstance = axios.create({
|
|
1801
|
+
httpsAgent: new https.Agent({ rejectUnauthorized: false }),
|
|
1802
|
+
headers: __assign({ "Content-Type": "application/json" }, APIHeaders),
|
|
1803
|
+
});
|
|
1804
|
+
// Intercepts outgoing requests to add authorization token, version header, and timeout settings.
|
|
1805
|
+
axiosInstance.interceptors.request.use(function (config) {
|
|
1806
|
+
var _a;
|
|
1807
|
+
config.timeout = Number((_a = process.env.NEXT_PUBLIC_API_TIMEOUT) !== null && _a !== void 0 ? _a : 605000);
|
|
1808
|
+
config.timeoutErrorMessage = "Operation Timed Out"; // Custom error message for timeouts.
|
|
1809
|
+
return config; // Returns the modified request configuration.
|
|
1810
|
+
}, function (axiosError) {
|
|
1811
|
+
var _a, _b;
|
|
1812
|
+
// Handles request errors.
|
|
1813
|
+
return {
|
|
1814
|
+
status: (_a = axiosError.response) === null || _a === void 0 ? void 0 : _a.status, // Extracts HTTP status from the error response.
|
|
1815
|
+
message: axiosError.message, // Extracts the error message.
|
|
1816
|
+
data: (_b = axiosError.response) === null || _b === void 0 ? void 0 : _b.data, // Extracts response data from the error.
|
|
1817
|
+
};
|
|
1818
|
+
});
|
|
1777
1819
|
|
|
1778
1820
|
var MAX_ATTEMPTS = 3;
|
|
1779
1821
|
var useOTPHandler = function (_a) {
|
|
@@ -1781,9 +1823,9 @@ var useOTPHandler = function (_a) {
|
|
|
1781
1823
|
var _b = React.useState(false), loading = _b[0], setLoading = _b[1];
|
|
1782
1824
|
var _c = React.useState(0), attemptCount = _c[0], setAttemptCount = _c[1];
|
|
1783
1825
|
var _d = React.useState(false), isMaxAttemptsReached = _d[0], setIsMaxAttemptsReached = _d[1];
|
|
1784
|
-
var handleSubmitOTP = React.useMemo(function () { return function (authenticationValue) { return __awaiter(void 0, void 0, void 0, function () {
|
|
1826
|
+
var handleSubmitOTP = React.useMemo(function () { return function (authenticationValue) { return __awaiter$1(void 0, void 0, void 0, function () {
|
|
1785
1827
|
var currentAttempt, response, error_1, currentAttempt;
|
|
1786
|
-
return __generator(this, function (_a) {
|
|
1828
|
+
return __generator$1(this, function (_a) {
|
|
1787
1829
|
switch (_a.label) {
|
|
1788
1830
|
case 0:
|
|
1789
1831
|
if (isMaxAttemptsReached) {
|
|
@@ -1800,18 +1842,13 @@ var useOTPHandler = function (_a) {
|
|
|
1800
1842
|
setAttemptCount(currentAttempt);
|
|
1801
1843
|
if (authenticationType === null)
|
|
1802
1844
|
return [2 /*return*/, false];
|
|
1803
|
-
return [4 /*yield*/,
|
|
1845
|
+
return [4 /*yield*/, axiosInstance.post(MFAEndpoint || "/api/auth/verify-mfa", {
|
|
1804
1846
|
provider: provider,
|
|
1805
1847
|
accessToken: accessToken,
|
|
1806
1848
|
idToken: idToken,
|
|
1807
1849
|
authenticationType: authenticationType,
|
|
1808
1850
|
MFACode: authenticationValue,
|
|
1809
1851
|
appCode: appCode,
|
|
1810
|
-
}, {
|
|
1811
|
-
headers: {
|
|
1812
|
-
"X-Device-ID": GenerateDeviceId(),
|
|
1813
|
-
},
|
|
1814
|
-
timeout: 605000,
|
|
1815
1852
|
})];
|
|
1816
1853
|
case 2:
|
|
1817
1854
|
response = (_a.sent()).data;
|
|
@@ -1873,6 +1910,75 @@ var useOTPHandler = function (_a) {
|
|
|
1873
1910
|
remainingAttempts: MAX_ATTEMPTS - attemptCount,
|
|
1874
1911
|
};
|
|
1875
1912
|
};
|
|
1913
|
+
var useCredentialsHandler = function (onAuthComplete) {
|
|
1914
|
+
var _a = React.useState(false), loading = _a[0], setLoading = _a[1];
|
|
1915
|
+
var _b = React.useState(0), attemptCount = _b[0], setAttemptCount = _b[1];
|
|
1916
|
+
var _c = React.useState(false), isMaxAttemptsReached = _c[0], setIsMaxAttemptsReached = _c[1];
|
|
1917
|
+
var handleSubmitCredentials = React.useMemo(function () {
|
|
1918
|
+
return function (CredAuthEndpoint, credentials, appCode) { return __awaiter$1(void 0, void 0, void 0, function () {
|
|
1919
|
+
var currentAttempt, response, error_2, currentAttempt;
|
|
1920
|
+
return __generator$1(this, function (_a) {
|
|
1921
|
+
switch (_a.label) {
|
|
1922
|
+
case 0:
|
|
1923
|
+
_a.trys.push([0, 2, 3, 4]);
|
|
1924
|
+
setLoading(true);
|
|
1925
|
+
currentAttempt = attemptCount + 1;
|
|
1926
|
+
setAttemptCount(currentAttempt);
|
|
1927
|
+
return [4 /*yield*/, axiosInstance.post(CredAuthEndpoint, {
|
|
1928
|
+
username: credentials.username,
|
|
1929
|
+
password: credentials.password,
|
|
1930
|
+
MFACode: credentials.MFACode,
|
|
1931
|
+
appCode: appCode,
|
|
1932
|
+
})];
|
|
1933
|
+
case 1:
|
|
1934
|
+
response = (_a.sent()).data;
|
|
1935
|
+
if (response) {
|
|
1936
|
+
onAuthComplete(true, response);
|
|
1937
|
+
return [2 /*return*/, true];
|
|
1938
|
+
}
|
|
1939
|
+
else {
|
|
1940
|
+
if (currentAttempt >= MAX_ATTEMPTS) {
|
|
1941
|
+
setIsMaxAttemptsReached(true);
|
|
1942
|
+
onAuthComplete(false, {
|
|
1943
|
+
message: "Maximum attempts reached",
|
|
1944
|
+
});
|
|
1945
|
+
}
|
|
1946
|
+
else {
|
|
1947
|
+
onAuthComplete(false, response.response.data);
|
|
1948
|
+
}
|
|
1949
|
+
return [2 /*return*/, false];
|
|
1950
|
+
}
|
|
1951
|
+
case 2:
|
|
1952
|
+
error_2 = _a.sent();
|
|
1953
|
+
console.error(error_2);
|
|
1954
|
+
currentAttempt = attemptCount + 1;
|
|
1955
|
+
if (currentAttempt >= MAX_ATTEMPTS) {
|
|
1956
|
+
setIsMaxAttemptsReached(true);
|
|
1957
|
+
onAuthComplete(false, error_2.response.data);
|
|
1958
|
+
}
|
|
1959
|
+
else {
|
|
1960
|
+
onAuthComplete(false, error_2.response.data);
|
|
1961
|
+
}
|
|
1962
|
+
onAuthComplete(false, error_2.response.data);
|
|
1963
|
+
return [2 /*return*/, false];
|
|
1964
|
+
case 3:
|
|
1965
|
+
setLoading(false);
|
|
1966
|
+
return [7 /*endfinally*/];
|
|
1967
|
+
case 4: return [2 /*return*/];
|
|
1968
|
+
}
|
|
1969
|
+
});
|
|
1970
|
+
}); };
|
|
1971
|
+
}, []);
|
|
1972
|
+
return {
|
|
1973
|
+
handleSubmitCredentials: handleSubmitCredentials,
|
|
1974
|
+
loading: loading,
|
|
1975
|
+
setLoading: setLoading,
|
|
1976
|
+
attemptCount: attemptCount,
|
|
1977
|
+
isMaxAttemptsReached: isMaxAttemptsReached,
|
|
1978
|
+
// resetAttempts,
|
|
1979
|
+
remainingAttempts: MAX_ATTEMPTS - attemptCount,
|
|
1980
|
+
};
|
|
1981
|
+
};
|
|
1876
1982
|
|
|
1877
1983
|
var MFAOptions = function (_a) {
|
|
1878
1984
|
var onComplete = _a.onComplete, onAuthFailed = _a.onAuthFailed, MFAEndpoints = _a.MFAEndpoints, usePassKey = _a.usePassKey;
|
|
@@ -1883,54 +1989,39 @@ var MFAOptions = function (_a) {
|
|
|
1883
1989
|
var context = useCAMSContext();
|
|
1884
1990
|
var _f = context.authMode === "MSAL" && "sendEmailOTP" in context
|
|
1885
1991
|
? context
|
|
1886
|
-
: { sendEmailOTP: null, completeMFA: null, logout: function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
1992
|
+
: { sendEmailOTP: null, completeMFA: null, logout: function () { return __awaiter$1(void 0, void 0, void 0, function () { return __generator$1(this, function (_a) {
|
|
1887
1993
|
return [2 /*return*/];
|
|
1888
1994
|
}); }); } }, sendEmailOTP = _f.sendEmailOTP, completeMFA = _f.completeMFA, logout = _f.logout;
|
|
1889
1995
|
var accessToken = context.authMode === "MSAL" ? context.accessToken : "";
|
|
1890
1996
|
var idToken = context.authMode === "MSAL" ? context.idToken : "";
|
|
1891
1997
|
var authenticate = useWebAuthn().authenticate;
|
|
1892
|
-
var handleFIDOLogin = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
1998
|
+
var handleFIDOLogin = function () { return __awaiter$1(void 0, void 0, void 0, function () {
|
|
1893
1999
|
var options, assertionResponse, error_1;
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
switch (_g.label) {
|
|
2000
|
+
return __generator$1(this, function (_a) {
|
|
2001
|
+
switch (_a.label) {
|
|
1897
2002
|
case 0:
|
|
1898
|
-
|
|
2003
|
+
_a.trys.push([0, 4, , 5]);
|
|
1899
2004
|
// 1. Fetch authentication challenge from your server
|
|
1900
2005
|
console.log("Requesting authentication challenge from server...");
|
|
1901
|
-
return [4 /*yield*/,
|
|
1902
|
-
headers: {
|
|
1903
|
-
"X-DEVICE-ID": GenerateDeviceId(),
|
|
1904
|
-
"X-API-VERSION": "1.0",
|
|
1905
|
-
},
|
|
1906
|
-
})];
|
|
2006
|
+
return [4 /*yield*/, axiosInstance.post(MFAEndpoints.RetrieveAuthChallenge, {})];
|
|
1907
2007
|
case 1:
|
|
1908
|
-
options = (
|
|
2008
|
+
options = (_a.sent()).data;
|
|
1909
2009
|
console.log("Received challenge:", options);
|
|
1910
2010
|
// 2. Call the SDK to trigger the browser's passkey authentication UI
|
|
1911
2011
|
console.log("Calling SDK authenticate function...");
|
|
1912
|
-
return [4 /*yield*/, authenticate(__assign(__assign({}, options), {
|
|
1913
|
-
type: "public-key",
|
|
1914
|
-
alg: param.alg
|
|
1915
|
-
}); }), attestation: ((_b = options.attestation) === null || _b === void 0 ? void 0 : _b.toLowerCase()) || "none", authenticatorSelection: __assign(__assign({}, options.authenticatorSelection), { residentKey: ((_d = (_c = options.authenticatorSelection) === null || _c === void 0 ? void 0 : _c.residentKey) === null || _d === void 0 ? void 0 : _d.toLowerCase()) || "discouraged", userVerification: ((_f = (_e = options.authenticatorSelection) === null || _e === void 0 ? void 0 : _e.userVerification) === null || _f === void 0 ? void 0 : _f.toLowerCase()) || "preferred" }) }))];
|
|
2012
|
+
return [4 /*yield*/, authenticate(__assign(__assign({}, options), { userVerification: "discouraged" }))];
|
|
1916
2013
|
case 2:
|
|
1917
|
-
assertionResponse =
|
|
2014
|
+
assertionResponse = _a.sent();
|
|
1918
2015
|
console.log("Authentication assertion received from client:", assertionResponse);
|
|
1919
2016
|
// 3. Send the assertion back to the server for verification
|
|
1920
2017
|
console.log("Sending assertion to server for verification...");
|
|
1921
|
-
return [4 /*yield*/,
|
|
1922
|
-
headers: {
|
|
1923
|
-
"X-DEVICE-ID": GenerateDeviceId(),
|
|
1924
|
-
"X-API-VERSION": "1.0",
|
|
1925
|
-
},
|
|
1926
|
-
withCredentials: true, // credentials: 'include'
|
|
1927
|
-
})];
|
|
2018
|
+
return [4 /*yield*/, axiosInstance.post(MFAEndpoints.AuthChallengeVerify, assertionResponse)];
|
|
1928
2019
|
case 3:
|
|
1929
|
-
|
|
2020
|
+
_a.sent();
|
|
1930
2021
|
sonner.toast.success("🔑 Sign-in successful!");
|
|
1931
2022
|
return [3 /*break*/, 5];
|
|
1932
2023
|
case 4:
|
|
1933
|
-
error_1 =
|
|
2024
|
+
error_1 = _a.sent();
|
|
1934
2025
|
console.error("Authentication failed:", error_1);
|
|
1935
2026
|
sonner.toast.error("❌ Could not sign in.");
|
|
1936
2027
|
return [3 /*break*/, 5];
|
|
@@ -1986,12 +2077,12 @@ var MFAOptions = function (_a) {
|
|
|
1986
2077
|
}
|
|
1987
2078
|
var content = jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, {});
|
|
1988
2079
|
if (!authType) {
|
|
1989
|
-
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 () {
|
|
2080
|
+
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 () {
|
|
1990
2081
|
var success;
|
|
1991
|
-
return __generator(this, function (_a) {
|
|
2082
|
+
return __generator$1(this, function (_a) {
|
|
1992
2083
|
switch (_a.label) {
|
|
1993
2084
|
case 0:
|
|
1994
|
-
resetAttempts();
|
|
2085
|
+
// resetAttempts();
|
|
1995
2086
|
setAuthType("EmailOTP");
|
|
1996
2087
|
setOtpVisible(true);
|
|
1997
2088
|
if (!sendEmailOTP) return [3 /*break*/, 2];
|
|
@@ -2008,7 +2099,6 @@ var MFAOptions = function (_a) {
|
|
|
2008
2099
|
}
|
|
2009
2100
|
});
|
|
2010
2101
|
}); }, 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 () {
|
|
2011
|
-
resetAttempts();
|
|
2012
2102
|
setAuthType("AuthenticatorCode");
|
|
2013
2103
|
setOtpVisible(true);
|
|
2014
2104
|
}, 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",
|
|
@@ -2017,7 +2107,7 @@ var MFAOptions = function (_a) {
|
|
|
2017
2107
|
// setAuthType("AuthenticatorCode");
|
|
2018
2108
|
// setOtpVisible(true);
|
|
2019
2109
|
// }}
|
|
2020
|
-
onClick: handleFIDOLogin, disabled: context.isLoading, children: [jsxRuntimeExports.jsx(
|
|
2110
|
+
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" })] })] }))] })] }));
|
|
2021
2111
|
}
|
|
2022
2112
|
else if (authType === "EmailOTP") {
|
|
2023
2113
|
content = (jsxRuntimeExports.jsx(Dialog, { open: otpVisible, onOpenChange: function () {
|
|
@@ -2049,28 +2139,27 @@ var credentialsSchema = z.z.object({
|
|
|
2049
2139
|
password: z.z.string().min(1, "Password is required"),
|
|
2050
2140
|
});
|
|
2051
2141
|
var ADLoginModal = function (_a) {
|
|
2052
|
-
var open = _a.open, onOpenChange = _a.onOpenChange, onLogin = _a.onLogin;
|
|
2142
|
+
var open = _a.open, isLoading = _a.isLoading, setIsLoading = _a.setIsLoading, onOpenChange = _a.onOpenChange, onLogin = _a.onLogin;
|
|
2053
2143
|
var _b = React.useState("credentials"), step = _b[0], setStep = _b[1];
|
|
2054
2144
|
var _c = React.useState({
|
|
2055
2145
|
username: "",
|
|
2056
2146
|
password: "",
|
|
2057
2147
|
}), credentials = _c[0], setCredentials = _c[1];
|
|
2058
2148
|
var _d = React.useState(""), mfaCode = _d[0], setMfaCode = _d[1];
|
|
2059
|
-
var _e = React.useState(false), isLoading = _e[0], setIsLoading = _e[1];
|
|
2060
2149
|
var form = reactHookForm.useForm({
|
|
2061
2150
|
resolver: a$1(credentialsSchema),
|
|
2062
2151
|
defaultValues: { username: "", password: "" },
|
|
2063
2152
|
});
|
|
2064
|
-
var handleCredentialsSubmit = function (values) { return __awaiter(void 0, void 0, void 0, function () {
|
|
2065
|
-
return __generator(this, function (_a) {
|
|
2153
|
+
var handleCredentialsSubmit = function (values) { return __awaiter$1(void 0, void 0, void 0, function () {
|
|
2154
|
+
return __generator$1(this, function (_a) {
|
|
2066
2155
|
setCredentials(values);
|
|
2067
2156
|
setStep("mfa");
|
|
2068
2157
|
return [2 /*return*/];
|
|
2069
2158
|
});
|
|
2070
2159
|
}); };
|
|
2071
|
-
var handleMFASubmit = function (code) { return __awaiter(void 0, void 0, void 0, function () {
|
|
2160
|
+
var handleMFASubmit = function (code) { return __awaiter$1(void 0, void 0, void 0, function () {
|
|
2072
2161
|
var error_1;
|
|
2073
|
-
return __generator(this, function (_a) {
|
|
2162
|
+
return __generator$1(this, function (_a) {
|
|
2074
2163
|
switch (_a.label) {
|
|
2075
2164
|
case 0:
|
|
2076
2165
|
setIsLoading(true);
|
|
@@ -2106,22 +2195,50 @@ var ADLoginModal = function (_a) {
|
|
|
2106
2195
|
form.reset();
|
|
2107
2196
|
setMfaCode("");
|
|
2108
2197
|
};
|
|
2109
|
-
return (jsxRuntimeExports.jsx(Dialog, { open: open, onOpenChange: handleClose, children: jsxRuntimeExports.jsxs(DialogContent, { className: "
|
|
2198
|
+
return (jsxRuntimeExports.jsx(Dialog, { open: open, onOpenChange: handleClose, children: jsxRuntimeExports.jsxs(DialogContent, { className: "min-w-[50vw] max-w-[70vw]", children: [jsxRuntimeExports.jsx(DialogHeader, { children: jsxRuntimeExports.jsxs("div", { className: "flex items-center gap-2", children: [jsxRuntimeExports.jsx(lucideReact.KeyIcon, { className: "w-8 h-8 text-[#506f4a]" }), jsxRuntimeExports.jsx(DialogTitle, { className: "text-2xl", children: "Sign in with AD" })] }) }), step === "credentials" ? (jsxRuntimeExports.jsx(Form, __assign({}, form, { children: jsxRuntimeExports.jsxs("form", { onSubmit: form.handleSubmit(handleCredentialsSubmit), className: "space-y-4", children: [jsxRuntimeExports.jsx(FormField, { control: form.control, name: "username", render: function (_a) {
|
|
2110
2199
|
var field = _a.field;
|
|
2111
|
-
return (jsxRuntimeExports.jsxs(FormItem, { children: [jsxRuntimeExports.jsx(FormLabel, { children: "Username" }), jsxRuntimeExports.jsx(FormControl, { children: jsxRuntimeExports.jsx(Input, __assign({ placeholder: "Enter your username" }, field)) }), jsxRuntimeExports.jsx(FormMessage, {})] }));
|
|
2200
|
+
return (jsxRuntimeExports.jsxs(FormItem, { children: [jsxRuntimeExports.jsx(FormLabel, { children: "Username" }), jsxRuntimeExports.jsx(FormControl, { children: jsxRuntimeExports.jsx(Input, __assign({ className: "h-12", placeholder: "Enter your username" }, field)) }), jsxRuntimeExports.jsx(FormMessage, {})] }));
|
|
2112
2201
|
} }), jsxRuntimeExports.jsx(FormField, { control: form.control, name: "password", render: function (_a) {
|
|
2113
2202
|
var field = _a.field;
|
|
2114
|
-
return (jsxRuntimeExports.jsxs(FormItem, { children: [jsxRuntimeExports.jsx(FormLabel, { children: "Password" }), jsxRuntimeExports.jsx(FormControl, { children: jsxRuntimeExports.jsx(Input, __assign({ type: "password", placeholder: "Enter your password" }, field)) }), jsxRuntimeExports.jsx(FormMessage, {})] }));
|
|
2203
|
+
return (jsxRuntimeExports.jsxs(FormItem, { children: [jsxRuntimeExports.jsx(FormLabel, { children: "Password" }), jsxRuntimeExports.jsx(FormControl, { children: jsxRuntimeExports.jsx(Input, __assign({ className: "h-12", type: "password", placeholder: "Enter your password" }, field)) }), jsxRuntimeExports.jsx(FormMessage, {})] }));
|
|
2115
2204
|
} }), jsxRuntimeExports.jsx(Button, { type: "submit", className: "w-full bg-[#506f4a] hover:bg-[#506f4a]/90", children: "Continue" })] }) }))) : (jsxRuntimeExports.jsxs("div", { className: "space-y-4", children: [jsxRuntimeExports.jsx(GenericOTPVerifier, { value: mfaCode, setValue: setMfaCode, setLoading: setIsLoading, isDisabled: isLoading, onChangeOTP: handleMFASubmit, fieldName: "AuthenticatorCode" }), isLoading && (jsxRuntimeExports.jsxs("div", { className: "flex items-center justify-center gap-2 text-sm text-muted-foreground", children: [jsxRuntimeExports.jsx(lucideReact.Loader2, { className: "w-4 h-4 animate-spin" }), jsxRuntimeExports.jsx("span", { children: "Verifying..." })] }))] }))] }) }));
|
|
2116
2205
|
};
|
|
2117
2206
|
|
|
2118
2207
|
var DefaultLoginPage = function (_a) {
|
|
2119
|
-
var usePassKey = _a.usePassKey, MFAEndpoints = _a.MFAEndpoints, PassKeysRegisterProps = _a.PassKeysRegisterProps;
|
|
2208
|
+
var usePassKey = _a.usePassKey, useADLogin = _a.useADLogin, MFAEndpoints = _a.MFAEndpoints, CredentialsAuthEndpoint = _a.CredentialsAuthEndpoint, PassKeysRegisterProps = _a.PassKeysRegisterProps;
|
|
2209
|
+
var cardVariants = {
|
|
2210
|
+
hidden: { opacity: 0, scale: 0.8, y: 50 },
|
|
2211
|
+
visible: {
|
|
2212
|
+
opacity: 1,
|
|
2213
|
+
scale: 1,
|
|
2214
|
+
y: 0,
|
|
2215
|
+
transition: { type: "spring", duration: 0.6 },
|
|
2216
|
+
},
|
|
2217
|
+
exit: { opacity: 0, scale: 0.8, y: -50, transition: { duration: 0.3 } },
|
|
2218
|
+
};
|
|
2120
2219
|
var context = useCAMSContext();
|
|
2121
2220
|
var login = context.login, isLoading = context.isLoading, authMode = context.authMode;
|
|
2122
2221
|
var _b = React.useState(false), showADModal = _b[0], setShowADModal = _b[1];
|
|
2123
2222
|
var register = useWebAuthn().register;
|
|
2223
|
+
var _c = useCredentialsHandler(function (state, data) { return __awaiter$1(void 0, void 0, void 0, function () {
|
|
2224
|
+
return __generator$1(this, function (_a) {
|
|
2225
|
+
console.log(data);
|
|
2226
|
+
if (state && data) {
|
|
2227
|
+
context.isAuthenticated = true;
|
|
2228
|
+
context.requiresMFA = false;
|
|
2229
|
+
context.setUserProfile({
|
|
2230
|
+
type: "AUTH_SUCCESS",
|
|
2231
|
+
userProfile: __assign({}, data),
|
|
2232
|
+
});
|
|
2233
|
+
}
|
|
2234
|
+
return [2 /*return*/];
|
|
2235
|
+
});
|
|
2236
|
+
}); }), handleSubmitCredentials = _c.handleSubmitCredentials, isCredAuthLoading = _c.loading, setIsCredAuthLoading = _c.setLoading;
|
|
2124
2237
|
var handleMSALLogin = function () {
|
|
2238
|
+
if (typeof window !== "undefined" && !window.crypto) {
|
|
2239
|
+
sonner.toast.error("Crypto API not available. Please use a modern browser.");
|
|
2240
|
+
return;
|
|
2241
|
+
}
|
|
2125
2242
|
if (authMode === "MSAL") {
|
|
2126
2243
|
login();
|
|
2127
2244
|
}
|
|
@@ -2130,30 +2247,15 @@ var DefaultLoginPage = function (_a) {
|
|
|
2130
2247
|
console.warn("Regular CAMS login requires configuration");
|
|
2131
2248
|
}
|
|
2132
2249
|
};
|
|
2133
|
-
var
|
|
2134
|
-
hidden: { opacity: 0, scale: 0.8, y: 50 },
|
|
2135
|
-
visible: {
|
|
2136
|
-
opacity: 1,
|
|
2137
|
-
scale: 1,
|
|
2138
|
-
y: 0,
|
|
2139
|
-
transition: { type: "spring", duration: 0.6 },
|
|
2140
|
-
},
|
|
2141
|
-
exit: { opacity: 0, scale: 0.8, y: -50, transition: { duration: 0.3 } },
|
|
2142
|
-
};
|
|
2143
|
-
var handleRegister = function (data) { return __awaiter(void 0, void 0, void 0, function () {
|
|
2250
|
+
var handleRegister = function (data) { return __awaiter$1(void 0, void 0, void 0, function () {
|
|
2144
2251
|
var options, attestationResponse, error_1;
|
|
2145
|
-
return __generator(this, function (_a) {
|
|
2252
|
+
return __generator$1(this, function (_a) {
|
|
2146
2253
|
switch (_a.label) {
|
|
2147
2254
|
case 0:
|
|
2148
2255
|
_a.trys.push([0, 4, , 5]);
|
|
2149
2256
|
// 1. Fetch challenge from your server
|
|
2150
2257
|
console.log("Requesting registration challenge from server...");
|
|
2151
|
-
return [4 /*yield*/,
|
|
2152
|
-
headers: {
|
|
2153
|
-
"X-DEVICE-ID": GenerateDeviceId(),
|
|
2154
|
-
"X-API-VERSION": "1.0",
|
|
2155
|
-
},
|
|
2156
|
-
})];
|
|
2258
|
+
return [4 /*yield*/, axiosInstance.post(MFAEndpoints.RegisterNewChallenge, __assign({}, data))];
|
|
2157
2259
|
case 1:
|
|
2158
2260
|
options = (_a.sent()).data;
|
|
2159
2261
|
console.log("Received challenge:", options);
|
|
@@ -2165,13 +2267,7 @@ var DefaultLoginPage = function (_a) {
|
|
|
2165
2267
|
console.log("Passkey created on client:", attestationResponse);
|
|
2166
2268
|
// 3. Send the response back to the server for verification
|
|
2167
2269
|
console.log("Sending attestation to server for verification...");
|
|
2168
|
-
return [4 /*yield*/,
|
|
2169
|
-
headers: {
|
|
2170
|
-
"X-DEVICE-ID": GenerateDeviceId(),
|
|
2171
|
-
"X-API-VERSION": "1.0",
|
|
2172
|
-
},
|
|
2173
|
-
withCredentials: true, // credentials: 'include'
|
|
2174
|
-
})];
|
|
2270
|
+
return [4 /*yield*/, axiosInstance.post(MFAEndpoints.RegisterVerify + "?username=".concat(data.username), attestationResponse)];
|
|
2175
2271
|
case 3:
|
|
2176
2272
|
_a.sent();
|
|
2177
2273
|
sonner.toast.success("✅ Registration successful! Passkey created.");
|
|
@@ -2185,15 +2281,19 @@ var DefaultLoginPage = function (_a) {
|
|
|
2185
2281
|
}
|
|
2186
2282
|
});
|
|
2187
2283
|
}); };
|
|
2188
|
-
return (jsxRuntimeExports.jsxs("main", { className: "min-h-screen bg-gray-50", children: [jsxRuntimeExports.jsx(framerMotion.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(framerMotion.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-
|
|
2284
|
+
return (jsxRuntimeExports.jsxs("main", { className: "min-h-screen bg-gray-50", children: [jsxRuntimeExports.jsx(framerMotion.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(framerMotion.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
|
|
2189
2285
|
// variant="outline"
|
|
2190
2286
|
, {
|
|
2191
2287
|
// variant="outline"
|
|
2192
|
-
className: "w-full flex items-center justify-center cursor-pointer bg-[#506f4a] hover:bg-[#506f4a] rounded-lg border border-transparent px-5 py-8 text-base font-medium transition-colors duration-250", onClick: handleMSALLogin, disabled: isLoading, children: [jsxRuntimeExports.jsx("img", { src: MicrosoftLogo, alt: "Microsoft Logo", width: 35, height: 35 }), jsxRuntimeExports.jsx("span", { className: "ml-2", children: isLoading ? "Logging in..." : "Sign in with Microsoft" })] }),
|
|
2288
|
+
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
|
|
2289
|
+
? "Logging in..."
|
|
2290
|
+
: "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$1(void 0, [_a], void 0, function (_b) {
|
|
2193
2291
|
var username = _b.username, password = _b.password, MFACode = _b.MFACode;
|
|
2194
|
-
return __generator(this, function (_c) {
|
|
2292
|
+
return __generator$1(this, function (_c) {
|
|
2195
2293
|
// Implement your AD login logic here
|
|
2196
2294
|
console.log("AD Login:", { username: username, password: password, MFACode: MFACode });
|
|
2295
|
+
// Example: await adLoginService(username, password, mfaCode);
|
|
2296
|
+
handleSubmitCredentials(CredentialsAuthEndpoint !== null && CredentialsAuthEndpoint !== void 0 ? CredentialsAuthEndpoint : "/api/auth/validate", { username: username, password: password, MFACode: MFACode }, context.appCode);
|
|
2197
2297
|
return [2 /*return*/];
|
|
2198
2298
|
});
|
|
2199
2299
|
}); } })] }));
|
|
@@ -2216,7 +2316,7 @@ var MFAGate = function (_a) {
|
|
|
2216
2316
|
// loginComponent: LoginComponent = DefaultLoginPage,
|
|
2217
2317
|
_c = _a.usePassKey,
|
|
2218
2318
|
// loginComponent: LoginComponent = DefaultLoginPage,
|
|
2219
|
-
usePassKey = _c === void 0 ? false : _c, PassKeysRegisterProps = _a.PassKeysRegisterProps, MFAEndpoints = _a.MFAEndpoints;
|
|
2319
|
+
usePassKey = _c === void 0 ? false : _c, _d = _a.useADLogin, useADLogin = _d === void 0 ? false : _d, CredentialsAuthEndpoint = _a.CredentialsAuthEndpoint, PassKeysRegisterProps = _a.PassKeysRegisterProps, MFAEndpoints = _a.MFAEndpoints;
|
|
2220
2320
|
var context = useCAMSContext();
|
|
2221
2321
|
var validatedMFAEndpoints = React.useMemo(function () {
|
|
2222
2322
|
var parsed = MFAEndpointsSchema.safeParse(MFAEndpoints);
|
|
@@ -2230,8 +2330,8 @@ var MFAGate = function (_a) {
|
|
|
2230
2330
|
if (!success)
|
|
2231
2331
|
camsSdk.Logger.error("MFA authentication failed");
|
|
2232
2332
|
}, []);
|
|
2233
|
-
var handleAuthFailed = React.useCallback(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
2234
|
-
return __generator(this, function (_a) {
|
|
2333
|
+
var handleAuthFailed = React.useCallback(function () { return __awaiter$1(void 0, void 0, void 0, function () {
|
|
2334
|
+
return __generator$1(this, function (_a) {
|
|
2235
2335
|
switch (_a.label) {
|
|
2236
2336
|
case 0: return [4 /*yield*/, context.logout()];
|
|
2237
2337
|
case 1:
|
|
@@ -2240,9 +2340,10 @@ var MFAGate = function (_a) {
|
|
|
2240
2340
|
}
|
|
2241
2341
|
});
|
|
2242
2342
|
}); }, [context.logout]);
|
|
2243
|
-
|
|
2343
|
+
if (useADLogin && !CredentialsAuthEndpoint)
|
|
2344
|
+
return jsxRuntimeExports.jsx(ErrorFallback, { message: "Invalid AD Login Configuration." });
|
|
2244
2345
|
if (!validatedMFAEndpoints)
|
|
2245
|
-
return jsxRuntimeExports.jsx(ErrorFallback, { message: "Invalid MFA
|
|
2346
|
+
return jsxRuntimeExports.jsx(ErrorFallback, { message: "Invalid MFA Configuration." });
|
|
2246
2347
|
if (context.authMode !== "MSAL")
|
|
2247
2348
|
return jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: children });
|
|
2248
2349
|
if (context.isLoading)
|
|
@@ -2251,7 +2352,7 @@ var MFAGate = function (_a) {
|
|
|
2251
2352
|
return (jsxRuntimeExports.jsx(MFAOptions, { MFAEndpoints: validatedMFAEndpoints, usePassKey: usePassKey, onComplete: handleComplete, onAuthFailed: handleAuthFailed }));
|
|
2252
2353
|
}
|
|
2253
2354
|
if (!context.isAuthenticated) {
|
|
2254
|
-
return (jsxRuntimeExports.jsx(DefaultLoginPage, { usePassKey: usePassKey, MFAEndpoints: MFAEndpoints, PassKeysRegisterProps: PassKeysRegisterProps }));
|
|
2355
|
+
return (jsxRuntimeExports.jsx(DefaultLoginPage, { usePassKey: usePassKey, useADLogin: useADLogin, MFAEndpoints: MFAEndpoints, PassKeysRegisterProps: PassKeysRegisterProps, CredentialsAuthEndpoint: CredentialsAuthEndpoint }));
|
|
2255
2356
|
}
|
|
2256
2357
|
return jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: children });
|
|
2257
2358
|
};
|