@nibssplc/cams-sdk-react 1.0.0-rc.2 → 1.0.0-rc.20
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/CAMSMSALProvider.d.ts +1 -0
- package/dist/components/DefaultLoginPage.d.ts +1 -0
- package/dist/components/UnifiedCAMSProvider.d.ts +1 -0
- package/dist/hooks/useCAMSMSALAuth.d.ts +3 -0
- package/dist/index.cjs.js +243 -105
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.esm.js +243 -105
- package/dist/index.esm.js.map +1 -1
- package/dist/lib/actions/Axiosinstance.d.ts +1 -0
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -18,6 +18,119 @@ import * as DialogPrimitive from '@radix-ui/react-dialog';
|
|
|
18
18
|
import { toast } from 'sonner';
|
|
19
19
|
import { motion } from 'framer-motion';
|
|
20
20
|
import axios from 'axios';
|
|
21
|
+
import https from 'https';
|
|
22
|
+
|
|
23
|
+
// Crypto polyfill for MSAL browser compatibility
|
|
24
|
+
if (typeof window !== 'undefined') {
|
|
25
|
+
// Ensure crypto object exists
|
|
26
|
+
if (!window.crypto) {
|
|
27
|
+
window.crypto = {};
|
|
28
|
+
}
|
|
29
|
+
// Polyfill getRandomValues
|
|
30
|
+
if (!window.crypto.getRandomValues) {
|
|
31
|
+
window.crypto.getRandomValues = function (array) {
|
|
32
|
+
var bytes = new Uint8Array(array.buffer, array.byteOffset, array.byteLength);
|
|
33
|
+
for (var i = 0; i < bytes.length; i++) {
|
|
34
|
+
bytes[i] = Math.floor(Math.random() * 256);
|
|
35
|
+
}
|
|
36
|
+
return array;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
// Polyfill crypto.subtle with SHA-256 (handles both undefined and null in non-HTTPS contexts)
|
|
40
|
+
if (!window.crypto.subtle || window.location.protocol === 'http:') {
|
|
41
|
+
var sha256_1 = function (data) { return __awaiter(void 0, void 0, void 0, function () {
|
|
42
|
+
var bytes, hash, k, ml, msg, i, w, j, j, s0, s1, a, b, c, d, e, f, g, h, j, S1, ch, temp1, S0, maj, temp2, result, i;
|
|
43
|
+
return __generator(this, function (_a) {
|
|
44
|
+
bytes = new Uint8Array(data);
|
|
45
|
+
hash = new Uint32Array(8);
|
|
46
|
+
k = new Uint32Array([
|
|
47
|
+
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
|
|
48
|
+
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
|
|
49
|
+
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
|
|
50
|
+
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
|
|
51
|
+
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
|
|
52
|
+
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
|
|
53
|
+
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
|
|
54
|
+
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
|
|
55
|
+
]);
|
|
56
|
+
hash[0] = 0x6a09e667;
|
|
57
|
+
hash[1] = 0xbb67ae85;
|
|
58
|
+
hash[2] = 0x3c6ef372;
|
|
59
|
+
hash[3] = 0xa54ff53a;
|
|
60
|
+
hash[4] = 0x510e527f;
|
|
61
|
+
hash[5] = 0x9b05688c;
|
|
62
|
+
hash[6] = 0x1f83d9ab;
|
|
63
|
+
hash[7] = 0x5be0cd19;
|
|
64
|
+
ml = bytes.length * 8;
|
|
65
|
+
msg = new Uint8Array(bytes.length + 64 + ((64 - ((bytes.length + 9) % 64)) % 64));
|
|
66
|
+
msg.set(bytes);
|
|
67
|
+
msg[bytes.length] = 0x80;
|
|
68
|
+
new DataView(msg.buffer).setUint32(msg.length - 4, ml, false);
|
|
69
|
+
for (i = 0; i < msg.length; i += 64) {
|
|
70
|
+
w = new Uint32Array(64);
|
|
71
|
+
for (j = 0; j < 16; j++)
|
|
72
|
+
w[j] = new DataView(msg.buffer).getUint32(i + j * 4, false);
|
|
73
|
+
for (j = 16; j < 64; j++) {
|
|
74
|
+
s0 = ((w[j - 15] >>> 7) | (w[j - 15] << 25)) ^ ((w[j - 15] >>> 18) | (w[j - 15] << 14)) ^ (w[j - 15] >>> 3);
|
|
75
|
+
s1 = ((w[j - 2] >>> 17) | (w[j - 2] << 15)) ^ ((w[j - 2] >>> 19) | (w[j - 2] << 13)) ^ (w[j - 2] >>> 10);
|
|
76
|
+
w[j] = (w[j - 16] + s0 + w[j - 7] + s1) >>> 0;
|
|
77
|
+
}
|
|
78
|
+
a = hash[0], b = hash[1], c = hash[2], d = hash[3], e = hash[4], f = hash[5], g = hash[6], h = hash[7];
|
|
79
|
+
for (j = 0; j < 64; j++) {
|
|
80
|
+
S1 = ((e >>> 6) | (e << 26)) ^ ((e >>> 11) | (e << 21)) ^ ((e >>> 25) | (e << 7));
|
|
81
|
+
ch = (e & f) ^ (~e & g);
|
|
82
|
+
temp1 = (h + S1 + ch + k[j] + w[j]) >>> 0;
|
|
83
|
+
S0 = ((a >>> 2) | (a << 30)) ^ ((a >>> 13) | (a << 19)) ^ ((a >>> 22) | (a << 10));
|
|
84
|
+
maj = (a & b) ^ (a & c) ^ (b & c);
|
|
85
|
+
temp2 = (S0 + maj) >>> 0;
|
|
86
|
+
h = g;
|
|
87
|
+
g = f;
|
|
88
|
+
f = e;
|
|
89
|
+
e = (d + temp1) >>> 0;
|
|
90
|
+
d = c;
|
|
91
|
+
c = b;
|
|
92
|
+
b = a;
|
|
93
|
+
a = (temp1 + temp2) >>> 0;
|
|
94
|
+
}
|
|
95
|
+
hash[0] = (hash[0] + a) >>> 0;
|
|
96
|
+
hash[1] = (hash[1] + b) >>> 0;
|
|
97
|
+
hash[2] = (hash[2] + c) >>> 0;
|
|
98
|
+
hash[3] = (hash[3] + d) >>> 0;
|
|
99
|
+
hash[4] = (hash[4] + e) >>> 0;
|
|
100
|
+
hash[5] = (hash[5] + f) >>> 0;
|
|
101
|
+
hash[6] = (hash[6] + g) >>> 0;
|
|
102
|
+
hash[7] = (hash[7] + h) >>> 0;
|
|
103
|
+
}
|
|
104
|
+
result = new Uint8Array(32);
|
|
105
|
+
for (i = 0; i < 8; i++)
|
|
106
|
+
new DataView(result.buffer).setUint32(i * 4, hash[i], false);
|
|
107
|
+
return [2 /*return*/, result.buffer];
|
|
108
|
+
});
|
|
109
|
+
}); };
|
|
110
|
+
window.crypto.subtle = {
|
|
111
|
+
digest: function (algorithm, data) { return __awaiter(void 0, void 0, void 0, function () {
|
|
112
|
+
var alg;
|
|
113
|
+
return __generator(this, function (_a) {
|
|
114
|
+
alg = typeof algorithm === 'string' ? algorithm : algorithm.name;
|
|
115
|
+
if (alg === 'SHA-256')
|
|
116
|
+
return [2 /*return*/, sha256_1(data)];
|
|
117
|
+
console.error("Unsupported crypto algorithm: ".concat(alg));
|
|
118
|
+
throw new Error("Unsupported algorithm: ".concat(alg));
|
|
119
|
+
});
|
|
120
|
+
}); }
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
// Polyfill randomUUID
|
|
124
|
+
if (!window.crypto.randomUUID) {
|
|
125
|
+
window.crypto.randomUUID = function () {
|
|
126
|
+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
|
127
|
+
var r = (Math.random() * 16) | 0;
|
|
128
|
+
var v = c === 'x' ? r : (r & 0x3) | 0x8;
|
|
129
|
+
return v.toString(16);
|
|
130
|
+
});
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
}
|
|
21
134
|
|
|
22
135
|
/******************************************************************************
|
|
23
136
|
Copyright (c) Microsoft Corporation.
|
|
@@ -59,7 +172,7 @@ function __rest(s, e) {
|
|
|
59
172
|
return t;
|
|
60
173
|
}
|
|
61
174
|
|
|
62
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
175
|
+
function __awaiter$1(thisArg, _arguments, P, generator) {
|
|
63
176
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
64
177
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
65
178
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
@@ -69,7 +182,7 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
69
182
|
});
|
|
70
183
|
}
|
|
71
184
|
|
|
72
|
-
function __generator(thisArg, body) {
|
|
185
|
+
function __generator$1(thisArg, body) {
|
|
73
186
|
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
74
187
|
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
75
188
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
@@ -166,10 +279,10 @@ function useCAMSAuth(options) {
|
|
|
166
279
|
}
|
|
167
280
|
}
|
|
168
281
|
}, [options.storageKey]);
|
|
169
|
-
var login = useCallback(function (config) { return __awaiter(_this, void 0, void 0, function () {
|
|
282
|
+
var login = useCallback(function (config) { return __awaiter$1(_this, void 0, void 0, function () {
|
|
170
283
|
var loginConfig, userProfile, err_1, e, isPopupClosedError, restoredToken, userProfile;
|
|
171
284
|
var _a, _b, _c;
|
|
172
|
-
return __generator(this, function (_d) {
|
|
285
|
+
return __generator$1(this, function (_d) {
|
|
173
286
|
switch (_d.label) {
|
|
174
287
|
case 0:
|
|
175
288
|
if (!sessionManagerRef.current)
|
|
@@ -217,8 +330,8 @@ function useCAMSAuth(options) {
|
|
|
217
330
|
}
|
|
218
331
|
});
|
|
219
332
|
}); }, [options.idleTimeout]);
|
|
220
|
-
var logout = useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
221
|
-
return __generator(this, function (_a) {
|
|
333
|
+
var logout = useCallback(function () { return __awaiter$1(_this, void 0, void 0, function () {
|
|
334
|
+
return __generator$1(this, function (_a) {
|
|
222
335
|
switch (_a.label) {
|
|
223
336
|
case 0:
|
|
224
337
|
if (!sessionManagerRef.current)
|
|
@@ -249,6 +362,7 @@ function useCAMSAuth(options) {
|
|
|
249
362
|
}
|
|
250
363
|
|
|
251
364
|
var setCookie$1 = function (name, value, days) {
|
|
365
|
+
if (days === void 0) { days = 1; }
|
|
252
366
|
var expires = new Date(Date.now() + days * 24 * 60 * 60 * 1000).toUTCString();
|
|
253
367
|
document.cookie = "".concat(name, "=").concat(encodeURIComponent(value), "; expires=").concat(expires, "; path=/; samesite=Lax");
|
|
254
368
|
};
|
|
@@ -269,17 +383,18 @@ var deleteCookie$1 = function (name) {
|
|
|
269
383
|
|
|
270
384
|
function useCAMSMSALAuth(options) {
|
|
271
385
|
var _this = this;
|
|
272
|
-
var
|
|
273
|
-
var
|
|
386
|
+
var optStorageKey = options.storageKey, optScopes = options.scopes, prompt = options.prompt, appCode = options.appCode, MFAEndpoint = options.MFAEndpoint, onAuthSuccess = options.onAuthSuccess, onAuthError = options.onAuthError, _a = options.activeCookiePeriod, activeCookiePeriod = _a === void 0 ? 1 : _a;
|
|
387
|
+
var storageKey = optStorageKey || "CAMS-MSAL-AUTH-SDK";
|
|
388
|
+
var _b = useMsal(), instance = _b.instance, inProgress = _b.inProgress, accounts = _b.accounts;
|
|
274
389
|
var account = useAccount(accounts[0] || {});
|
|
275
|
-
var
|
|
276
|
-
var
|
|
277
|
-
var
|
|
278
|
-
var
|
|
279
|
-
var
|
|
390
|
+
var _c = useState(null), error = _c[0], setError = _c[1];
|
|
391
|
+
var _d = useState(""), idToken = _d[0], setIdToken = _d[1];
|
|
392
|
+
var _e = useState(""), accessToken = _e[0], setAccessToken = _e[1];
|
|
393
|
+
var _f = useState(null), mfaAuthenticator = _f[0], setMfaAuthenticator = _f[1];
|
|
394
|
+
var _g = useState(false), requiresMFA = _g[0], setRequiresMFA = _g[1];
|
|
280
395
|
var isLoading = inProgress !== InteractionStatus.None;
|
|
281
396
|
var isAuthenticated = !!account && !!accessToken && !requiresMFA;
|
|
282
|
-
var scopes =
|
|
397
|
+
var scopes = optScopes || ["openid", "profile", "email"];
|
|
283
398
|
var isTokenValid = function (token) {
|
|
284
399
|
try {
|
|
285
400
|
var payload = JSON.parse(atob(token.split(".")[1]));
|
|
@@ -303,15 +418,14 @@ function useCAMSMSALAuth(options) {
|
|
|
303
418
|
var mfaConfig = {
|
|
304
419
|
accessToken: accessToken_1,
|
|
305
420
|
idToken: idToken_1,
|
|
306
|
-
appCode:
|
|
421
|
+
appCode: appCode,
|
|
307
422
|
provider: "MSAL",
|
|
308
|
-
apiEndpoint:
|
|
423
|
+
apiEndpoint: MFAEndpoint,
|
|
309
424
|
};
|
|
310
425
|
var authenticator = new CAMSMFAAuthenticator(mfaConfig);
|
|
311
426
|
setMfaAuthenticator(authenticator);
|
|
312
427
|
setRequiresMFA(true);
|
|
313
428
|
}
|
|
314
|
-
Logger.debug("App Code", { ">>>": options.appCode });
|
|
315
429
|
}
|
|
316
430
|
else {
|
|
317
431
|
localStorage.removeItem(storageKey);
|
|
@@ -353,22 +467,26 @@ function useCAMSMSALAuth(options) {
|
|
|
353
467
|
// };
|
|
354
468
|
// handleRedirect();
|
|
355
469
|
// }, []);
|
|
356
|
-
var login = useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
470
|
+
var login = useCallback(function () { return __awaiter$1(_this, void 0, void 0, function () {
|
|
357
471
|
var response, mfaConfig, authenticator, err_1, camsError_1, camsError;
|
|
358
|
-
var _a
|
|
359
|
-
return __generator(this, function (
|
|
360
|
-
switch (
|
|
472
|
+
var _a;
|
|
473
|
+
return __generator$1(this, function (_b) {
|
|
474
|
+
switch (_b.label) {
|
|
361
475
|
case 0:
|
|
476
|
+
if (inProgress !== InteractionStatus.None) {
|
|
477
|
+
Logger.warn("Authentication already in progress, ignoring duplicate call");
|
|
478
|
+
return [2 /*return*/];
|
|
479
|
+
}
|
|
362
480
|
setError(null);
|
|
363
|
-
|
|
481
|
+
_b.label = 1;
|
|
364
482
|
case 1:
|
|
365
|
-
|
|
483
|
+
_b.trys.push([1, 3, , 4]);
|
|
366
484
|
return [4 /*yield*/, instance.loginPopup({
|
|
367
485
|
scopes: scopes,
|
|
368
|
-
prompt:
|
|
486
|
+
prompt: prompt || "login",
|
|
369
487
|
})];
|
|
370
488
|
case 2:
|
|
371
|
-
response =
|
|
489
|
+
response = _b.sent();
|
|
372
490
|
console.log("Login Token response:", {
|
|
373
491
|
accessToken: response.accessToken,
|
|
374
492
|
idToken: response.idToken,
|
|
@@ -378,9 +496,9 @@ function useCAMSMSALAuth(options) {
|
|
|
378
496
|
mfaConfig = {
|
|
379
497
|
accessToken: response.accessToken,
|
|
380
498
|
idToken: response.idToken,
|
|
381
|
-
appCode:
|
|
499
|
+
appCode: appCode,
|
|
382
500
|
provider: "MSAL",
|
|
383
|
-
apiEndpoint:
|
|
501
|
+
apiEndpoint: MFAEndpoint,
|
|
384
502
|
};
|
|
385
503
|
authenticator = new CAMSMFAAuthenticator(mfaConfig);
|
|
386
504
|
setMfaAuthenticator(authenticator);
|
|
@@ -394,10 +512,15 @@ function useCAMSMSALAuth(options) {
|
|
|
394
512
|
idToken: response.idToken,
|
|
395
513
|
}));
|
|
396
514
|
}
|
|
397
|
-
|
|
515
|
+
onAuthSuccess === null || onAuthSuccess === void 0 ? void 0 : onAuthSuccess(response.accessToken);
|
|
398
516
|
return [3 /*break*/, 4];
|
|
399
517
|
case 3:
|
|
400
|
-
err_1 =
|
|
518
|
+
err_1 = _b.sent();
|
|
519
|
+
// Handle interaction_in_progress error
|
|
520
|
+
if (err_1.errorCode === "interaction_in_progress") {
|
|
521
|
+
Logger.warn("Interaction already in progress, please wait");
|
|
522
|
+
return [2 /*return*/];
|
|
523
|
+
}
|
|
401
524
|
// Handle user cancellation gracefully
|
|
402
525
|
if (err_1.errorCode === "user_cancelled") {
|
|
403
526
|
Logger.error("User cancelled login");
|
|
@@ -406,22 +529,22 @@ function useCAMSMSALAuth(options) {
|
|
|
406
529
|
}
|
|
407
530
|
// If popup is blocked
|
|
408
531
|
if (err_1.errorCode === "popup_window_error" ||
|
|
409
|
-
((
|
|
532
|
+
((_a = err_1.message) === null || _a === void 0 ? void 0 : _a.includes("popup"))) {
|
|
410
533
|
camsError_1 = new CAMSError(CAMSErrorType.POPUP_BLOCKED, "Popup blocked by browser. Please allow popups and try again.");
|
|
411
534
|
setError(camsError_1);
|
|
412
|
-
|
|
535
|
+
onAuthError === null || onAuthError === void 0 ? void 0 : onAuthError(camsError_1);
|
|
413
536
|
return [2 /*return*/];
|
|
414
537
|
}
|
|
415
538
|
camsError = new CAMSError(CAMSErrorType.API_VALIDATION_ERROR, "Login failed: " + err_1.message || err_1);
|
|
416
539
|
setError(camsError);
|
|
417
|
-
|
|
540
|
+
onAuthError === null || onAuthError === void 0 ? void 0 : onAuthError(camsError);
|
|
418
541
|
return [3 /*break*/, 4];
|
|
419
542
|
case 4: return [2 /*return*/];
|
|
420
543
|
}
|
|
421
544
|
});
|
|
422
|
-
}); }, [instance, scopes,
|
|
423
|
-
var completeMFA = useCallback(function (data) { return __awaiter(_this, void 0, void 0, function () {
|
|
424
|
-
return __generator(this, function (_a) {
|
|
545
|
+
}); }, [instance, scopes, prompt, appCode, MFAEndpoint, onAuthSuccess, onAuthError, storageKey, inProgress]);
|
|
546
|
+
var completeMFA = useCallback(function (data) { return __awaiter$1(_this, void 0, void 0, function () {
|
|
547
|
+
return __generator$1(this, function (_a) {
|
|
425
548
|
if (!mfaAuthenticator) {
|
|
426
549
|
throw new CAMSError(CAMSErrorType.API_VALIDATION_ERROR, "MFA Authenticator not initialized");
|
|
427
550
|
}
|
|
@@ -435,7 +558,7 @@ function useCAMSMSALAuth(options) {
|
|
|
435
558
|
accessToken: accessToken,
|
|
436
559
|
idToken: idToken,
|
|
437
560
|
}));
|
|
438
|
-
setCookie$1("CAMS-MSAL-AUTH-SDK-PROFILE", JSON.stringify({ type: "AUTH_SUCCESS", userProfile: __assign({}, data) }),
|
|
561
|
+
setCookie$1("CAMS-MSAL-AUTH-SDK-PROFILE", JSON.stringify({ type: "AUTH_SUCCESS", userProfile: __assign({}, data) }), activeCookiePeriod);
|
|
439
562
|
setRequiresMFA(false);
|
|
440
563
|
// Set requiresMFA to false after storage update
|
|
441
564
|
Logger.debug("MFA completed successfully, storage updated", {
|
|
@@ -454,9 +577,9 @@ function useCAMSMSALAuth(options) {
|
|
|
454
577
|
}
|
|
455
578
|
return [2 /*return*/];
|
|
456
579
|
});
|
|
457
|
-
}); }, [mfaAuthenticator, accessToken, idToken, storageKey]);
|
|
458
|
-
var sendEmailOTP = useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
459
|
-
return __generator(this, function (_a) {
|
|
580
|
+
}); }, [mfaAuthenticator, accessToken, idToken, storageKey, activeCookiePeriod]);
|
|
581
|
+
var sendEmailOTP = useCallback(function () { return __awaiter$1(_this, void 0, void 0, function () {
|
|
582
|
+
return __generator$1(this, function (_a) {
|
|
460
583
|
switch (_a.label) {
|
|
461
584
|
case 0:
|
|
462
585
|
if (!mfaAuthenticator) {
|
|
@@ -467,9 +590,9 @@ function useCAMSMSALAuth(options) {
|
|
|
467
590
|
}
|
|
468
591
|
});
|
|
469
592
|
}); }, [mfaAuthenticator]);
|
|
470
|
-
var logout = useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
593
|
+
var logout = useCallback(function () { return __awaiter$1(_this, void 0, void 0, function () {
|
|
471
594
|
var err_2, camsError;
|
|
472
|
-
return __generator(this, function (_a) {
|
|
595
|
+
return __generator$1(this, function (_a) {
|
|
473
596
|
switch (_a.label) {
|
|
474
597
|
case 0:
|
|
475
598
|
_a.trys.push([0, 2, , 3]);
|
|
@@ -505,12 +628,13 @@ function useCAMSMSALAuth(options) {
|
|
|
505
628
|
error: error,
|
|
506
629
|
idToken: idToken,
|
|
507
630
|
accessToken: accessToken,
|
|
508
|
-
appCode:
|
|
631
|
+
appCode: appCode,
|
|
509
632
|
mfaAuthenticator: mfaAuthenticator,
|
|
510
633
|
requiresMFA: requiresMFA,
|
|
511
634
|
completeMFA: completeMFA,
|
|
512
635
|
sendEmailOTP: sendEmailOTP,
|
|
513
636
|
setRequiresMFA: setRequiresMFA,
|
|
637
|
+
activeCookiePeriod: activeCookiePeriod,
|
|
514
638
|
};
|
|
515
639
|
}
|
|
516
640
|
|
|
@@ -553,10 +677,10 @@ function arrayBufferToBase64url(buffer) {
|
|
|
553
677
|
* @returns A promise that resolves to a JSON-serializable representation of the PublicKeyCredential.
|
|
554
678
|
*/
|
|
555
679
|
function register(options) {
|
|
556
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
680
|
+
return __awaiter$1(this, void 0, void 0, function () {
|
|
557
681
|
var createOptions, credential, publicKeyCredential, attestationResponse, transports, err_1;
|
|
558
682
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
559
|
-
return __generator(this, function (_k) {
|
|
683
|
+
return __generator$1(this, function (_k) {
|
|
560
684
|
switch (_k.label) {
|
|
561
685
|
case 0:
|
|
562
686
|
_k.trys.push([0, 2, , 3]);
|
|
@@ -614,10 +738,10 @@ function register(options) {
|
|
|
614
738
|
* @returns A promise that resolves to a JSON-serializable representation of the PublicKeyCredential.
|
|
615
739
|
*/
|
|
616
740
|
function authenticate(options) {
|
|
617
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
741
|
+
return __awaiter$1(this, void 0, void 0, function () {
|
|
618
742
|
var getOptions, credential, publicKeyCredential, assertionResponse;
|
|
619
743
|
var _a;
|
|
620
|
-
return __generator(this, function (_b) {
|
|
744
|
+
return __generator$1(this, function (_b) {
|
|
621
745
|
switch (_b.label) {
|
|
622
746
|
case 0:
|
|
623
747
|
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) })); }) });
|
|
@@ -1104,7 +1228,9 @@ function ProtectedRoute(_a) {
|
|
|
1104
1228
|
|
|
1105
1229
|
var CAMSMSALContext = createContext(null);
|
|
1106
1230
|
var setCookie = function (name, value, days) {
|
|
1231
|
+
if (days === void 0) { days = 1; }
|
|
1107
1232
|
var expires = new Date(Date.now() + days * 864e5).toUTCString();
|
|
1233
|
+
Logger.debug("Auth Cookie Expires >>>", { name: name, value: value, expires: expires });
|
|
1108
1234
|
document.cookie = "".concat(name, "=").concat(encodeURIComponent(value), "; expires=").concat(expires, "; path=/; samesite=Lax");
|
|
1109
1235
|
};
|
|
1110
1236
|
var getCookie = function (name) {
|
|
@@ -1169,7 +1295,7 @@ function CAMSMSALProviderInner(_a) {
|
|
|
1169
1295
|
localStorage.setItem(auth.storageKey, JSON.stringify({
|
|
1170
1296
|
accessToken: auth.accessToken,
|
|
1171
1297
|
idToken: auth.idToken,
|
|
1172
|
-
appCode: auth.appCode
|
|
1298
|
+
appCode: auth.appCode,
|
|
1173
1299
|
}));
|
|
1174
1300
|
}
|
|
1175
1301
|
}, [auth.accessToken, auth.idToken, auth.storageKey]);
|
|
@@ -1177,7 +1303,7 @@ function CAMSMSALProviderInner(_a) {
|
|
|
1177
1303
|
useEffect(function () {
|
|
1178
1304
|
if (typeof window !== "undefined") {
|
|
1179
1305
|
if (userProfile) {
|
|
1180
|
-
setCookie(profileStorageKey, JSON.stringify(userProfile),
|
|
1306
|
+
setCookie(profileStorageKey, JSON.stringify(userProfile), auth.activeCookiePeriod); // Store for 1 day
|
|
1181
1307
|
}
|
|
1182
1308
|
else {
|
|
1183
1309
|
deleteCookie(profileStorageKey);
|
|
@@ -1185,8 +1311,8 @@ function CAMSMSALProviderInner(_a) {
|
|
|
1185
1311
|
}
|
|
1186
1312
|
}, [userProfile, profileStorageKey]);
|
|
1187
1313
|
// Enhanced logout that also clears profile
|
|
1188
|
-
var enhancedLogout = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
1189
|
-
return __generator(this, function (_a) {
|
|
1314
|
+
var enhancedLogout = function () { return __awaiter$1(_this, void 0, void 0, function () {
|
|
1315
|
+
return __generator$1(this, function (_a) {
|
|
1190
1316
|
switch (_a.label) {
|
|
1191
1317
|
case 0: return [4 /*yield*/, auth.logout()];
|
|
1192
1318
|
case 1:
|
|
@@ -1204,7 +1330,9 @@ function CAMSMSALProviderInner(_a) {
|
|
|
1204
1330
|
}
|
|
1205
1331
|
function CAMSMSALProvider(props) {
|
|
1206
1332
|
var msalConfig = props.msalConfig, msalInstance = props.msalInstance;
|
|
1207
|
-
var instance =
|
|
1333
|
+
var instance = typeof window !== "undefined"
|
|
1334
|
+
? msalInstance || new PublicClientApplication(msalConfig)
|
|
1335
|
+
: null;
|
|
1208
1336
|
return (jsxRuntimeExports.jsx(MsalProvider, { instance: instance, children: jsxRuntimeExports.jsx(CAMSMSALProviderInner, __assign({}, props)) }));
|
|
1209
1337
|
}
|
|
1210
1338
|
function useCAMSMSALContext() {
|
|
@@ -1282,8 +1410,8 @@ function CAMSProviderCore(props) {
|
|
|
1282
1410
|
}
|
|
1283
1411
|
}
|
|
1284
1412
|
}, [userProfile, profileStorageKey]);
|
|
1285
|
-
var enhancedLogout = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
1286
|
-
return __generator(this, function (_a) {
|
|
1413
|
+
var enhancedLogout = function () { return __awaiter$1(_this, void 0, void 0, function () {
|
|
1414
|
+
return __generator$1(this, function (_a) {
|
|
1287
1415
|
switch (_a.label) {
|
|
1288
1416
|
case 0: return [4 /*yield*/, auth.logout()];
|
|
1289
1417
|
case 1:
|
|
@@ -1326,7 +1454,8 @@ function CAMSProviderCore(props) {
|
|
|
1326
1454
|
userProfile,
|
|
1327
1455
|
]);
|
|
1328
1456
|
var value = useMemo(function () {
|
|
1329
|
-
|
|
1457
|
+
auth.logout; var authRest = __rest(auth, ["logout"]);
|
|
1458
|
+
return __assign(__assign({}, authRest), { logout: enhancedLogout, userProfile: userProfile, setUserProfile: setUserProfile, authMode: mode });
|
|
1330
1459
|
}, [auth, userProfile, mode]);
|
|
1331
1460
|
return jsxRuntimeExports.jsx(CAMSContext.Provider, { value: value, children: children });
|
|
1332
1461
|
}
|
|
@@ -1338,7 +1467,9 @@ function UnifiedCAMSProvider(props) {
|
|
|
1338
1467
|
}
|
|
1339
1468
|
if (props.mode === "MSAL") {
|
|
1340
1469
|
var msalConfig = props.msalConfig, msalInstance = props.msalInstance;
|
|
1341
|
-
var instance =
|
|
1470
|
+
var instance = typeof window !== "undefined"
|
|
1471
|
+
? msalInstance || new PublicClientApplication(msalConfig)
|
|
1472
|
+
: null;
|
|
1342
1473
|
return (jsxRuntimeExports.jsx(MsalProvider, { instance: instance, children: jsxRuntimeExports.jsx(CAMSProviderCore, __assign({}, props)) }));
|
|
1343
1474
|
}
|
|
1344
1475
|
return (jsxRuntimeExports.jsx(ClientOnly, { fallback: jsxRuntimeExports.jsx("div", { children: "Loading..." }), children: jsxRuntimeExports.jsx(CAMSProviderCore, __assign({}, props)) }));
|
|
@@ -1702,7 +1833,7 @@ styleInject(css_248z);
|
|
|
1702
1833
|
|
|
1703
1834
|
var LoadingSpinner = function (_a) {
|
|
1704
1835
|
var loadingText = _a.loadingText;
|
|
1705
|
-
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..." }))] }));
|
|
1836
|
+
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..." }))] }));
|
|
1706
1837
|
};
|
|
1707
1838
|
|
|
1708
1839
|
var AuthSuccessAnimation = function (_a) {
|
|
@@ -1754,15 +1885,36 @@ var APIHeaders = {
|
|
|
1754
1885
|
"X-API-VERSION": "1.0",
|
|
1755
1886
|
};
|
|
1756
1887
|
|
|
1888
|
+
// Creates an Axios instance with a base URL determined by the environment (production or development).
|
|
1889
|
+
var axiosInstance = axios.create({
|
|
1890
|
+
httpsAgent: new https.Agent({ rejectUnauthorized: false }),
|
|
1891
|
+
headers: __assign({ "Content-Type": "application/json" }, APIHeaders),
|
|
1892
|
+
});
|
|
1893
|
+
// Intercepts outgoing requests to add authorization token, version header, and timeout settings.
|
|
1894
|
+
axiosInstance.interceptors.request.use(function (config) {
|
|
1895
|
+
var _a;
|
|
1896
|
+
config.timeout = Number((_a = process.env.NEXT_PUBLIC_API_TIMEOUT) !== null && _a !== void 0 ? _a : 605000);
|
|
1897
|
+
config.timeoutErrorMessage = "Operation Timed Out"; // Custom error message for timeouts.
|
|
1898
|
+
return config; // Returns the modified request configuration.
|
|
1899
|
+
}, function (axiosError) {
|
|
1900
|
+
var _a, _b;
|
|
1901
|
+
// Handles request errors.
|
|
1902
|
+
return {
|
|
1903
|
+
status: (_a = axiosError.response) === null || _a === void 0 ? void 0 : _a.status, // Extracts HTTP status from the error response.
|
|
1904
|
+
message: axiosError.message, // Extracts the error message.
|
|
1905
|
+
data: (_b = axiosError.response) === null || _b === void 0 ? void 0 : _b.data, // Extracts response data from the error.
|
|
1906
|
+
};
|
|
1907
|
+
});
|
|
1908
|
+
|
|
1757
1909
|
var MAX_ATTEMPTS = 3;
|
|
1758
1910
|
var useOTPHandler = function (_a) {
|
|
1759
1911
|
var provider = _a.provider, accessToken = _a.accessToken, idToken = _a.idToken, appCode = _a.appCode, authenticationType = _a.authenticationType, MFAEndpoint = _a.MFAEndpoint, onAuthComplete = _a.onAuthComplete;
|
|
1760
1912
|
var _b = useState(false), loading = _b[0], setLoading = _b[1];
|
|
1761
1913
|
var _c = useState(0), attemptCount = _c[0], setAttemptCount = _c[1];
|
|
1762
1914
|
var _d = useState(false), isMaxAttemptsReached = _d[0], setIsMaxAttemptsReached = _d[1];
|
|
1763
|
-
var handleSubmitOTP = useMemo(function () { return function (authenticationValue) { return __awaiter(void 0, void 0, void 0, function () {
|
|
1915
|
+
var handleSubmitOTP = useMemo(function () { return function (authenticationValue) { return __awaiter$1(void 0, void 0, void 0, function () {
|
|
1764
1916
|
var currentAttempt, response, error_1, currentAttempt;
|
|
1765
|
-
return __generator(this, function (_a) {
|
|
1917
|
+
return __generator$1(this, function (_a) {
|
|
1766
1918
|
switch (_a.label) {
|
|
1767
1919
|
case 0:
|
|
1768
1920
|
if (isMaxAttemptsReached) {
|
|
@@ -1779,16 +1931,13 @@ var useOTPHandler = function (_a) {
|
|
|
1779
1931
|
setAttemptCount(currentAttempt);
|
|
1780
1932
|
if (authenticationType === null)
|
|
1781
1933
|
return [2 /*return*/, false];
|
|
1782
|
-
return [4 /*yield*/,
|
|
1934
|
+
return [4 /*yield*/, axiosInstance.post(MFAEndpoint || "/api/auth/verify-mfa", {
|
|
1783
1935
|
provider: provider,
|
|
1784
1936
|
accessToken: accessToken,
|
|
1785
1937
|
idToken: idToken,
|
|
1786
1938
|
authenticationType: authenticationType,
|
|
1787
1939
|
MFACode: authenticationValue,
|
|
1788
1940
|
appCode: appCode,
|
|
1789
|
-
}, {
|
|
1790
|
-
headers: APIHeaders,
|
|
1791
|
-
timeout: 605000,
|
|
1792
1941
|
})];
|
|
1793
1942
|
case 2:
|
|
1794
1943
|
response = (_a.sent()).data;
|
|
@@ -1855,23 +2004,20 @@ var useCredentialsHandler = function (onAuthComplete) {
|
|
|
1855
2004
|
var _b = useState(0), attemptCount = _b[0], setAttemptCount = _b[1];
|
|
1856
2005
|
var _c = useState(false), isMaxAttemptsReached = _c[0], setIsMaxAttemptsReached = _c[1];
|
|
1857
2006
|
var handleSubmitCredentials = useMemo(function () {
|
|
1858
|
-
return function (CredAuthEndpoint, credentials, appCode) { return __awaiter(void 0, void 0, void 0, function () {
|
|
2007
|
+
return function (CredAuthEndpoint, credentials, appCode) { return __awaiter$1(void 0, void 0, void 0, function () {
|
|
1859
2008
|
var currentAttempt, response, error_2, currentAttempt;
|
|
1860
|
-
return __generator(this, function (_a) {
|
|
2009
|
+
return __generator$1(this, function (_a) {
|
|
1861
2010
|
switch (_a.label) {
|
|
1862
2011
|
case 0:
|
|
1863
2012
|
_a.trys.push([0, 2, 3, 4]);
|
|
1864
2013
|
setLoading(true);
|
|
1865
2014
|
currentAttempt = attemptCount + 1;
|
|
1866
2015
|
setAttemptCount(currentAttempt);
|
|
1867
|
-
return [4 /*yield*/,
|
|
2016
|
+
return [4 /*yield*/, axiosInstance.post(CredAuthEndpoint, {
|
|
1868
2017
|
username: credentials.username,
|
|
1869
2018
|
password: credentials.password,
|
|
1870
2019
|
MFACode: credentials.MFACode,
|
|
1871
2020
|
appCode: appCode,
|
|
1872
|
-
}, {
|
|
1873
|
-
headers: APIHeaders,
|
|
1874
|
-
timeout: 605000,
|
|
1875
2021
|
})];
|
|
1876
2022
|
case 1:
|
|
1877
2023
|
response = (_a.sent()).data;
|
|
@@ -1932,23 +2078,21 @@ var MFAOptions = function (_a) {
|
|
|
1932
2078
|
var context = useCAMSContext();
|
|
1933
2079
|
var _f = context.authMode === "MSAL" && "sendEmailOTP" in context
|
|
1934
2080
|
? context
|
|
1935
|
-
: { sendEmailOTP: null, completeMFA: null, logout: function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
2081
|
+
: { sendEmailOTP: null, completeMFA: null, logout: function () { return __awaiter$1(void 0, void 0, void 0, function () { return __generator$1(this, function (_a) {
|
|
1936
2082
|
return [2 /*return*/];
|
|
1937
2083
|
}); }); } }, sendEmailOTP = _f.sendEmailOTP, completeMFA = _f.completeMFA, logout = _f.logout;
|
|
1938
2084
|
var accessToken = context.authMode === "MSAL" ? context.accessToken : "";
|
|
1939
2085
|
var idToken = context.authMode === "MSAL" ? context.idToken : "";
|
|
1940
2086
|
var authenticate = useWebAuthn().authenticate;
|
|
1941
|
-
var handleFIDOLogin = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
2087
|
+
var handleFIDOLogin = function () { return __awaiter$1(void 0, void 0, void 0, function () {
|
|
1942
2088
|
var options, assertionResponse, error_1;
|
|
1943
|
-
return __generator(this, function (_a) {
|
|
2089
|
+
return __generator$1(this, function (_a) {
|
|
1944
2090
|
switch (_a.label) {
|
|
1945
2091
|
case 0:
|
|
1946
2092
|
_a.trys.push([0, 4, , 5]);
|
|
1947
2093
|
// 1. Fetch authentication challenge from your server
|
|
1948
2094
|
console.log("Requesting authentication challenge from server...");
|
|
1949
|
-
return [4 /*yield*/,
|
|
1950
|
-
headers: APIHeaders,
|
|
1951
|
-
})];
|
|
2095
|
+
return [4 /*yield*/, axiosInstance.post(MFAEndpoints.RetrieveAuthChallenge, {})];
|
|
1952
2096
|
case 1:
|
|
1953
2097
|
options = (_a.sent()).data;
|
|
1954
2098
|
console.log("Received challenge:", options);
|
|
@@ -1960,10 +2104,7 @@ var MFAOptions = function (_a) {
|
|
|
1960
2104
|
console.log("Authentication assertion received from client:", assertionResponse);
|
|
1961
2105
|
// 3. Send the assertion back to the server for verification
|
|
1962
2106
|
console.log("Sending assertion to server for verification...");
|
|
1963
|
-
return [4 /*yield*/,
|
|
1964
|
-
headers: APIHeaders,
|
|
1965
|
-
withCredentials: true, // credentials: 'include'
|
|
1966
|
-
})];
|
|
2107
|
+
return [4 /*yield*/, axiosInstance.post(MFAEndpoints.AuthChallengeVerify, assertionResponse)];
|
|
1967
2108
|
case 3:
|
|
1968
2109
|
_a.sent();
|
|
1969
2110
|
toast.success("🔑 Sign-in successful!");
|
|
@@ -2025,12 +2166,12 @@ var MFAOptions = function (_a) {
|
|
|
2025
2166
|
}
|
|
2026
2167
|
var content = jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, {});
|
|
2027
2168
|
if (!authType) {
|
|
2028
|
-
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 () {
|
|
2169
|
+
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 () {
|
|
2029
2170
|
var success;
|
|
2030
|
-
return __generator(this, function (_a) {
|
|
2171
|
+
return __generator$1(this, function (_a) {
|
|
2031
2172
|
switch (_a.label) {
|
|
2032
2173
|
case 0:
|
|
2033
|
-
resetAttempts();
|
|
2174
|
+
// resetAttempts();
|
|
2034
2175
|
setAuthType("EmailOTP");
|
|
2035
2176
|
setOtpVisible(true);
|
|
2036
2177
|
if (!sendEmailOTP) return [3 /*break*/, 2];
|
|
@@ -2047,7 +2188,6 @@ var MFAOptions = function (_a) {
|
|
|
2047
2188
|
}
|
|
2048
2189
|
});
|
|
2049
2190
|
}); }, children: [jsxRuntimeExports.jsx(Mail, { className: "w-5 h-5" }), jsxRuntimeExports.jsxs("div", { className: "text-left", children: [jsxRuntimeExports.jsx("div", { className: "font-medium", children: "Email OTP" }), jsxRuntimeExports.jsx("div", { className: "text-sm text-gray-500", children: "Send code to your email" })] })] }), jsxRuntimeExports.jsxs(Button, { variant: "outline", className: "w-full flex items-center justify-start gap-3 p-4 h-auto border-2 hover:border-[#506f4a] hover:bg-[#506f4a]/5 transition-all", onClick: function () {
|
|
2050
|
-
resetAttempts();
|
|
2051
2191
|
setAuthType("AuthenticatorCode");
|
|
2052
2192
|
setOtpVisible(true);
|
|
2053
2193
|
}, children: [jsxRuntimeExports.jsx("img", { src: MicrosoftAuthenticatorImg, alt: "Authenticator", className: "rounded-full", width: 24, height: 24, onError: function () { return jsxRuntimeExports.jsx(Shield, {}); } }), jsxRuntimeExports.jsxs("div", { className: "text-left", children: [jsxRuntimeExports.jsx("div", { className: "font-medium", children: "Authenticator App" }), jsxRuntimeExports.jsx("div", { className: "text-sm text-gray-500", children: "Use Authenticator App" })] })] }), usePassKey && (jsxRuntimeExports.jsxs(Button, { variant: "outline", className: "w-full flex items-center justify-start gap-3 p-4 h-auto border-2 hover:border-[#506f4a] hover:bg-[#506f4a]/5 transition-all",
|
|
@@ -2056,7 +2196,7 @@ var MFAOptions = function (_a) {
|
|
|
2056
2196
|
// setAuthType("AuthenticatorCode");
|
|
2057
2197
|
// setOtpVisible(true);
|
|
2058
2198
|
// }}
|
|
2059
|
-
onClick: handleFIDOLogin, disabled: context.isLoading, children: [jsxRuntimeExports.jsx(
|
|
2199
|
+
onClick: handleFIDOLogin, disabled: context.isLoading, children: [jsxRuntimeExports.jsx(KeyIcon, { className: "text-[#506f4a]", size: 48 }), jsxRuntimeExports.jsxs("div", { className: "text-left", children: [jsxRuntimeExports.jsx("div", { className: "font-medium", children: "Continue with Passkey" }), jsxRuntimeExports.jsx("div", { className: "text-sm text-gray-500", children: "Passkey" })] })] }))] })] }));
|
|
2060
2200
|
}
|
|
2061
2201
|
else if (authType === "EmailOTP") {
|
|
2062
2202
|
content = (jsxRuntimeExports.jsx(Dialog, { open: otpVisible, onOpenChange: function () {
|
|
@@ -2099,16 +2239,16 @@ var ADLoginModal = function (_a) {
|
|
|
2099
2239
|
resolver: a$1(credentialsSchema),
|
|
2100
2240
|
defaultValues: { username: "", password: "" },
|
|
2101
2241
|
});
|
|
2102
|
-
var handleCredentialsSubmit = function (values) { return __awaiter(void 0, void 0, void 0, function () {
|
|
2103
|
-
return __generator(this, function (_a) {
|
|
2242
|
+
var handleCredentialsSubmit = function (values) { return __awaiter$1(void 0, void 0, void 0, function () {
|
|
2243
|
+
return __generator$1(this, function (_a) {
|
|
2104
2244
|
setCredentials(values);
|
|
2105
2245
|
setStep("mfa");
|
|
2106
2246
|
return [2 /*return*/];
|
|
2107
2247
|
});
|
|
2108
2248
|
}); };
|
|
2109
|
-
var handleMFASubmit = function (code) { return __awaiter(void 0, void 0, void 0, function () {
|
|
2249
|
+
var handleMFASubmit = function (code) { return __awaiter$1(void 0, void 0, void 0, function () {
|
|
2110
2250
|
var error_1;
|
|
2111
|
-
return __generator(this, function (_a) {
|
|
2251
|
+
return __generator$1(this, function (_a) {
|
|
2112
2252
|
switch (_a.label) {
|
|
2113
2253
|
case 0:
|
|
2114
2254
|
setIsLoading(true);
|
|
@@ -2144,7 +2284,7 @@ var ADLoginModal = function (_a) {
|
|
|
2144
2284
|
form.reset();
|
|
2145
2285
|
setMfaCode("");
|
|
2146
2286
|
};
|
|
2147
|
-
return (jsxRuntimeExports.jsx(Dialog, { open: open, onOpenChange: handleClose, children: jsxRuntimeExports.jsxs(DialogContent, { className: "
|
|
2287
|
+
return (jsxRuntimeExports.jsx(Dialog, { open: open, onOpenChange: handleClose, children: jsxRuntimeExports.jsxs(DialogContent, { className: "min-w-[50vw] max-w-[70vw]", children: [jsxRuntimeExports.jsx(DialogHeader, { children: jsxRuntimeExports.jsxs("div", { className: "flex items-center gap-2", children: [jsxRuntimeExports.jsx(KeyIcon, { className: "w-8 h-8 text-[#506f4a]" }), jsxRuntimeExports.jsx(DialogTitle, { className: "text-2xl", children: "Sign in with AD" })] }) }), step === "credentials" ? (jsxRuntimeExports.jsx(Form, __assign({}, form, { children: jsxRuntimeExports.jsxs("form", { onSubmit: form.handleSubmit(handleCredentialsSubmit), className: "space-y-4", children: [jsxRuntimeExports.jsx(FormField, { control: form.control, name: "username", render: function (_a) {
|
|
2148
2288
|
var field = _a.field;
|
|
2149
2289
|
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, {})] }));
|
|
2150
2290
|
} }), jsxRuntimeExports.jsx(FormField, { control: form.control, name: "password", render: function (_a) {
|
|
@@ -2169,8 +2309,8 @@ var DefaultLoginPage = function (_a) {
|
|
|
2169
2309
|
var login = context.login, isLoading = context.isLoading, authMode = context.authMode;
|
|
2170
2310
|
var _b = useState(false), showADModal = _b[0], setShowADModal = _b[1];
|
|
2171
2311
|
var register = useWebAuthn().register;
|
|
2172
|
-
var _c = useCredentialsHandler(function (state, data) { return __awaiter(void 0, void 0, void 0, function () {
|
|
2173
|
-
return __generator(this, function (_a) {
|
|
2312
|
+
var _c = useCredentialsHandler(function (state, data) { return __awaiter$1(void 0, void 0, void 0, function () {
|
|
2313
|
+
return __generator$1(this, function (_a) {
|
|
2174
2314
|
console.log(data);
|
|
2175
2315
|
if (state && data) {
|
|
2176
2316
|
context.isAuthenticated = true;
|
|
@@ -2184,6 +2324,10 @@ var DefaultLoginPage = function (_a) {
|
|
|
2184
2324
|
});
|
|
2185
2325
|
}); }), handleSubmitCredentials = _c.handleSubmitCredentials, isCredAuthLoading = _c.loading, setIsCredAuthLoading = _c.setLoading;
|
|
2186
2326
|
var handleMSALLogin = function () {
|
|
2327
|
+
if (typeof window !== "undefined" && !window.crypto) {
|
|
2328
|
+
toast.error("Crypto API not available. Please use a modern browser.");
|
|
2329
|
+
return;
|
|
2330
|
+
}
|
|
2187
2331
|
if (authMode === "MSAL") {
|
|
2188
2332
|
login();
|
|
2189
2333
|
}
|
|
@@ -2192,17 +2336,15 @@ var DefaultLoginPage = function (_a) {
|
|
|
2192
2336
|
console.warn("Regular CAMS login requires configuration");
|
|
2193
2337
|
}
|
|
2194
2338
|
};
|
|
2195
|
-
var handleRegister = function (data) { return __awaiter(void 0, void 0, void 0, function () {
|
|
2339
|
+
var handleRegister = function (data) { return __awaiter$1(void 0, void 0, void 0, function () {
|
|
2196
2340
|
var options, attestationResponse, error_1;
|
|
2197
|
-
return __generator(this, function (_a) {
|
|
2341
|
+
return __generator$1(this, function (_a) {
|
|
2198
2342
|
switch (_a.label) {
|
|
2199
2343
|
case 0:
|
|
2200
2344
|
_a.trys.push([0, 4, , 5]);
|
|
2201
2345
|
// 1. Fetch challenge from your server
|
|
2202
2346
|
console.log("Requesting registration challenge from server...");
|
|
2203
|
-
return [4 /*yield*/,
|
|
2204
|
-
headers: APIHeaders,
|
|
2205
|
-
})];
|
|
2347
|
+
return [4 /*yield*/, axiosInstance.post(MFAEndpoints.RegisterNewChallenge, __assign({}, data))];
|
|
2206
2348
|
case 1:
|
|
2207
2349
|
options = (_a.sent()).data;
|
|
2208
2350
|
console.log("Received challenge:", options);
|
|
@@ -2214,10 +2356,7 @@ var DefaultLoginPage = function (_a) {
|
|
|
2214
2356
|
console.log("Passkey created on client:", attestationResponse);
|
|
2215
2357
|
// 3. Send the response back to the server for verification
|
|
2216
2358
|
console.log("Sending attestation to server for verification...");
|
|
2217
|
-
return [4 /*yield*/,
|
|
2218
|
-
headers: APIHeaders,
|
|
2219
|
-
withCredentials: true, // credentials: 'include'
|
|
2220
|
-
})];
|
|
2359
|
+
return [4 /*yield*/, axiosInstance.post(MFAEndpoints.RegisterVerify + "?username=".concat(data.username), attestationResponse)];
|
|
2221
2360
|
case 3:
|
|
2222
2361
|
_a.sent();
|
|
2223
2362
|
toast.success("✅ Registration successful! Passkey created.");
|
|
@@ -2231,15 +2370,15 @@ var DefaultLoginPage = function (_a) {
|
|
|
2231
2370
|
}
|
|
2232
2371
|
});
|
|
2233
2372
|
}); };
|
|
2234
|
-
return (jsxRuntimeExports.jsxs("main", { className: "min-h-screen bg-gray-50", children: [jsxRuntimeExports.jsx(motion.div, { initial: { opacity: 0 }, animate: { opacity: 1 }, exit: { opacity: 0 }, transition: { duration: 0.5 }, children: jsxRuntimeExports.jsx("div", { className: "flex h-screen items-center justify-center", children: jsxRuntimeExports.jsxs(motion.div, { variants: cardVariants, initial: "hidden", animate: "visible", exit: "exit", className: "w-full max-w-md p-6 space-y-4 bg-gray-50 rounded-2xl shadow-2xl --dark:bg-gray-800", children: [jsxRuntimeExports.jsxs(CardHeader, { className: "text-center space-y-3", children: [jsxRuntimeExports.jsx("div", { className: "w-full flex items-center justify-center", children: jsxRuntimeExports.jsx("img", { src: NIBSSLogo, alt: "NIBSS Logo", width: 265, height: 265 }) }), jsxRuntimeExports.jsx(CardTitle, { className: "text-3xl font-bold --text-gray-900 --dark:text-white", children: "NIBSS CAMS" }), jsxRuntimeExports.jsx(CardTitle, { className: "text-gray-500 dark:text-gray-400 font-bold text-lg", children: "Centralized Authentication" })] }), jsxRuntimeExports.jsxs(CardAction, { className: "w-full flex flex-col items-center justify-center text-center text-gray-500 dark:text-gray-400 mb-
|
|
2373
|
+
return (jsxRuntimeExports.jsxs("main", { className: "min-h-screen bg-gray-50", children: [jsxRuntimeExports.jsx(motion.div, { initial: { opacity: 0 }, animate: { opacity: 1 }, exit: { opacity: 0 }, transition: { duration: 0.5 }, children: jsxRuntimeExports.jsx("div", { className: "flex h-screen items-center justify-center", children: jsxRuntimeExports.jsxs(motion.div, { variants: cardVariants, initial: "hidden", animate: "visible", exit: "exit", className: "w-full max-w-md p-6 space-y-4 bg-gray-50 rounded-2xl shadow-2xl --dark:bg-gray-800", children: [jsxRuntimeExports.jsxs(CardHeader, { className: "text-center space-y-3", children: [jsxRuntimeExports.jsx("div", { className: "w-full flex items-center justify-center", children: jsxRuntimeExports.jsx("img", { src: NIBSSLogo, alt: "NIBSS Logo", width: 265, height: 265 }) }), jsxRuntimeExports.jsx(CardTitle, { className: "text-3xl font-bold --text-gray-900 --dark:text-white", children: "NIBSS CAMS" }), jsxRuntimeExports.jsx(CardTitle, { className: "text-gray-500 dark:text-gray-400 font-bold text-lg", children: "Centralized Authentication" })] }), jsxRuntimeExports.jsxs(CardAction, { className: "w-full flex flex-col items-center justify-center text-center text-gray-500 dark:text-gray-400 mb-8", children: [jsxRuntimeExports.jsx("img", { src: AuthLogo, alt: "Auth Logo", width: 365, height: 365 }), "Use Below Identity Providers To Authenticate"] }), jsxRuntimeExports.jsxs("div", { className: "space-y-4", children: [jsxRuntimeExports.jsxs(Button
|
|
2235
2374
|
// variant="outline"
|
|
2236
2375
|
, {
|
|
2237
2376
|
// variant="outline"
|
|
2238
2377
|
className: "w-full flex items-center justify-center cursor-pointer bg-[#506f4a] hover:bg-[#506f4a] rounded-lg border border-transparent px-5 py-8 text-base font-medium transition-colors duration-250", onClick: handleMSALLogin, disabled: isLoading, children: [jsxRuntimeExports.jsx("img", { src: MicrosoftLogo, alt: "Microsoft Logo", width: 35, height: 35 }), jsxRuntimeExports.jsx("span", { className: "ml-2", children: isLoading ? "Logging in..." : "Sign in with Microsoft" })] }), useADLogin && (jsxRuntimeExports.jsxs(Button, { className: "w-full flex items-center justify-center cursor-pointer bg-[#506f4a] hover:bg-[#506f4a] rounded-lg border border-transparent px-5 py-8 text-base font-medium transition-colors duration-250", onClick: function () { return setShowADModal(true); }, disabled: isLoading, children: [jsxRuntimeExports.jsx(KeyIcon, { className: "text-[#506f4a]", size: 64 }), jsxRuntimeExports.jsx("span", { children: isLoading
|
|
2239
2378
|
? "Logging in..."
|
|
2240
|
-
: "Sign in with ActiveDirectory" })] })), usePassKey && (jsxRuntimeExports.jsxs(Button, { className: "w-full flex items-center justify-center cursor-pointer bg-[#506f4a] hover:bg-[#506f4a] rounded-lg border border-transparent px-5 py-8 text-base font-medium transition-colors duration-250", onClick: function () { return handleRegister(PassKeysRegisterProps); }, disabled: isLoading, children: [jsxRuntimeExports.jsx(KeyIcon, { className: "text-[#506f4a]", size: 64 }), jsxRuntimeExports.jsx("span", { children: "Create a Passkey" })] }))] }), jsxRuntimeExports.jsxs(CardFooter, { className: "flex items-center justify-center mt-6 space-x-2 text-gray-400 text-sm", children: [jsxRuntimeExports.jsx(ShieldCheck, { className: "w-4 h-4 text-[#506f4a] pulse-glow" }), jsxRuntimeExports.jsx("span", { children: "Powered By NIBSS" })] })] }) }) }, "landing"), jsxRuntimeExports.jsx(ADLoginModal, { open: showADModal, onOpenChange: setShowADModal, isLoading: isCredAuthLoading, setIsLoading: setIsCredAuthLoading, onLogin: function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
|
|
2379
|
+
: "Sign in with ActiveDirectory" })] })), usePassKey && (jsxRuntimeExports.jsxs(Button, { className: "w-full flex items-center justify-center cursor-pointer bg-[#506f4a] hover:bg-[#506f4a] rounded-lg border border-transparent px-5 py-8 text-base font-medium transition-colors duration-250", onClick: function () { return handleRegister(PassKeysRegisterProps); }, disabled: isLoading, children: [jsxRuntimeExports.jsx(KeyIcon, { className: "text-[#506f4a]", size: 64 }), jsxRuntimeExports.jsx("span", { children: "Create a Passkey" })] }))] }), jsxRuntimeExports.jsxs(CardFooter, { className: "flex items-center justify-center mt-6 space-x-2 text-gray-400 text-sm", children: [jsxRuntimeExports.jsx(ShieldCheck, { className: "w-4 h-4 text-[#506f4a] pulse-glow" }), jsxRuntimeExports.jsx("span", { children: "Powered By NIBSS" })] })] }) }) }, "landing"), jsxRuntimeExports.jsx(ADLoginModal, { open: showADModal, onOpenChange: setShowADModal, isLoading: isCredAuthLoading, setIsLoading: setIsCredAuthLoading, onLogin: function (_a) { return __awaiter$1(void 0, [_a], void 0, function (_b) {
|
|
2241
2380
|
var username = _b.username, password = _b.password, MFACode = _b.MFACode;
|
|
2242
|
-
return __generator(this, function (_c) {
|
|
2381
|
+
return __generator$1(this, function (_c) {
|
|
2243
2382
|
// Implement your AD login logic here
|
|
2244
2383
|
console.log("AD Login:", { username: username, password: password, MFACode: MFACode });
|
|
2245
2384
|
// Example: await adLoginService(username, password, mfaCode);
|
|
@@ -2280,8 +2419,8 @@ var MFAGate = function (_a) {
|
|
|
2280
2419
|
if (!success)
|
|
2281
2420
|
Logger.error("MFA authentication failed");
|
|
2282
2421
|
}, []);
|
|
2283
|
-
var handleAuthFailed = useCallback(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
2284
|
-
return __generator(this, function (_a) {
|
|
2422
|
+
var handleAuthFailed = useCallback(function () { return __awaiter$1(void 0, void 0, void 0, function () {
|
|
2423
|
+
return __generator$1(this, function (_a) {
|
|
2285
2424
|
switch (_a.label) {
|
|
2286
2425
|
case 0: return [4 /*yield*/, context.logout()];
|
|
2287
2426
|
case 1:
|
|
@@ -2290,7 +2429,6 @@ var MFAGate = function (_a) {
|
|
|
2290
2429
|
}
|
|
2291
2430
|
});
|
|
2292
2431
|
}); }, [context.logout]);
|
|
2293
|
-
Logger.debug("MFA Endpoint >>>", { MFAEndpoints: MFAEndpoints });
|
|
2294
2432
|
if (useADLogin && !CredentialsAuthEndpoint)
|
|
2295
2433
|
return jsxRuntimeExports.jsx(ErrorFallback, { message: "Invalid AD Login Configuration." });
|
|
2296
2434
|
if (!validatedMFAEndpoints)
|