@nibssplc/cams-sdk-react 1.0.0-rc.5 → 1.0.0-rc.51
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/README.md +18 -4
- package/dist/components/MFAGate.d.ts +7 -1
- package/dist/components/UnifiedCAMSProvider.d.ts +5 -0
- package/dist/context/CAMSContext.d.ts +5 -0
- package/dist/hooks/useCAMSMSALAuth.d.ts +3 -2
- package/dist/index.cjs.js +326 -176
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.esm.js +326 -176
- package/dist/index.esm.js.map +1 -1
- package/dist/lib/actions/Axiosinstance.d.ts +1 -0
- package/dist/styles.css +3 -0
- package/package.json +7 -3
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);
|
|
@@ -80,7 +81,7 @@ function __rest(s, e) {
|
|
|
80
81
|
return t;
|
|
81
82
|
}
|
|
82
83
|
|
|
83
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
84
|
+
function __awaiter$1(thisArg, _arguments, P, generator) {
|
|
84
85
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
85
86
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
86
87
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
@@ -90,7 +91,7 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
90
91
|
});
|
|
91
92
|
}
|
|
92
93
|
|
|
93
|
-
function __generator(thisArg, body) {
|
|
94
|
+
function __generator$1(thisArg, body) {
|
|
94
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);
|
|
95
96
|
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
96
97
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
@@ -187,10 +188,10 @@ function useCAMSAuth(options) {
|
|
|
187
188
|
}
|
|
188
189
|
}
|
|
189
190
|
}, [options.storageKey]);
|
|
190
|
-
var login = React.useCallback(function (config) { return __awaiter(_this, void 0, void 0, function () {
|
|
191
|
+
var login = React.useCallback(function (config) { return __awaiter$1(_this, void 0, void 0, function () {
|
|
191
192
|
var loginConfig, userProfile, err_1, e, isPopupClosedError, restoredToken, userProfile;
|
|
192
193
|
var _a, _b, _c;
|
|
193
|
-
return __generator(this, function (_d) {
|
|
194
|
+
return __generator$1(this, function (_d) {
|
|
194
195
|
switch (_d.label) {
|
|
195
196
|
case 0:
|
|
196
197
|
if (!sessionManagerRef.current)
|
|
@@ -238,8 +239,8 @@ function useCAMSAuth(options) {
|
|
|
238
239
|
}
|
|
239
240
|
});
|
|
240
241
|
}); }, [options.idleTimeout]);
|
|
241
|
-
var logout = React.useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
242
|
-
return __generator(this, function (_a) {
|
|
242
|
+
var logout = React.useCallback(function () { return __awaiter$1(_this, void 0, void 0, function () {
|
|
243
|
+
return __generator$1(this, function (_a) {
|
|
243
244
|
switch (_a.label) {
|
|
244
245
|
case 0:
|
|
245
246
|
if (!sessionManagerRef.current)
|
|
@@ -269,11 +270,154 @@ function useCAMSAuth(options) {
|
|
|
269
270
|
};
|
|
270
271
|
}
|
|
271
272
|
|
|
272
|
-
var
|
|
273
|
+
var _a;
|
|
274
|
+
// Crypto polyfill for MSAL browser compatibility
|
|
275
|
+
// Only apply if crypto.subtle is completely missing
|
|
276
|
+
if (typeof window !== "undefined" && !((_a = window.crypto) === null || _a === void 0 ? void 0 : _a.subtle)) {
|
|
277
|
+
// Ensure crypto object exists
|
|
278
|
+
if (!window.crypto) {
|
|
279
|
+
window.crypto = {};
|
|
280
|
+
}
|
|
281
|
+
// Polyfill getRandomValues
|
|
282
|
+
if (!window.crypto.getRandomValues) {
|
|
283
|
+
window.crypto.getRandomValues = function (array) {
|
|
284
|
+
var bytes = new Uint8Array(array.buffer, array.byteOffset, array.byteLength);
|
|
285
|
+
for (var i = 0; i < bytes.length; i++) {
|
|
286
|
+
bytes[i] = Math.floor(Math.random() * 256);
|
|
287
|
+
}
|
|
288
|
+
return array;
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
var sha256_1 = function (data) { return __awaiter(void 0, void 0, void 0, function () {
|
|
292
|
+
var toUint8, bytes, hash, k, ml, msg, dv, high, low, i, w, j, j, s0, s1, a, b, c, d, e, f, g, h, j, S1, ch, temp1, S0, maj, temp2, result, i;
|
|
293
|
+
return __generator(this, function (_a) {
|
|
294
|
+
toUint8 = function (src) {
|
|
295
|
+
if (src instanceof ArrayBuffer)
|
|
296
|
+
return new Uint8Array(src);
|
|
297
|
+
if (ArrayBuffer.isView(src)) {
|
|
298
|
+
var view = src;
|
|
299
|
+
return new Uint8Array(view.buffer, view.byteOffset || 0, view.byteLength);
|
|
300
|
+
}
|
|
301
|
+
throw new TypeError("Unsupported BufferSource");
|
|
302
|
+
};
|
|
303
|
+
bytes = toUint8(data);
|
|
304
|
+
hash = new Uint32Array(8);
|
|
305
|
+
k = new Uint32Array([
|
|
306
|
+
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1,
|
|
307
|
+
0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
|
|
308
|
+
0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786,
|
|
309
|
+
0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
|
|
310
|
+
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147,
|
|
311
|
+
0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
|
|
312
|
+
0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 0xa2bfe8a1, 0xa81a664b,
|
|
313
|
+
0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
|
|
314
|
+
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a,
|
|
315
|
+
0x5b9cca4f, 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
|
|
316
|
+
0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,
|
|
317
|
+
]);
|
|
318
|
+
hash[0] = 0x6a09e667;
|
|
319
|
+
hash[1] = 0xbb67ae85;
|
|
320
|
+
hash[2] = 0x3c6ef372;
|
|
321
|
+
hash[3] = 0xa54ff53a;
|
|
322
|
+
hash[4] = 0x510e527f;
|
|
323
|
+
hash[5] = 0x9b05688c;
|
|
324
|
+
hash[6] = 0x1f83d9ab;
|
|
325
|
+
hash[7] = 0x5be0cd19;
|
|
326
|
+
ml = bytes.length * 8;
|
|
327
|
+
msg = new Uint8Array(bytes.length + 64 + ((64 - ((bytes.length + 9) % 64)) % 64));
|
|
328
|
+
msg.set(bytes);
|
|
329
|
+
msg[bytes.length] = 0x80;
|
|
330
|
+
dv = new DataView(msg.buffer);
|
|
331
|
+
high = Math.floor(ml / 0x100000000);
|
|
332
|
+
low = ml >>> 0;
|
|
333
|
+
dv.setUint32(msg.length - 8, high, false);
|
|
334
|
+
dv.setUint32(msg.length - 4, low, false);
|
|
335
|
+
for (i = 0; i < msg.length; i += 64) {
|
|
336
|
+
w = new Uint32Array(64);
|
|
337
|
+
for (j = 0; j < 16; j++)
|
|
338
|
+
w[j] = new DataView(msg.buffer).getUint32(i + j * 4, false);
|
|
339
|
+
for (j = 16; j < 64; j++) {
|
|
340
|
+
s0 = ((w[j - 15] >>> 7) | (w[j - 15] << 25)) ^
|
|
341
|
+
((w[j - 15] >>> 18) | (w[j - 15] << 14)) ^
|
|
342
|
+
(w[j - 15] >>> 3);
|
|
343
|
+
s1 = ((w[j - 2] >>> 17) | (w[j - 2] << 15)) ^
|
|
344
|
+
((w[j - 2] >>> 19) | (w[j - 2] << 13)) ^
|
|
345
|
+
(w[j - 2] >>> 10);
|
|
346
|
+
w[j] = (w[j - 16] + s0 + w[j - 7] + s1) >>> 0;
|
|
347
|
+
}
|
|
348
|
+
a = hash[0], b = hash[1], c = hash[2], d = hash[3], e = hash[4], f = hash[5], g = hash[6], h = hash[7];
|
|
349
|
+
for (j = 0; j < 64; j++) {
|
|
350
|
+
S1 = ((e >>> 6) | (e << 26)) ^
|
|
351
|
+
((e >>> 11) | (e << 21)) ^
|
|
352
|
+
((e >>> 25) | (e << 7));
|
|
353
|
+
ch = (e & f) ^ (~e & g);
|
|
354
|
+
temp1 = (h + S1 + ch + k[j] + w[j]) >>> 0;
|
|
355
|
+
S0 = ((a >>> 2) | (a << 30)) ^
|
|
356
|
+
((a >>> 13) | (a << 19)) ^
|
|
357
|
+
((a >>> 22) | (a << 10));
|
|
358
|
+
maj = (a & b) ^ (a & c) ^ (b & c);
|
|
359
|
+
temp2 = (S0 + maj) >>> 0;
|
|
360
|
+
h = g;
|
|
361
|
+
g = f;
|
|
362
|
+
f = e;
|
|
363
|
+
e = (d + temp1) >>> 0;
|
|
364
|
+
d = c;
|
|
365
|
+
c = b;
|
|
366
|
+
b = a;
|
|
367
|
+
a = (temp1 + temp2) >>> 0;
|
|
368
|
+
}
|
|
369
|
+
hash[0] = (hash[0] + a) >>> 0;
|
|
370
|
+
hash[1] = (hash[1] + b) >>> 0;
|
|
371
|
+
hash[2] = (hash[2] + c) >>> 0;
|
|
372
|
+
hash[3] = (hash[3] + d) >>> 0;
|
|
373
|
+
hash[4] = (hash[4] + e) >>> 0;
|
|
374
|
+
hash[5] = (hash[5] + f) >>> 0;
|
|
375
|
+
hash[6] = (hash[6] + g) >>> 0;
|
|
376
|
+
hash[7] = (hash[7] + h) >>> 0;
|
|
377
|
+
}
|
|
378
|
+
result = new Uint8Array(32);
|
|
379
|
+
for (i = 0; i < 8; i++)
|
|
380
|
+
new DataView(result.buffer).setUint32(i * 4, hash[i], false);
|
|
381
|
+
return [2 /*return*/, result.buffer];
|
|
382
|
+
});
|
|
383
|
+
}); };
|
|
384
|
+
// Create the polyfilled subtle object
|
|
385
|
+
var polyfillSubtle = {
|
|
386
|
+
digest: function (algorithm, data) { return __awaiter(void 0, void 0, void 0, function () {
|
|
387
|
+
var alg;
|
|
388
|
+
return __generator(this, function (_a) {
|
|
389
|
+
alg = typeof algorithm === "string"
|
|
390
|
+
? algorithm
|
|
391
|
+
: algorithm.name;
|
|
392
|
+
if (alg === "SHA-256")
|
|
393
|
+
return [2 /*return*/, sha256_1(data)];
|
|
394
|
+
throw new Error("Unsupported algorithm: ".concat(alg));
|
|
395
|
+
});
|
|
396
|
+
}); },
|
|
397
|
+
};
|
|
398
|
+
// Set the polyfilled subtle object
|
|
399
|
+
window.crypto.subtle = polyfillSubtle;
|
|
400
|
+
// Polyfill randomUUID
|
|
401
|
+
if (!window.crypto.randomUUID) {
|
|
402
|
+
window.crypto.randomUUID =
|
|
403
|
+
function () {
|
|
404
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
|
|
405
|
+
var r = (Math.random() * 16) | 0;
|
|
406
|
+
var v = c === "x" ? r : (r & 0x3) | 0x8;
|
|
407
|
+
return v.toString(16);
|
|
408
|
+
});
|
|
409
|
+
};
|
|
410
|
+
}
|
|
411
|
+
console.log("Crypto polyfill applied (native crypto.subtle not available)");
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
var setCookie = function (name, value, days) {
|
|
415
|
+
if (days === void 0) { days = 1; }
|
|
273
416
|
var expires = new Date(Date.now() + days * 24 * 60 * 60 * 1000).toUTCString();
|
|
417
|
+
console.log("Auth Cookie Expires >>>", { name: name, value: value, expires: expires });
|
|
274
418
|
document.cookie = "".concat(name, "=").concat(encodeURIComponent(value), "; expires=").concat(expires, "; path=/; samesite=Lax");
|
|
275
419
|
};
|
|
276
|
-
var getCookie
|
|
420
|
+
var getCookie = function (name) {
|
|
277
421
|
var _a;
|
|
278
422
|
return ((_a = document.cookie
|
|
279
423
|
.split("; ")
|
|
@@ -284,23 +428,24 @@ var getCookie$1 = function (name) {
|
|
|
284
428
|
.split("=")[1])
|
|
285
429
|
: null;
|
|
286
430
|
};
|
|
287
|
-
var deleteCookie
|
|
431
|
+
var deleteCookie = function (name) {
|
|
288
432
|
document.cookie = name + "=; Max-Age=-99999999; path=/";
|
|
289
433
|
};
|
|
290
434
|
|
|
291
435
|
function useCAMSMSALAuth(options) {
|
|
292
436
|
var _this = this;
|
|
293
|
-
var
|
|
294
|
-
var
|
|
437
|
+
var optStorageKey = options.storageKey, optScopes = options.scopes, prompt = options.prompt, appCode = options.appCode, MFAEndpoint = options.MFAEndpoint, _a = options.activeCookiePeriod, activeCookiePeriod = _a === void 0 ? 1 : _a;
|
|
438
|
+
var storageKey = optStorageKey || "CAMS-MSAL-AUTH-SDK";
|
|
439
|
+
var _b = msalReact.useMsal(), instance = _b.instance, inProgress = _b.inProgress, accounts = _b.accounts;
|
|
295
440
|
var account = msalReact.useAccount(accounts[0] || {});
|
|
296
|
-
var
|
|
297
|
-
var
|
|
298
|
-
var
|
|
299
|
-
var
|
|
300
|
-
var
|
|
441
|
+
var _c = React.useState(null), error = _c[0], setError = _c[1];
|
|
442
|
+
var _d = React.useState(""), idToken = _d[0], setIdToken = _d[1];
|
|
443
|
+
var _e = React.useState(""), accessToken = _e[0], setAccessToken = _e[1];
|
|
444
|
+
var _f = React.useState(null), mfaAuthenticator = _f[0], setMfaAuthenticator = _f[1];
|
|
445
|
+
var _g = React.useState(false), requiresMFA = _g[0], setRequiresMFA = _g[1];
|
|
301
446
|
var isLoading = inProgress !== msalBrowser.InteractionStatus.None;
|
|
302
447
|
var isAuthenticated = !!account && !!accessToken && !requiresMFA;
|
|
303
|
-
var scopes =
|
|
448
|
+
var scopes = optScopes || ["openid", "profile", "email"];
|
|
304
449
|
var isTokenValid = function (token) {
|
|
305
450
|
try {
|
|
306
451
|
var payload = JSON.parse(atob(token.split(".")[1]));
|
|
@@ -324,15 +469,14 @@ function useCAMSMSALAuth(options) {
|
|
|
324
469
|
var mfaConfig = {
|
|
325
470
|
accessToken: accessToken_1,
|
|
326
471
|
idToken: idToken_1,
|
|
327
|
-
appCode:
|
|
472
|
+
appCode: appCode,
|
|
328
473
|
provider: "MSAL",
|
|
329
|
-
apiEndpoint:
|
|
474
|
+
apiEndpoint: MFAEndpoint,
|
|
330
475
|
};
|
|
331
476
|
var authenticator = new camsSdk.CAMSMFAAuthenticator(mfaConfig);
|
|
332
477
|
setMfaAuthenticator(authenticator);
|
|
333
478
|
setRequiresMFA(true);
|
|
334
479
|
}
|
|
335
|
-
camsSdk.Logger.debug("App Code", { ">>>": options.appCode });
|
|
336
480
|
}
|
|
337
481
|
else {
|
|
338
482
|
localStorage.removeItem(storageKey);
|
|
@@ -374,22 +518,26 @@ function useCAMSMSALAuth(options) {
|
|
|
374
518
|
// };
|
|
375
519
|
// handleRedirect();
|
|
376
520
|
// }, []);
|
|
377
|
-
var login = React.useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
521
|
+
var login = React.useCallback(function () { return __awaiter$1(_this, void 0, void 0, function () {
|
|
378
522
|
var response, mfaConfig, authenticator, err_1, camsError_1, camsError;
|
|
379
|
-
var _a
|
|
380
|
-
return __generator(this, function (
|
|
381
|
-
switch (
|
|
523
|
+
var _a;
|
|
524
|
+
return __generator$1(this, function (_b) {
|
|
525
|
+
switch (_b.label) {
|
|
382
526
|
case 0:
|
|
527
|
+
if (inProgress !== msalBrowser.InteractionStatus.None) {
|
|
528
|
+
camsSdk.Logger.warn("Authentication already in progress, ignoring duplicate call");
|
|
529
|
+
return [2 /*return*/];
|
|
530
|
+
}
|
|
383
531
|
setError(null);
|
|
384
|
-
|
|
532
|
+
_b.label = 1;
|
|
385
533
|
case 1:
|
|
386
|
-
|
|
534
|
+
_b.trys.push([1, 3, , 4]);
|
|
387
535
|
return [4 /*yield*/, instance.loginPopup({
|
|
388
536
|
scopes: scopes,
|
|
389
|
-
prompt:
|
|
537
|
+
prompt: prompt || "login",
|
|
390
538
|
})];
|
|
391
539
|
case 2:
|
|
392
|
-
response =
|
|
540
|
+
response = _b.sent();
|
|
393
541
|
console.log("Login Token response:", {
|
|
394
542
|
accessToken: response.accessToken,
|
|
395
543
|
idToken: response.idToken,
|
|
@@ -399,9 +547,9 @@ function useCAMSMSALAuth(options) {
|
|
|
399
547
|
mfaConfig = {
|
|
400
548
|
accessToken: response.accessToken,
|
|
401
549
|
idToken: response.idToken,
|
|
402
|
-
appCode:
|
|
550
|
+
appCode: appCode,
|
|
403
551
|
provider: "MSAL",
|
|
404
|
-
apiEndpoint:
|
|
552
|
+
apiEndpoint: MFAEndpoint,
|
|
405
553
|
};
|
|
406
554
|
authenticator = new camsSdk.CAMSMFAAuthenticator(mfaConfig);
|
|
407
555
|
setMfaAuthenticator(authenticator);
|
|
@@ -415,10 +563,14 @@ function useCAMSMSALAuth(options) {
|
|
|
415
563
|
idToken: response.idToken,
|
|
416
564
|
}));
|
|
417
565
|
}
|
|
418
|
-
(_a = options.onAuthSuccess) === null || _a === void 0 ? void 0 : _a.call(options, response.accessToken);
|
|
419
566
|
return [3 /*break*/, 4];
|
|
420
567
|
case 3:
|
|
421
|
-
err_1 =
|
|
568
|
+
err_1 = _b.sent();
|
|
569
|
+
// Handle interaction_in_progress error
|
|
570
|
+
if (err_1.errorCode === "interaction_in_progress") {
|
|
571
|
+
camsSdk.Logger.warn("Interaction already in progress, please wait");
|
|
572
|
+
return [2 /*return*/];
|
|
573
|
+
}
|
|
422
574
|
// Handle user cancellation gracefully
|
|
423
575
|
if (err_1.errorCode === "user_cancelled") {
|
|
424
576
|
camsSdk.Logger.error("User cancelled login");
|
|
@@ -427,22 +579,28 @@ function useCAMSMSALAuth(options) {
|
|
|
427
579
|
}
|
|
428
580
|
// If popup is blocked
|
|
429
581
|
if (err_1.errorCode === "popup_window_error" ||
|
|
430
|
-
((
|
|
582
|
+
((_a = err_1.message) === null || _a === void 0 ? void 0 : _a.includes("popup"))) {
|
|
431
583
|
camsError_1 = new camsSdk.CAMSError(camsSdk.CAMSErrorType.POPUP_BLOCKED, "Popup blocked by browser. Please allow popups and try again.");
|
|
432
584
|
setError(camsError_1);
|
|
433
|
-
(_c = options.onAuthError) === null || _c === void 0 ? void 0 : _c.call(options, camsError_1);
|
|
434
585
|
return [2 /*return*/];
|
|
435
586
|
}
|
|
436
587
|
camsError = new camsSdk.CAMSError(camsSdk.CAMSErrorType.API_VALIDATION_ERROR, "Login failed: " + err_1.message || err_1);
|
|
437
588
|
setError(camsError);
|
|
438
|
-
(_d = options.onAuthError) === null || _d === void 0 ? void 0 : _d.call(options, camsError);
|
|
439
589
|
return [3 /*break*/, 4];
|
|
440
590
|
case 4: return [2 /*return*/];
|
|
441
591
|
}
|
|
442
592
|
});
|
|
443
|
-
}); }, [
|
|
444
|
-
|
|
445
|
-
|
|
593
|
+
}); }, [
|
|
594
|
+
instance,
|
|
595
|
+
scopes,
|
|
596
|
+
prompt,
|
|
597
|
+
appCode,
|
|
598
|
+
MFAEndpoint,
|
|
599
|
+
storageKey,
|
|
600
|
+
inProgress,
|
|
601
|
+
]);
|
|
602
|
+
var completeMFA = React.useCallback(function (data) { return __awaiter$1(_this, void 0, void 0, function () {
|
|
603
|
+
return __generator$1(this, function (_a) {
|
|
446
604
|
if (!mfaAuthenticator) {
|
|
447
605
|
throw new camsSdk.CAMSError(camsSdk.CAMSErrorType.API_VALIDATION_ERROR, "MFA Authenticator not initialized");
|
|
448
606
|
}
|
|
@@ -456,7 +614,7 @@ function useCAMSMSALAuth(options) {
|
|
|
456
614
|
accessToken: accessToken,
|
|
457
615
|
idToken: idToken,
|
|
458
616
|
}));
|
|
459
|
-
setCookie
|
|
617
|
+
setCookie("CAMS-MSAL-AUTH-SDK-PROFILE", JSON.stringify({ type: "AUTH_SUCCESS", userProfile: __assign({}, data) }), activeCookiePeriod);
|
|
460
618
|
setRequiresMFA(false);
|
|
461
619
|
// Set requiresMFA to false after storage update
|
|
462
620
|
camsSdk.Logger.debug("MFA completed successfully, storage updated", {
|
|
@@ -475,9 +633,9 @@ function useCAMSMSALAuth(options) {
|
|
|
475
633
|
}
|
|
476
634
|
return [2 /*return*/];
|
|
477
635
|
});
|
|
478
|
-
}); }, [mfaAuthenticator, accessToken, idToken, storageKey]);
|
|
479
|
-
var sendEmailOTP = React.useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
480
|
-
return __generator(this, function (_a) {
|
|
636
|
+
}); }, [mfaAuthenticator, accessToken, idToken, storageKey, activeCookiePeriod]);
|
|
637
|
+
var sendEmailOTP = React.useCallback(function () { return __awaiter$1(_this, void 0, void 0, function () {
|
|
638
|
+
return __generator$1(this, function (_a) {
|
|
481
639
|
switch (_a.label) {
|
|
482
640
|
case 0:
|
|
483
641
|
if (!mfaAuthenticator) {
|
|
@@ -488,9 +646,9 @@ function useCAMSMSALAuth(options) {
|
|
|
488
646
|
}
|
|
489
647
|
});
|
|
490
648
|
}); }, [mfaAuthenticator]);
|
|
491
|
-
var logout = React.useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
649
|
+
var logout = React.useCallback(function () { return __awaiter$1(_this, void 0, void 0, function () {
|
|
492
650
|
var err_2, camsError;
|
|
493
|
-
return __generator(this, function (_a) {
|
|
651
|
+
return __generator$1(this, function (_a) {
|
|
494
652
|
switch (_a.label) {
|
|
495
653
|
case 0:
|
|
496
654
|
_a.trys.push([0, 2, , 3]);
|
|
@@ -526,12 +684,13 @@ function useCAMSMSALAuth(options) {
|
|
|
526
684
|
error: error,
|
|
527
685
|
idToken: idToken,
|
|
528
686
|
accessToken: accessToken,
|
|
529
|
-
appCode:
|
|
687
|
+
appCode: appCode,
|
|
530
688
|
mfaAuthenticator: mfaAuthenticator,
|
|
531
689
|
requiresMFA: requiresMFA,
|
|
532
690
|
completeMFA: completeMFA,
|
|
533
691
|
sendEmailOTP: sendEmailOTP,
|
|
534
692
|
setRequiresMFA: setRequiresMFA,
|
|
693
|
+
activeCookiePeriod: activeCookiePeriod,
|
|
535
694
|
};
|
|
536
695
|
}
|
|
537
696
|
|
|
@@ -574,10 +733,10 @@ function arrayBufferToBase64url(buffer) {
|
|
|
574
733
|
* @returns A promise that resolves to a JSON-serializable representation of the PublicKeyCredential.
|
|
575
734
|
*/
|
|
576
735
|
function register(options) {
|
|
577
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
736
|
+
return __awaiter$1(this, void 0, void 0, function () {
|
|
578
737
|
var createOptions, credential, publicKeyCredential, attestationResponse, transports, err_1;
|
|
579
738
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
580
|
-
return __generator(this, function (_k) {
|
|
739
|
+
return __generator$1(this, function (_k) {
|
|
581
740
|
switch (_k.label) {
|
|
582
741
|
case 0:
|
|
583
742
|
_k.trys.push([0, 2, , 3]);
|
|
@@ -635,10 +794,10 @@ function register(options) {
|
|
|
635
794
|
* @returns A promise that resolves to a JSON-serializable representation of the PublicKeyCredential.
|
|
636
795
|
*/
|
|
637
796
|
function authenticate(options) {
|
|
638
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
797
|
+
return __awaiter$1(this, void 0, void 0, function () {
|
|
639
798
|
var getOptions, credential, publicKeyCredential, assertionResponse;
|
|
640
799
|
var _a;
|
|
641
|
-
return __generator(this, function (_b) {
|
|
800
|
+
return __generator$1(this, function (_b) {
|
|
642
801
|
switch (_b.label) {
|
|
643
802
|
case 0:
|
|
644
803
|
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) })); }) });
|
|
@@ -1111,7 +1270,7 @@ function ProtectedRoute(_a) {
|
|
|
1111
1270
|
var children = _a.children, fallback = _a.fallback, redirectTo = _a.redirectTo;
|
|
1112
1271
|
var _b = useCAMSContext$1(), isAuthenticated = _b.isAuthenticated, isLoading = _b.isLoading;
|
|
1113
1272
|
if (isLoading) {
|
|
1114
|
-
return fallback || jsxRuntimeExports.jsx("div", { children: "Loading..." });
|
|
1273
|
+
return fallback || jsxRuntimeExports.jsx("div", { className: 'h-screen flex items-center justify-center', children: "Loading..." });
|
|
1115
1274
|
}
|
|
1116
1275
|
if (!isAuthenticated) {
|
|
1117
1276
|
if (redirectTo && typeof window !== 'undefined') {
|
|
@@ -1124,24 +1283,6 @@ function ProtectedRoute(_a) {
|
|
|
1124
1283
|
}
|
|
1125
1284
|
|
|
1126
1285
|
var CAMSMSALContext = React.createContext(null);
|
|
1127
|
-
var setCookie = function (name, value, days) {
|
|
1128
|
-
var expires = new Date(Date.now() + days * 864e5).toUTCString();
|
|
1129
|
-
document.cookie = "".concat(name, "=").concat(encodeURIComponent(value), "; expires=").concat(expires, "; path=/; samesite=Lax");
|
|
1130
|
-
};
|
|
1131
|
-
var getCookie = function (name) {
|
|
1132
|
-
var _a;
|
|
1133
|
-
return ((_a = document.cookie
|
|
1134
|
-
.split("; ")
|
|
1135
|
-
.find(function (row) { return row.startsWith(name + "="); })) === null || _a === void 0 ? void 0 : _a.split("=")[1])
|
|
1136
|
-
? decodeURIComponent(document.cookie
|
|
1137
|
-
.split("; ")
|
|
1138
|
-
.find(function (row) { return row.startsWith(name + "="); })
|
|
1139
|
-
.split("=")[1])
|
|
1140
|
-
: null;
|
|
1141
|
-
};
|
|
1142
|
-
var deleteCookie = function (name) {
|
|
1143
|
-
document.cookie = name + "=; Max-Age=-99999999; path=/";
|
|
1144
|
-
};
|
|
1145
1286
|
var isTokenValid = function (token) {
|
|
1146
1287
|
try {
|
|
1147
1288
|
var payload = JSON.parse(atob(token.split(".")[1]));
|
|
@@ -1190,7 +1331,7 @@ function CAMSMSALProviderInner(_a) {
|
|
|
1190
1331
|
localStorage.setItem(auth.storageKey, JSON.stringify({
|
|
1191
1332
|
accessToken: auth.accessToken,
|
|
1192
1333
|
idToken: auth.idToken,
|
|
1193
|
-
appCode: auth.appCode
|
|
1334
|
+
appCode: auth.appCode,
|
|
1194
1335
|
}));
|
|
1195
1336
|
}
|
|
1196
1337
|
}, [auth.accessToken, auth.idToken, auth.storageKey]);
|
|
@@ -1206,8 +1347,8 @@ function CAMSMSALProviderInner(_a) {
|
|
|
1206
1347
|
}
|
|
1207
1348
|
}, [userProfile, profileStorageKey]);
|
|
1208
1349
|
// Enhanced logout that also clears profile
|
|
1209
|
-
var enhancedLogout = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
1210
|
-
return __generator(this, function (_a) {
|
|
1350
|
+
var enhancedLogout = function () { return __awaiter$1(_this, void 0, void 0, function () {
|
|
1351
|
+
return __generator$1(this, function (_a) {
|
|
1211
1352
|
switch (_a.label) {
|
|
1212
1353
|
case 0: return [4 /*yield*/, auth.logout()];
|
|
1213
1354
|
case 1:
|
|
@@ -1224,7 +1365,12 @@ function CAMSMSALProviderInner(_a) {
|
|
|
1224
1365
|
return (jsxRuntimeExports.jsx(CAMSMSALContext.Provider, { value: value, children: children }));
|
|
1225
1366
|
}
|
|
1226
1367
|
function CAMSMSALProvider(props) {
|
|
1368
|
+
var _a;
|
|
1227
1369
|
var msalConfig = props.msalConfig, msalInstance = props.msalInstance;
|
|
1370
|
+
// Ensure crypto is available before creating MSAL instance
|
|
1371
|
+
if (typeof window !== "undefined" && !((_a = window.crypto) === null || _a === void 0 ? void 0 : _a.subtle)) {
|
|
1372
|
+
throw new Error("Crypto API not available. Polyfill failed to load.");
|
|
1373
|
+
}
|
|
1228
1374
|
var instance = msalInstance || new msalBrowser.PublicClientApplication(msalConfig);
|
|
1229
1375
|
return (jsxRuntimeExports.jsx(msalReact.MsalProvider, { instance: instance, children: jsxRuntimeExports.jsx(CAMSMSALProviderInner, __assign({}, props)) }));
|
|
1230
1376
|
}
|
|
@@ -1274,7 +1420,7 @@ function CAMSProviderCore(props) {
|
|
|
1274
1420
|
if (typeof window === "undefined")
|
|
1275
1421
|
return null;
|
|
1276
1422
|
try {
|
|
1277
|
-
var storedProfile = getCookie
|
|
1423
|
+
var storedProfile = getCookie(profileStorageKey);
|
|
1278
1424
|
return storedProfile ? JSON.parse(storedProfile) : null;
|
|
1279
1425
|
}
|
|
1280
1426
|
catch (_a) {
|
|
@@ -1284,7 +1430,7 @@ function CAMSProviderCore(props) {
|
|
|
1284
1430
|
var _a = React.useState(getInitialProfile), userProfile = _a[0], setUserProfile = _a[1];
|
|
1285
1431
|
React.useEffect(function () {
|
|
1286
1432
|
if (typeof window !== "undefined") {
|
|
1287
|
-
var storedProfile = getCookie
|
|
1433
|
+
var storedProfile = getCookie(profileStorageKey);
|
|
1288
1434
|
if (storedProfile) {
|
|
1289
1435
|
try {
|
|
1290
1436
|
setUserProfile(JSON.parse(storedProfile));
|
|
@@ -1296,47 +1442,41 @@ function CAMSProviderCore(props) {
|
|
|
1296
1442
|
React.useEffect(function () {
|
|
1297
1443
|
if (typeof window !== "undefined") {
|
|
1298
1444
|
if (userProfile) {
|
|
1299
|
-
setCookie
|
|
1445
|
+
setCookie(profileStorageKey, JSON.stringify(userProfile), 1);
|
|
1300
1446
|
}
|
|
1301
1447
|
else {
|
|
1302
|
-
deleteCookie
|
|
1448
|
+
deleteCookie(profileStorageKey);
|
|
1303
1449
|
}
|
|
1304
1450
|
}
|
|
1305
1451
|
}, [userProfile, profileStorageKey]);
|
|
1306
|
-
var enhancedLogout = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
1307
|
-
return __generator(this, function (_a) {
|
|
1452
|
+
var enhancedLogout = function () { return __awaiter$1(_this, void 0, void 0, function () {
|
|
1453
|
+
return __generator$1(this, function (_a) {
|
|
1308
1454
|
switch (_a.label) {
|
|
1309
1455
|
case 0: return [4 /*yield*/, auth.logout()];
|
|
1310
1456
|
case 1:
|
|
1311
1457
|
_a.sent();
|
|
1312
1458
|
setUserProfile(null);
|
|
1313
1459
|
if (typeof window !== "undefined") {
|
|
1314
|
-
deleteCookie
|
|
1460
|
+
deleteCookie(profileStorageKey);
|
|
1315
1461
|
}
|
|
1316
1462
|
return [2 /*return*/];
|
|
1317
1463
|
}
|
|
1318
1464
|
});
|
|
1319
1465
|
}); };
|
|
1320
|
-
// Handle MFA completion for MSAL mode
|
|
1321
1466
|
React.useEffect(function () {
|
|
1322
1467
|
if (mode === "MSAL" &&
|
|
1323
1468
|
"requiresMFA" in auth &&
|
|
1324
1469
|
!auth.requiresMFA &&
|
|
1325
1470
|
auth.isAuthenticated) {
|
|
1326
|
-
// MFA completed, extract profile from localStorage
|
|
1327
1471
|
var storedData = localStorage.getItem(auth.storageKey);
|
|
1328
1472
|
if (storedData) {
|
|
1329
1473
|
try {
|
|
1330
1474
|
var parsed = JSON.parse(storedData);
|
|
1331
|
-
console.log("Parsed storage data:", parsed);
|
|
1332
1475
|
if (parsed.userProfile) {
|
|
1333
|
-
console.log("Setting user profile:", parsed.userProfile);
|
|
1334
1476
|
setUserProfile(parsed.userProfile);
|
|
1335
1477
|
}
|
|
1336
1478
|
}
|
|
1337
|
-
catch (
|
|
1338
|
-
console.error("Error parsing stored data:", e);
|
|
1339
|
-
}
|
|
1479
|
+
catch (_a) { }
|
|
1340
1480
|
}
|
|
1341
1481
|
}
|
|
1342
1482
|
}, [
|
|
@@ -1347,22 +1487,27 @@ function CAMSProviderCore(props) {
|
|
|
1347
1487
|
userProfile,
|
|
1348
1488
|
]);
|
|
1349
1489
|
var value = React.useMemo(function () {
|
|
1350
|
-
|
|
1351
|
-
|
|
1490
|
+
auth.logout; var authRest = __rest(auth, ["logout"]);
|
|
1491
|
+
return __assign(__assign({}, authRest), { logout: enhancedLogout, userProfile: userProfile, setUserProfile: setUserProfile, authMode: mode, onAuthSuccess: mode === "MSAL" ? props.onAuthSuccess : undefined, onAuthError: mode === "MSAL" ? props.onAuthError : undefined });
|
|
1492
|
+
}, [auth, userProfile, mode, props]);
|
|
1352
1493
|
return jsxRuntimeExports.jsx(CAMSContext.Provider, { value: value, children: children });
|
|
1353
1494
|
}
|
|
1354
1495
|
function UnifiedCAMSProvider(props) {
|
|
1496
|
+
var _a;
|
|
1355
1497
|
// Validate appCode is a valid GUID
|
|
1356
1498
|
var appCodeValidation = GuidSchema.safeParse(props.appCode);
|
|
1357
1499
|
if (!appCodeValidation.success) {
|
|
1358
|
-
throw new Error("Invalid
|
|
1500
|
+
throw new Error("Invalid CAS APP CODE: ".concat(appCodeValidation.error.issues[0].message));
|
|
1359
1501
|
}
|
|
1360
1502
|
if (props.mode === "MSAL") {
|
|
1361
1503
|
var msalConfig = props.msalConfig, msalInstance = props.msalInstance;
|
|
1504
|
+
if (typeof window !== "undefined" && !((_a = window.crypto) === null || _a === void 0 ? void 0 : _a.subtle)) {
|
|
1505
|
+
throw new Error("Crypto API not available. Polyfill failed to load.");
|
|
1506
|
+
}
|
|
1362
1507
|
var instance = msalInstance || new msalBrowser.PublicClientApplication(msalConfig);
|
|
1363
1508
|
return (jsxRuntimeExports.jsx(msalReact.MsalProvider, { instance: instance, children: jsxRuntimeExports.jsx(CAMSProviderCore, __assign({}, props)) }));
|
|
1364
1509
|
}
|
|
1365
|
-
return (jsxRuntimeExports.jsx(ClientOnly, { fallback: jsxRuntimeExports.jsx("div", { children: "Loading..." }), children: jsxRuntimeExports.jsx(CAMSProviderCore, __assign({}, props)) }));
|
|
1510
|
+
return (jsxRuntimeExports.jsx(ClientOnly, { fallback: jsxRuntimeExports.jsx("div", { className: 'h-screen flex items-center justify-center', children: "Loading..." }), children: jsxRuntimeExports.jsx(CAMSProviderCore, __assign({}, props)) }));
|
|
1366
1511
|
}
|
|
1367
1512
|
// Backward compatibility exports
|
|
1368
1513
|
var CAMSProvider = function (props) { return (jsxRuntimeExports.jsx(UnifiedCAMSProvider, __assign({}, props, { mode: "REGULAR" }))); };
|
|
@@ -1691,39 +1836,9 @@ function DialogTitle(_a) {
|
|
|
1691
1836
|
|
|
1692
1837
|
var a="container_f782f4",i="inner_37f4c9",c="bar_409d0f";const r=({size:r=35,color:l="black",speed:d=1,stroke:o=3.5})=>jsxRuntimeExports.jsx("div",{className:a,style:{"--uib-size":r+"px","--uib-color":l,"--uib-speed":d+"s","--uib-stroke":o+"px"},children:jsxRuntimeExports.jsxs("div",{className:i,children:[jsxRuntimeExports.jsx("div",{className:c}),jsxRuntimeExports.jsx("div",{className:c}),jsxRuntimeExports.jsx("div",{className:c}),jsxRuntimeExports.jsx("div",{className:c})]})});
|
|
1693
1838
|
|
|
1694
|
-
function styleInject(css, ref) {
|
|
1695
|
-
if ( ref === void 0 ) ref = {};
|
|
1696
|
-
var insertAt = ref.insertAt;
|
|
1697
|
-
|
|
1698
|
-
if (typeof document === 'undefined') { return; }
|
|
1699
|
-
|
|
1700
|
-
var head = document.head || document.getElementsByTagName('head')[0];
|
|
1701
|
-
var style = document.createElement('style');
|
|
1702
|
-
style.type = 'text/css';
|
|
1703
|
-
|
|
1704
|
-
if (insertAt === 'top') {
|
|
1705
|
-
if (head.firstChild) {
|
|
1706
|
-
head.insertBefore(style, head.firstChild);
|
|
1707
|
-
} else {
|
|
1708
|
-
head.appendChild(style);
|
|
1709
|
-
}
|
|
1710
|
-
} else {
|
|
1711
|
-
head.appendChild(style);
|
|
1712
|
-
}
|
|
1713
|
-
|
|
1714
|
-
if (style.styleSheet) {
|
|
1715
|
-
style.styleSheet.cssText = css;
|
|
1716
|
-
} else {
|
|
1717
|
-
style.appendChild(document.createTextNode(css));
|
|
1718
|
-
}
|
|
1719
|
-
}
|
|
1720
|
-
|
|
1721
|
-
var css_248z = ".container_f782f4 {\n flex-shrink: 0;\n display: inline-flex;\n align-items: center;\n justify-content: center;\n height: calc(var(--uib-size) * 0.9);\n width: var(--uib-size);\n}\n\n.inner_37f4c9 {\n display: flex;\n align-items: center;\n justify-content: space-between;\n width: var(--uib-size);\n height: calc(var(--uib-size) * 0.9);\n}\n\n.bar_409d0f {\n width: var(--uib-stroke);\n height: 100%;\n background-color: var(--uib-color);\n transition: background-color 0.3s ease;\n}\n\n.bar_409d0f:nth-child(1) {\n animation: grow_ca6a4e var(--uib-speed) ease-in-out calc(var(--uib-speed) * -0.45) infinite;\n}\n\n.bar_409d0f:nth-child(2) {\n animation: grow_ca6a4e var(--uib-speed) ease-in-out calc(var(--uib-speed) * -0.3) infinite;\n}\n\n.bar_409d0f:nth-child(3) {\n animation: grow_ca6a4e var(--uib-speed) ease-in-out calc(var(--uib-speed) * -0.15) infinite;\n}\n\n.bar_409d0f:nth-child(4) {\n animation: grow_ca6a4e var(--uib-speed) ease-in-out infinite;\n}\n\n@keyframes grow_ca6a4e {\n 0%, 100% {\n transform: scaleY(0.3);\n }\n 50% {\n transform: scaleY(1);\n }\n}";
|
|
1722
|
-
styleInject(css_248z);
|
|
1723
|
-
|
|
1724
1839
|
var LoadingSpinner = function (_a) {
|
|
1725
1840
|
var loadingText = _a.loadingText;
|
|
1726
|
-
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..." }))] }));
|
|
1841
|
+
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..." }))] }));
|
|
1727
1842
|
};
|
|
1728
1843
|
|
|
1729
1844
|
var AuthSuccessAnimation = function (_a) {
|
|
@@ -1775,15 +1890,36 @@ var APIHeaders = {
|
|
|
1775
1890
|
"X-API-VERSION": "1.0",
|
|
1776
1891
|
};
|
|
1777
1892
|
|
|
1893
|
+
// Creates an Axios instance with a base URL determined by the environment (production or development).
|
|
1894
|
+
var axiosInstance = axios.create({
|
|
1895
|
+
httpsAgent: new https.Agent({ rejectUnauthorized: false }),
|
|
1896
|
+
headers: __assign({ "Content-Type": "application/json" }, APIHeaders),
|
|
1897
|
+
});
|
|
1898
|
+
// Intercepts outgoing requests to add authorization token, version header, and timeout settings.
|
|
1899
|
+
axiosInstance.interceptors.request.use(function (config) {
|
|
1900
|
+
var _a;
|
|
1901
|
+
config.timeout = Number((_a = process.env.NEXT_PUBLIC_API_TIMEOUT) !== null && _a !== void 0 ? _a : 605000);
|
|
1902
|
+
config.timeoutErrorMessage = "Operation Timed Out"; // Custom error message for timeouts.
|
|
1903
|
+
return config; // Returns the modified request configuration.
|
|
1904
|
+
}, function (axiosError) {
|
|
1905
|
+
var _a, _b;
|
|
1906
|
+
// Handles request errors.
|
|
1907
|
+
return {
|
|
1908
|
+
status: (_a = axiosError.response) === null || _a === void 0 ? void 0 : _a.status, // Extracts HTTP status from the error response.
|
|
1909
|
+
message: axiosError.message, // Extracts the error message.
|
|
1910
|
+
data: (_b = axiosError.response) === null || _b === void 0 ? void 0 : _b.data, // Extracts response data from the error.
|
|
1911
|
+
};
|
|
1912
|
+
});
|
|
1913
|
+
|
|
1778
1914
|
var MAX_ATTEMPTS = 3;
|
|
1779
1915
|
var useOTPHandler = function (_a) {
|
|
1780
1916
|
var provider = _a.provider, accessToken = _a.accessToken, idToken = _a.idToken, appCode = _a.appCode, authenticationType = _a.authenticationType, MFAEndpoint = _a.MFAEndpoint, onAuthComplete = _a.onAuthComplete;
|
|
1781
1917
|
var _b = React.useState(false), loading = _b[0], setLoading = _b[1];
|
|
1782
1918
|
var _c = React.useState(0), attemptCount = _c[0], setAttemptCount = _c[1];
|
|
1783
1919
|
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 () {
|
|
1920
|
+
var handleSubmitOTP = React.useMemo(function () { return function (authenticationValue) { return __awaiter$1(void 0, void 0, void 0, function () {
|
|
1785
1921
|
var currentAttempt, response, error_1, currentAttempt;
|
|
1786
|
-
return __generator(this, function (_a) {
|
|
1922
|
+
return __generator$1(this, function (_a) {
|
|
1787
1923
|
switch (_a.label) {
|
|
1788
1924
|
case 0:
|
|
1789
1925
|
if (isMaxAttemptsReached) {
|
|
@@ -1800,16 +1936,13 @@ var useOTPHandler = function (_a) {
|
|
|
1800
1936
|
setAttemptCount(currentAttempt);
|
|
1801
1937
|
if (authenticationType === null)
|
|
1802
1938
|
return [2 /*return*/, false];
|
|
1803
|
-
return [4 /*yield*/,
|
|
1939
|
+
return [4 /*yield*/, axiosInstance.post(MFAEndpoint || "/api/auth/verify-mfa", {
|
|
1804
1940
|
provider: provider,
|
|
1805
1941
|
accessToken: accessToken,
|
|
1806
1942
|
idToken: idToken,
|
|
1807
1943
|
authenticationType: authenticationType,
|
|
1808
1944
|
MFACode: authenticationValue,
|
|
1809
1945
|
appCode: appCode,
|
|
1810
|
-
}, {
|
|
1811
|
-
headers: APIHeaders,
|
|
1812
|
-
timeout: 605000,
|
|
1813
1946
|
})];
|
|
1814
1947
|
case 2:
|
|
1815
1948
|
response = (_a.sent()).data;
|
|
@@ -1876,23 +2009,20 @@ var useCredentialsHandler = function (onAuthComplete) {
|
|
|
1876
2009
|
var _b = React.useState(0), attemptCount = _b[0], setAttemptCount = _b[1];
|
|
1877
2010
|
var _c = React.useState(false), isMaxAttemptsReached = _c[0], setIsMaxAttemptsReached = _c[1];
|
|
1878
2011
|
var handleSubmitCredentials = React.useMemo(function () {
|
|
1879
|
-
return function (CredAuthEndpoint, credentials, appCode) { return __awaiter(void 0, void 0, void 0, function () {
|
|
2012
|
+
return function (CredAuthEndpoint, credentials, appCode) { return __awaiter$1(void 0, void 0, void 0, function () {
|
|
1880
2013
|
var currentAttempt, response, error_2, currentAttempt;
|
|
1881
|
-
return __generator(this, function (_a) {
|
|
2014
|
+
return __generator$1(this, function (_a) {
|
|
1882
2015
|
switch (_a.label) {
|
|
1883
2016
|
case 0:
|
|
1884
2017
|
_a.trys.push([0, 2, 3, 4]);
|
|
1885
2018
|
setLoading(true);
|
|
1886
2019
|
currentAttempt = attemptCount + 1;
|
|
1887
2020
|
setAttemptCount(currentAttempt);
|
|
1888
|
-
return [4 /*yield*/,
|
|
2021
|
+
return [4 /*yield*/, axiosInstance.post(CredAuthEndpoint, {
|
|
1889
2022
|
username: credentials.username,
|
|
1890
2023
|
password: credentials.password,
|
|
1891
2024
|
MFACode: credentials.MFACode,
|
|
1892
2025
|
appCode: appCode,
|
|
1893
|
-
}, {
|
|
1894
|
-
headers: APIHeaders,
|
|
1895
|
-
timeout: 605000,
|
|
1896
2026
|
})];
|
|
1897
2027
|
case 1:
|
|
1898
2028
|
response = (_a.sent()).data;
|
|
@@ -1953,23 +2083,21 @@ var MFAOptions = function (_a) {
|
|
|
1953
2083
|
var context = useCAMSContext();
|
|
1954
2084
|
var _f = context.authMode === "MSAL" && "sendEmailOTP" in context
|
|
1955
2085
|
? context
|
|
1956
|
-
: { sendEmailOTP: null, completeMFA: null, logout: function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
2086
|
+
: { sendEmailOTP: null, completeMFA: null, logout: function () { return __awaiter$1(void 0, void 0, void 0, function () { return __generator$1(this, function (_a) {
|
|
1957
2087
|
return [2 /*return*/];
|
|
1958
2088
|
}); }); } }, sendEmailOTP = _f.sendEmailOTP, completeMFA = _f.completeMFA, logout = _f.logout;
|
|
1959
2089
|
var accessToken = context.authMode === "MSAL" ? context.accessToken : "";
|
|
1960
2090
|
var idToken = context.authMode === "MSAL" ? context.idToken : "";
|
|
1961
2091
|
var authenticate = useWebAuthn().authenticate;
|
|
1962
|
-
var handleFIDOLogin = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
2092
|
+
var handleFIDOLogin = function () { return __awaiter$1(void 0, void 0, void 0, function () {
|
|
1963
2093
|
var options, assertionResponse, error_1;
|
|
1964
|
-
return __generator(this, function (_a) {
|
|
2094
|
+
return __generator$1(this, function (_a) {
|
|
1965
2095
|
switch (_a.label) {
|
|
1966
2096
|
case 0:
|
|
1967
2097
|
_a.trys.push([0, 4, , 5]);
|
|
1968
2098
|
// 1. Fetch authentication challenge from your server
|
|
1969
2099
|
console.log("Requesting authentication challenge from server...");
|
|
1970
|
-
return [4 /*yield*/,
|
|
1971
|
-
headers: APIHeaders,
|
|
1972
|
-
})];
|
|
2100
|
+
return [4 /*yield*/, axiosInstance.post(MFAEndpoints.RetrieveAuthChallenge, {})];
|
|
1973
2101
|
case 1:
|
|
1974
2102
|
options = (_a.sent()).data;
|
|
1975
2103
|
console.log("Received challenge:", options);
|
|
@@ -1981,9 +2109,7 @@ var MFAOptions = function (_a) {
|
|
|
1981
2109
|
console.log("Authentication assertion received from client:", assertionResponse);
|
|
1982
2110
|
// 3. Send the assertion back to the server for verification
|
|
1983
2111
|
console.log("Sending assertion to server for verification...");
|
|
1984
|
-
return [4 /*yield*/,
|
|
1985
|
-
headers: APIHeaders
|
|
1986
|
-
})];
|
|
2112
|
+
return [4 /*yield*/, axiosInstance.post(MFAEndpoints.AuthChallengeVerify, assertionResponse)];
|
|
1987
2113
|
case 3:
|
|
1988
2114
|
_a.sent();
|
|
1989
2115
|
sonner.toast.success("🔑 Sign-in successful!");
|
|
@@ -2045,12 +2171,12 @@ var MFAOptions = function (_a) {
|
|
|
2045
2171
|
}
|
|
2046
2172
|
var content = jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, {});
|
|
2047
2173
|
if (!authType) {
|
|
2048
|
-
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 () {
|
|
2174
|
+
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 () {
|
|
2049
2175
|
var success;
|
|
2050
|
-
return __generator(this, function (_a) {
|
|
2176
|
+
return __generator$1(this, function (_a) {
|
|
2051
2177
|
switch (_a.label) {
|
|
2052
2178
|
case 0:
|
|
2053
|
-
resetAttempts();
|
|
2179
|
+
// resetAttempts();
|
|
2054
2180
|
setAuthType("EmailOTP");
|
|
2055
2181
|
setOtpVisible(true);
|
|
2056
2182
|
if (!sendEmailOTP) return [3 /*break*/, 2];
|
|
@@ -2067,7 +2193,6 @@ var MFAOptions = function (_a) {
|
|
|
2067
2193
|
}
|
|
2068
2194
|
});
|
|
2069
2195
|
}); }, 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 () {
|
|
2070
|
-
resetAttempts();
|
|
2071
2196
|
setAuthType("AuthenticatorCode");
|
|
2072
2197
|
setOtpVisible(true);
|
|
2073
2198
|
}, 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",
|
|
@@ -2076,7 +2201,7 @@ var MFAOptions = function (_a) {
|
|
|
2076
2201
|
// setAuthType("AuthenticatorCode");
|
|
2077
2202
|
// setOtpVisible(true);
|
|
2078
2203
|
// }}
|
|
2079
|
-
onClick: handleFIDOLogin, disabled: context.isLoading, children: [jsxRuntimeExports.jsx(
|
|
2204
|
+
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" })] })] }))] })] }));
|
|
2080
2205
|
}
|
|
2081
2206
|
else if (authType === "EmailOTP") {
|
|
2082
2207
|
content = (jsxRuntimeExports.jsx(Dialog, { open: otpVisible, onOpenChange: function () {
|
|
@@ -2119,16 +2244,16 @@ var ADLoginModal = function (_a) {
|
|
|
2119
2244
|
resolver: a$1(credentialsSchema),
|
|
2120
2245
|
defaultValues: { username: "", password: "" },
|
|
2121
2246
|
});
|
|
2122
|
-
var handleCredentialsSubmit = function (values) { return __awaiter(void 0, void 0, void 0, function () {
|
|
2123
|
-
return __generator(this, function (_a) {
|
|
2247
|
+
var handleCredentialsSubmit = function (values) { return __awaiter$1(void 0, void 0, void 0, function () {
|
|
2248
|
+
return __generator$1(this, function (_a) {
|
|
2124
2249
|
setCredentials(values);
|
|
2125
2250
|
setStep("mfa");
|
|
2126
2251
|
return [2 /*return*/];
|
|
2127
2252
|
});
|
|
2128
2253
|
}); };
|
|
2129
|
-
var handleMFASubmit = function (code) { return __awaiter(void 0, void 0, void 0, function () {
|
|
2254
|
+
var handleMFASubmit = function (code) { return __awaiter$1(void 0, void 0, void 0, function () {
|
|
2130
2255
|
var error_1;
|
|
2131
|
-
return __generator(this, function (_a) {
|
|
2256
|
+
return __generator$1(this, function (_a) {
|
|
2132
2257
|
switch (_a.label) {
|
|
2133
2258
|
case 0:
|
|
2134
2259
|
setIsLoading(true);
|
|
@@ -2189,8 +2314,8 @@ var DefaultLoginPage = function (_a) {
|
|
|
2189
2314
|
var login = context.login, isLoading = context.isLoading, authMode = context.authMode;
|
|
2190
2315
|
var _b = React.useState(false), showADModal = _b[0], setShowADModal = _b[1];
|
|
2191
2316
|
var register = useWebAuthn().register;
|
|
2192
|
-
var _c = useCredentialsHandler(function (state, data) { return __awaiter(void 0, void 0, void 0, function () {
|
|
2193
|
-
return __generator(this, function (_a) {
|
|
2317
|
+
var _c = useCredentialsHandler(function (state, data) { return __awaiter$1(void 0, void 0, void 0, function () {
|
|
2318
|
+
return __generator$1(this, function (_a) {
|
|
2194
2319
|
console.log(data);
|
|
2195
2320
|
if (state && data) {
|
|
2196
2321
|
context.isAuthenticated = true;
|
|
@@ -2204,6 +2329,10 @@ var DefaultLoginPage = function (_a) {
|
|
|
2204
2329
|
});
|
|
2205
2330
|
}); }), handleSubmitCredentials = _c.handleSubmitCredentials, isCredAuthLoading = _c.loading, setIsCredAuthLoading = _c.setLoading;
|
|
2206
2331
|
var handleMSALLogin = function () {
|
|
2332
|
+
if (typeof window !== "undefined" && !window.crypto) {
|
|
2333
|
+
sonner.toast.error("Crypto API not available. Please use a modern browser.");
|
|
2334
|
+
return;
|
|
2335
|
+
}
|
|
2207
2336
|
if (authMode === "MSAL") {
|
|
2208
2337
|
login();
|
|
2209
2338
|
}
|
|
@@ -2212,17 +2341,15 @@ var DefaultLoginPage = function (_a) {
|
|
|
2212
2341
|
console.warn("Regular CAMS login requires configuration");
|
|
2213
2342
|
}
|
|
2214
2343
|
};
|
|
2215
|
-
var handleRegister = function (data) { return __awaiter(void 0, void 0, void 0, function () {
|
|
2344
|
+
var handleRegister = function (data) { return __awaiter$1(void 0, void 0, void 0, function () {
|
|
2216
2345
|
var options, attestationResponse, error_1;
|
|
2217
|
-
return __generator(this, function (_a) {
|
|
2346
|
+
return __generator$1(this, function (_a) {
|
|
2218
2347
|
switch (_a.label) {
|
|
2219
2348
|
case 0:
|
|
2220
2349
|
_a.trys.push([0, 4, , 5]);
|
|
2221
2350
|
// 1. Fetch challenge from your server
|
|
2222
2351
|
console.log("Requesting registration challenge from server...");
|
|
2223
|
-
return [4 /*yield*/,
|
|
2224
|
-
headers: APIHeaders,
|
|
2225
|
-
})];
|
|
2352
|
+
return [4 /*yield*/, axiosInstance.post(MFAEndpoints.RegisterNewChallenge, __assign({}, data))];
|
|
2226
2353
|
case 1:
|
|
2227
2354
|
options = (_a.sent()).data;
|
|
2228
2355
|
console.log("Received challenge:", options);
|
|
@@ -2234,9 +2361,7 @@ var DefaultLoginPage = function (_a) {
|
|
|
2234
2361
|
console.log("Passkey created on client:", attestationResponse);
|
|
2235
2362
|
// 3. Send the response back to the server for verification
|
|
2236
2363
|
console.log("Sending attestation to server for verification...");
|
|
2237
|
-
return [4 /*yield*/,
|
|
2238
|
-
headers: APIHeaders
|
|
2239
|
-
})];
|
|
2364
|
+
return [4 /*yield*/, axiosInstance.post(MFAEndpoints.RegisterVerify + "?username=".concat(data.username), attestationResponse)];
|
|
2240
2365
|
case 3:
|
|
2241
2366
|
_a.sent();
|
|
2242
2367
|
sonner.toast.success("✅ Registration successful! Passkey created.");
|
|
@@ -2250,15 +2375,15 @@ var DefaultLoginPage = function (_a) {
|
|
|
2250
2375
|
}
|
|
2251
2376
|
});
|
|
2252
2377
|
}); };
|
|
2253
|
-
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-
|
|
2378
|
+
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
|
|
2254
2379
|
// variant="outline"
|
|
2255
2380
|
, {
|
|
2256
2381
|
// variant="outline"
|
|
2257
2382
|
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
|
|
2258
2383
|
? "Logging in..."
|
|
2259
|
-
: "Sign in with ActiveDirectory" })] })), usePassKey && (jsxRuntimeExports.jsxs(Button, { className: "w-full flex items-center justify-center cursor-pointer bg-[#506f4a] hover:bg-[#506f4a] rounded-lg border border-transparent px-5 py-8 text-base font-medium transition-colors duration-250", onClick: function () { return handleRegister(PassKeysRegisterProps); }, disabled: isLoading, children: [jsxRuntimeExports.jsx(lucideReact.KeyIcon, { className: "text-[#506f4a]", size: 64 }), jsxRuntimeExports.jsx("span", { children: "Create a Passkey" })] }))] }), jsxRuntimeExports.jsxs(CardFooter, { className: "flex items-center justify-center mt-6 space-x-2 text-gray-400 text-sm", children: [jsxRuntimeExports.jsx(lucideReact.ShieldCheck, { className: "w-4 h-4 text-[#506f4a] pulse-glow" }), jsxRuntimeExports.jsx("span", { children: "Powered By NIBSS" })] })] }) }) }, "landing"), jsxRuntimeExports.jsx(ADLoginModal, { open: showADModal, onOpenChange: setShowADModal, isLoading: isCredAuthLoading, setIsLoading: setIsCredAuthLoading, onLogin: function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
|
|
2384
|
+
: "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) {
|
|
2260
2385
|
var username = _b.username, password = _b.password, MFACode = _b.MFACode;
|
|
2261
|
-
return __generator(this, function (_c) {
|
|
2386
|
+
return __generator$1(this, function (_c) {
|
|
2262
2387
|
// Implement your AD login logic here
|
|
2263
2388
|
console.log("AD Login:", { username: username, password: password, MFACode: MFACode });
|
|
2264
2389
|
// Example: await adLoginService(username, password, mfaCode);
|
|
@@ -2281,12 +2406,30 @@ var MFAEndpointsSchema = z.object({
|
|
|
2281
2406
|
AuthChallengeVerify: z.url("MFA AuthChallengeVerify must be a valid URL"),
|
|
2282
2407
|
});
|
|
2283
2408
|
var MFAGate = function (_a) {
|
|
2284
|
-
var children = _a.children, _b = _a.fallback, fallback = _b === void 0 ? jsxRuntimeExports.jsx(LoadingSpinner, {}) : _b,
|
|
2409
|
+
var children = _a.children, _b = _a.fallback, fallback = _b === void 0 ? jsxRuntimeExports.jsx("div", { className: 'h-screen flex items-center justify-center', children: jsxRuntimeExports.jsx(LoadingSpinner, {}) }) : _b,
|
|
2285
2410
|
// loginComponent: LoginComponent = DefaultLoginPage,
|
|
2286
2411
|
_c = _a.usePassKey,
|
|
2287
2412
|
// loginComponent: LoginComponent = DefaultLoginPage,
|
|
2288
|
-
usePassKey = _c === void 0 ? false : _c, _d = _a.useADLogin, useADLogin = _d === void 0 ? false : _d, CredentialsAuthEndpoint = _a.CredentialsAuthEndpoint, PassKeysRegisterProps = _a.PassKeysRegisterProps, MFAEndpoints = _a.MFAEndpoints;
|
|
2413
|
+
usePassKey = _c === void 0 ? false : _c, _d = _a.useADLogin, useADLogin = _d === void 0 ? false : _d, CredentialsAuthEndpoint = _a.CredentialsAuthEndpoint, PassKeysRegisterProps = _a.PassKeysRegisterProps, MFAEndpoints = _a.MFAEndpoints, requiresMFA = _a.requiresMFA, onAuthSuccess = _a.onAuthSuccess, onAuthError = _a.onAuthError;
|
|
2289
2414
|
var context = useCAMSContext();
|
|
2415
|
+
var hasCalledOnAuthSuccess = React.useRef(false);
|
|
2416
|
+
React.useEffect(function () {
|
|
2417
|
+
var _a;
|
|
2418
|
+
if (context.authMode === "MSAL" && context.accessToken && context.idToken && !hasCalledOnAuthSuccess.current) {
|
|
2419
|
+
var tokens = {
|
|
2420
|
+
accessToken: context.accessToken,
|
|
2421
|
+
idToken: context.idToken,
|
|
2422
|
+
};
|
|
2423
|
+
onAuthSuccess === null || onAuthSuccess === void 0 ? void 0 : onAuthSuccess(tokens);
|
|
2424
|
+
(_a = context.onAuthSuccess) === null || _a === void 0 ? void 0 : _a.call(context, tokens);
|
|
2425
|
+
hasCalledOnAuthSuccess.current = true;
|
|
2426
|
+
}
|
|
2427
|
+
}, [context.accessToken, context.idToken, context.authMode, onAuthSuccess, context]);
|
|
2428
|
+
React.useEffect(function () {
|
|
2429
|
+
if (!context.accessToken) {
|
|
2430
|
+
hasCalledOnAuthSuccess.current = false;
|
|
2431
|
+
}
|
|
2432
|
+
}, [context.accessToken]);
|
|
2290
2433
|
var validatedMFAEndpoints = React.useMemo(function () {
|
|
2291
2434
|
var parsed = MFAEndpointsSchema.safeParse(MFAEndpoints);
|
|
2292
2435
|
if (!parsed.success) {
|
|
@@ -2296,20 +2439,26 @@ var MFAGate = function (_a) {
|
|
|
2296
2439
|
return parsed.data;
|
|
2297
2440
|
}, [MFAEndpoints]);
|
|
2298
2441
|
var handleComplete = React.useCallback(function (success) {
|
|
2299
|
-
if (!success)
|
|
2442
|
+
if (!success) {
|
|
2300
2443
|
camsSdk.Logger.error("MFA authentication failed");
|
|
2444
|
+
}
|
|
2301
2445
|
}, []);
|
|
2302
|
-
var handleAuthFailed = React.useCallback(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2446
|
+
var handleAuthFailed = React.useCallback(function () { return __awaiter$1(void 0, void 0, void 0, function () {
|
|
2447
|
+
var _a;
|
|
2448
|
+
return __generator$1(this, function (_b) {
|
|
2449
|
+
switch (_b.label) {
|
|
2450
|
+
case 0:
|
|
2451
|
+
if (context.authMode === "MSAL" && context.error) {
|
|
2452
|
+
onAuthError === null || onAuthError === void 0 ? void 0 : onAuthError(context.error);
|
|
2453
|
+
(_a = context.onAuthError) === null || _a === void 0 ? void 0 : _a.call(context, context.error);
|
|
2454
|
+
}
|
|
2455
|
+
return [4 /*yield*/, context.logout()];
|
|
2306
2456
|
case 1:
|
|
2307
|
-
|
|
2457
|
+
_b.sent();
|
|
2308
2458
|
return [2 /*return*/];
|
|
2309
2459
|
}
|
|
2310
2460
|
});
|
|
2311
|
-
}); }, [context
|
|
2312
|
-
camsSdk.Logger.debug("MFA Endpoint >>>", { MFAEndpoints: MFAEndpoints });
|
|
2461
|
+
}); }, [context, onAuthError]);
|
|
2313
2462
|
if (useADLogin && !CredentialsAuthEndpoint)
|
|
2314
2463
|
return jsxRuntimeExports.jsx(ErrorFallback, { message: "Invalid AD Login Configuration." });
|
|
2315
2464
|
if (!validatedMFAEndpoints)
|
|
@@ -2318,10 +2467,11 @@ var MFAGate = function (_a) {
|
|
|
2318
2467
|
return jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: children });
|
|
2319
2468
|
if (context.isLoading)
|
|
2320
2469
|
return fallback;
|
|
2321
|
-
if (context.requiresMFA) {
|
|
2322
|
-
return (jsxRuntimeExports.jsx(MFAOptions, { MFAEndpoints: validatedMFAEndpoints, usePassKey: usePassKey, onComplete: handleComplete, onAuthFailed: handleAuthFailed }));
|
|
2323
|
-
}
|
|
2324
2470
|
if (!context.isAuthenticated) {
|
|
2471
|
+
var shouldRequireMFA = requiresMFA !== null && requiresMFA !== void 0 ? requiresMFA : context.requiresMFA;
|
|
2472
|
+
if (shouldRequireMFA && context.accessToken) {
|
|
2473
|
+
return (jsxRuntimeExports.jsx(MFAOptions, { MFAEndpoints: validatedMFAEndpoints, usePassKey: usePassKey, onComplete: handleComplete, onAuthFailed: handleAuthFailed }));
|
|
2474
|
+
}
|
|
2325
2475
|
return (jsxRuntimeExports.jsx(DefaultLoginPage, { usePassKey: usePassKey, useADLogin: useADLogin, MFAEndpoints: MFAEndpoints, PassKeysRegisterProps: PassKeysRegisterProps, CredentialsAuthEndpoint: CredentialsAuthEndpoint }));
|
|
2326
2476
|
}
|
|
2327
2477
|
return jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: children });
|