@nibssplc/cams-sdk-react 1.0.0-rc.4 → 1.0.0-rc.41
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 +292 -126
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.esm.js +292 -126
- 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,163 @@ 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
|
+
// Run immediately and synchronously
|
|
26
|
+
// Ensure crypto object exists
|
|
27
|
+
if (!window.crypto) {
|
|
28
|
+
window.crypto = {};
|
|
29
|
+
}
|
|
30
|
+
// Polyfill getRandomValues
|
|
31
|
+
if (!window.crypto.getRandomValues) {
|
|
32
|
+
window.crypto.getRandomValues = function (array) {
|
|
33
|
+
var bytes = new Uint8Array(array.buffer, array.byteOffset, array.byteLength);
|
|
34
|
+
for (var i = 0; i < bytes.length; i++) {
|
|
35
|
+
bytes[i] = Math.floor(Math.random() * 256);
|
|
36
|
+
}
|
|
37
|
+
return array;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
var sha256_1 = function (data) { return __awaiter(void 0, void 0, void 0, function () {
|
|
41
|
+
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;
|
|
42
|
+
return __generator(this, function (_a) {
|
|
43
|
+
toUint8 = function (src) {
|
|
44
|
+
if (src instanceof ArrayBuffer)
|
|
45
|
+
return new Uint8Array(src);
|
|
46
|
+
if (ArrayBuffer.isView(src)) {
|
|
47
|
+
var view = src;
|
|
48
|
+
return new Uint8Array(view.buffer, view.byteOffset || 0, view.byteLength);
|
|
49
|
+
}
|
|
50
|
+
throw new TypeError("Unsupported BufferSource");
|
|
51
|
+
};
|
|
52
|
+
bytes = toUint8(data);
|
|
53
|
+
hash = new Uint32Array(8);
|
|
54
|
+
k = new Uint32Array([
|
|
55
|
+
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1,
|
|
56
|
+
0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
|
|
57
|
+
0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786,
|
|
58
|
+
0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
|
|
59
|
+
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147,
|
|
60
|
+
0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
|
|
61
|
+
0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 0xa2bfe8a1, 0xa81a664b,
|
|
62
|
+
0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
|
|
63
|
+
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a,
|
|
64
|
+
0x5b9cca4f, 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
|
|
65
|
+
0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,
|
|
66
|
+
]);
|
|
67
|
+
hash[0] = 0x6a09e667;
|
|
68
|
+
hash[1] = 0xbb67ae85;
|
|
69
|
+
hash[2] = 0x3c6ef372;
|
|
70
|
+
hash[3] = 0xa54ff53a;
|
|
71
|
+
hash[4] = 0x510e527f;
|
|
72
|
+
hash[5] = 0x9b05688c;
|
|
73
|
+
hash[6] = 0x1f83d9ab;
|
|
74
|
+
hash[7] = 0x5be0cd19;
|
|
75
|
+
ml = bytes.length * 8;
|
|
76
|
+
msg = new Uint8Array(bytes.length + 64 + ((64 - ((bytes.length + 9) % 64)) % 64));
|
|
77
|
+
msg.set(bytes);
|
|
78
|
+
msg[bytes.length] = 0x80;
|
|
79
|
+
dv = new DataView(msg.buffer);
|
|
80
|
+
high = Math.floor(ml / 0x100000000);
|
|
81
|
+
low = ml >>> 0;
|
|
82
|
+
dv.setUint32(msg.length - 8, high, false);
|
|
83
|
+
dv.setUint32(msg.length - 4, low, false);
|
|
84
|
+
for (i = 0; i < msg.length; i += 64) {
|
|
85
|
+
w = new Uint32Array(64);
|
|
86
|
+
for (j = 0; j < 16; j++)
|
|
87
|
+
w[j] = new DataView(msg.buffer).getUint32(i + j * 4, false);
|
|
88
|
+
for (j = 16; j < 64; j++) {
|
|
89
|
+
s0 = ((w[j - 15] >>> 7) | (w[j - 15] << 25)) ^
|
|
90
|
+
((w[j - 15] >>> 18) | (w[j - 15] << 14)) ^
|
|
91
|
+
(w[j - 15] >>> 3);
|
|
92
|
+
s1 = ((w[j - 2] >>> 17) | (w[j - 2] << 15)) ^
|
|
93
|
+
((w[j - 2] >>> 19) | (w[j - 2] << 13)) ^
|
|
94
|
+
(w[j - 2] >>> 10);
|
|
95
|
+
w[j] = (w[j - 16] + s0 + w[j - 7] + s1) >>> 0;
|
|
96
|
+
}
|
|
97
|
+
a = hash[0], b = hash[1], c = hash[2], d = hash[3], e = hash[4], f = hash[5], g = hash[6], h = hash[7];
|
|
98
|
+
for (j = 0; j < 64; j++) {
|
|
99
|
+
S1 = ((e >>> 6) | (e << 26)) ^
|
|
100
|
+
((e >>> 11) | (e << 21)) ^
|
|
101
|
+
((e >>> 25) | (e << 7));
|
|
102
|
+
ch = (e & f) ^ (~e & g);
|
|
103
|
+
temp1 = (h + S1 + ch + k[j] + w[j]) >>> 0;
|
|
104
|
+
S0 = ((a >>> 2) | (a << 30)) ^
|
|
105
|
+
((a >>> 13) | (a << 19)) ^
|
|
106
|
+
((a >>> 22) | (a << 10));
|
|
107
|
+
maj = (a & b) ^ (a & c) ^ (b & c);
|
|
108
|
+
temp2 = (S0 + maj) >>> 0;
|
|
109
|
+
h = g;
|
|
110
|
+
g = f;
|
|
111
|
+
f = e;
|
|
112
|
+
e = (d + temp1) >>> 0;
|
|
113
|
+
d = c;
|
|
114
|
+
c = b;
|
|
115
|
+
b = a;
|
|
116
|
+
a = (temp1 + temp2) >>> 0;
|
|
117
|
+
}
|
|
118
|
+
hash[0] = (hash[0] + a) >>> 0;
|
|
119
|
+
hash[1] = (hash[1] + b) >>> 0;
|
|
120
|
+
hash[2] = (hash[2] + c) >>> 0;
|
|
121
|
+
hash[3] = (hash[3] + d) >>> 0;
|
|
122
|
+
hash[4] = (hash[4] + e) >>> 0;
|
|
123
|
+
hash[5] = (hash[5] + f) >>> 0;
|
|
124
|
+
hash[6] = (hash[6] + g) >>> 0;
|
|
125
|
+
hash[7] = (hash[7] + h) >>> 0;
|
|
126
|
+
}
|
|
127
|
+
result = new Uint8Array(32);
|
|
128
|
+
for (i = 0; i < 8; i++)
|
|
129
|
+
new DataView(result.buffer).setUint32(i * 4, hash[i], false);
|
|
130
|
+
return [2 /*return*/, result.buffer];
|
|
131
|
+
});
|
|
132
|
+
}); };
|
|
133
|
+
// Store reference to original subtle if it exists
|
|
134
|
+
var originalSubtle_1 = window.crypto.subtle;
|
|
135
|
+
// Create the polyfilled subtle object
|
|
136
|
+
var polyfillSubtle = {
|
|
137
|
+
digest: function (algorithm, data) { return __awaiter(void 0, void 0, void 0, function () {
|
|
138
|
+
var alg;
|
|
139
|
+
return __generator(this, function (_a) {
|
|
140
|
+
alg = typeof algorithm === "string"
|
|
141
|
+
? algorithm
|
|
142
|
+
: algorithm.name;
|
|
143
|
+
if (alg === "SHA-256")
|
|
144
|
+
return [2 /*return*/, sha256_1(data)];
|
|
145
|
+
if (originalSubtle_1 === null || originalSubtle_1 === void 0 ? void 0 : originalSubtle_1.digest)
|
|
146
|
+
return [2 /*return*/, originalSubtle_1.digest(algorithm, data)];
|
|
147
|
+
throw new Error("Unsupported algorithm: ".concat(alg));
|
|
148
|
+
});
|
|
149
|
+
}); },
|
|
150
|
+
};
|
|
151
|
+
// Try to define the property, fallback to assignment if needed
|
|
152
|
+
try {
|
|
153
|
+
Object.defineProperty(window.crypto, "subtle", {
|
|
154
|
+
configurable: true,
|
|
155
|
+
enumerable: true,
|
|
156
|
+
writable: true,
|
|
157
|
+
value: polyfillSubtle,
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
catch (_a) {
|
|
161
|
+
// Some environments prevent redefining built-ins
|
|
162
|
+
window.crypto.subtle = polyfillSubtle;
|
|
163
|
+
}
|
|
164
|
+
// Polyfill randomUUID
|
|
165
|
+
if (!window.crypto.randomUUID) {
|
|
166
|
+
window.crypto.randomUUID =
|
|
167
|
+
function () {
|
|
168
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
|
|
169
|
+
var r = (Math.random() * 16) | 0;
|
|
170
|
+
var v = c === "x" ? r : (r & 0x3) | 0x8;
|
|
171
|
+
return v.toString(16);
|
|
172
|
+
});
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
// Log success for debugging
|
|
176
|
+
console.log("Crypto polyfill loaded successfully");
|
|
177
|
+
}
|
|
21
178
|
|
|
22
179
|
/******************************************************************************
|
|
23
180
|
Copyright (c) Microsoft Corporation.
|
|
@@ -59,7 +216,7 @@ function __rest(s, e) {
|
|
|
59
216
|
return t;
|
|
60
217
|
}
|
|
61
218
|
|
|
62
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
219
|
+
function __awaiter$1(thisArg, _arguments, P, generator) {
|
|
63
220
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
64
221
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
65
222
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
@@ -69,7 +226,7 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
69
226
|
});
|
|
70
227
|
}
|
|
71
228
|
|
|
72
|
-
function __generator(thisArg, body) {
|
|
229
|
+
function __generator$1(thisArg, body) {
|
|
73
230
|
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
231
|
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
75
232
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
@@ -166,10 +323,10 @@ function useCAMSAuth(options) {
|
|
|
166
323
|
}
|
|
167
324
|
}
|
|
168
325
|
}, [options.storageKey]);
|
|
169
|
-
var login = useCallback(function (config) { return __awaiter(_this, void 0, void 0, function () {
|
|
326
|
+
var login = useCallback(function (config) { return __awaiter$1(_this, void 0, void 0, function () {
|
|
170
327
|
var loginConfig, userProfile, err_1, e, isPopupClosedError, restoredToken, userProfile;
|
|
171
328
|
var _a, _b, _c;
|
|
172
|
-
return __generator(this, function (_d) {
|
|
329
|
+
return __generator$1(this, function (_d) {
|
|
173
330
|
switch (_d.label) {
|
|
174
331
|
case 0:
|
|
175
332
|
if (!sessionManagerRef.current)
|
|
@@ -217,8 +374,8 @@ function useCAMSAuth(options) {
|
|
|
217
374
|
}
|
|
218
375
|
});
|
|
219
376
|
}); }, [options.idleTimeout]);
|
|
220
|
-
var logout = useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
221
|
-
return __generator(this, function (_a) {
|
|
377
|
+
var logout = useCallback(function () { return __awaiter$1(_this, void 0, void 0, function () {
|
|
378
|
+
return __generator$1(this, function (_a) {
|
|
222
379
|
switch (_a.label) {
|
|
223
380
|
case 0:
|
|
224
381
|
if (!sessionManagerRef.current)
|
|
@@ -248,11 +405,13 @@ function useCAMSAuth(options) {
|
|
|
248
405
|
};
|
|
249
406
|
}
|
|
250
407
|
|
|
251
|
-
var setCookie
|
|
408
|
+
var setCookie = function (name, value, days) {
|
|
409
|
+
if (days === void 0) { days = 1; }
|
|
252
410
|
var expires = new Date(Date.now() + days * 24 * 60 * 60 * 1000).toUTCString();
|
|
411
|
+
console.log("Auth Cookie Expires >>>", { name: name, value: value, expires: expires });
|
|
253
412
|
document.cookie = "".concat(name, "=").concat(encodeURIComponent(value), "; expires=").concat(expires, "; path=/; samesite=Lax");
|
|
254
413
|
};
|
|
255
|
-
var getCookie
|
|
414
|
+
var getCookie = function (name) {
|
|
256
415
|
var _a;
|
|
257
416
|
return ((_a = document.cookie
|
|
258
417
|
.split("; ")
|
|
@@ -263,23 +422,24 @@ var getCookie$1 = function (name) {
|
|
|
263
422
|
.split("=")[1])
|
|
264
423
|
: null;
|
|
265
424
|
};
|
|
266
|
-
var deleteCookie
|
|
425
|
+
var deleteCookie = function (name) {
|
|
267
426
|
document.cookie = name + "=; Max-Age=-99999999; path=/";
|
|
268
427
|
};
|
|
269
428
|
|
|
270
429
|
function useCAMSMSALAuth(options) {
|
|
271
430
|
var _this = this;
|
|
272
|
-
var
|
|
273
|
-
var
|
|
431
|
+
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;
|
|
432
|
+
var storageKey = optStorageKey || "CAMS-MSAL-AUTH-SDK";
|
|
433
|
+
var _b = useMsal(), instance = _b.instance, inProgress = _b.inProgress, accounts = _b.accounts;
|
|
274
434
|
var account = useAccount(accounts[0] || {});
|
|
275
|
-
var
|
|
276
|
-
var
|
|
277
|
-
var
|
|
278
|
-
var
|
|
279
|
-
var
|
|
435
|
+
var _c = useState(null), error = _c[0], setError = _c[1];
|
|
436
|
+
var _d = useState(""), idToken = _d[0], setIdToken = _d[1];
|
|
437
|
+
var _e = useState(""), accessToken = _e[0], setAccessToken = _e[1];
|
|
438
|
+
var _f = useState(null), mfaAuthenticator = _f[0], setMfaAuthenticator = _f[1];
|
|
439
|
+
var _g = useState(false), requiresMFA = _g[0], setRequiresMFA = _g[1];
|
|
280
440
|
var isLoading = inProgress !== InteractionStatus.None;
|
|
281
441
|
var isAuthenticated = !!account && !!accessToken && !requiresMFA;
|
|
282
|
-
var scopes =
|
|
442
|
+
var scopes = optScopes || ["openid", "profile", "email"];
|
|
283
443
|
var isTokenValid = function (token) {
|
|
284
444
|
try {
|
|
285
445
|
var payload = JSON.parse(atob(token.split(".")[1]));
|
|
@@ -303,15 +463,14 @@ function useCAMSMSALAuth(options) {
|
|
|
303
463
|
var mfaConfig = {
|
|
304
464
|
accessToken: accessToken_1,
|
|
305
465
|
idToken: idToken_1,
|
|
306
|
-
appCode:
|
|
466
|
+
appCode: appCode,
|
|
307
467
|
provider: "MSAL",
|
|
308
|
-
apiEndpoint:
|
|
468
|
+
apiEndpoint: MFAEndpoint,
|
|
309
469
|
};
|
|
310
470
|
var authenticator = new CAMSMFAAuthenticator(mfaConfig);
|
|
311
471
|
setMfaAuthenticator(authenticator);
|
|
312
472
|
setRequiresMFA(true);
|
|
313
473
|
}
|
|
314
|
-
Logger.debug("App Code", { ">>>": options.appCode });
|
|
315
474
|
}
|
|
316
475
|
else {
|
|
317
476
|
localStorage.removeItem(storageKey);
|
|
@@ -353,22 +512,26 @@ function useCAMSMSALAuth(options) {
|
|
|
353
512
|
// };
|
|
354
513
|
// handleRedirect();
|
|
355
514
|
// }, []);
|
|
356
|
-
var login = useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
515
|
+
var login = useCallback(function () { return __awaiter$1(_this, void 0, void 0, function () {
|
|
357
516
|
var response, mfaConfig, authenticator, err_1, camsError_1, camsError;
|
|
358
|
-
var _a
|
|
359
|
-
return __generator(this, function (
|
|
360
|
-
switch (
|
|
517
|
+
var _a;
|
|
518
|
+
return __generator$1(this, function (_b) {
|
|
519
|
+
switch (_b.label) {
|
|
361
520
|
case 0:
|
|
521
|
+
if (inProgress !== InteractionStatus.None) {
|
|
522
|
+
Logger.warn("Authentication already in progress, ignoring duplicate call");
|
|
523
|
+
return [2 /*return*/];
|
|
524
|
+
}
|
|
362
525
|
setError(null);
|
|
363
|
-
|
|
526
|
+
_b.label = 1;
|
|
364
527
|
case 1:
|
|
365
|
-
|
|
528
|
+
_b.trys.push([1, 3, , 4]);
|
|
366
529
|
return [4 /*yield*/, instance.loginPopup({
|
|
367
530
|
scopes: scopes,
|
|
368
|
-
prompt:
|
|
531
|
+
prompt: prompt || "login",
|
|
369
532
|
})];
|
|
370
533
|
case 2:
|
|
371
|
-
response =
|
|
534
|
+
response = _b.sent();
|
|
372
535
|
console.log("Login Token response:", {
|
|
373
536
|
accessToken: response.accessToken,
|
|
374
537
|
idToken: response.idToken,
|
|
@@ -378,9 +541,9 @@ function useCAMSMSALAuth(options) {
|
|
|
378
541
|
mfaConfig = {
|
|
379
542
|
accessToken: response.accessToken,
|
|
380
543
|
idToken: response.idToken,
|
|
381
|
-
appCode:
|
|
544
|
+
appCode: appCode,
|
|
382
545
|
provider: "MSAL",
|
|
383
|
-
apiEndpoint:
|
|
546
|
+
apiEndpoint: MFAEndpoint,
|
|
384
547
|
};
|
|
385
548
|
authenticator = new CAMSMFAAuthenticator(mfaConfig);
|
|
386
549
|
setMfaAuthenticator(authenticator);
|
|
@@ -394,10 +557,15 @@ function useCAMSMSALAuth(options) {
|
|
|
394
557
|
idToken: response.idToken,
|
|
395
558
|
}));
|
|
396
559
|
}
|
|
397
|
-
|
|
560
|
+
onAuthSuccess === null || onAuthSuccess === void 0 ? void 0 : onAuthSuccess(response.accessToken);
|
|
398
561
|
return [3 /*break*/, 4];
|
|
399
562
|
case 3:
|
|
400
|
-
err_1 =
|
|
563
|
+
err_1 = _b.sent();
|
|
564
|
+
// Handle interaction_in_progress error
|
|
565
|
+
if (err_1.errorCode === "interaction_in_progress") {
|
|
566
|
+
Logger.warn("Interaction already in progress, please wait");
|
|
567
|
+
return [2 /*return*/];
|
|
568
|
+
}
|
|
401
569
|
// Handle user cancellation gracefully
|
|
402
570
|
if (err_1.errorCode === "user_cancelled") {
|
|
403
571
|
Logger.error("User cancelled login");
|
|
@@ -406,22 +574,22 @@ function useCAMSMSALAuth(options) {
|
|
|
406
574
|
}
|
|
407
575
|
// If popup is blocked
|
|
408
576
|
if (err_1.errorCode === "popup_window_error" ||
|
|
409
|
-
((
|
|
577
|
+
((_a = err_1.message) === null || _a === void 0 ? void 0 : _a.includes("popup"))) {
|
|
410
578
|
camsError_1 = new CAMSError(CAMSErrorType.POPUP_BLOCKED, "Popup blocked by browser. Please allow popups and try again.");
|
|
411
579
|
setError(camsError_1);
|
|
412
|
-
|
|
580
|
+
onAuthError === null || onAuthError === void 0 ? void 0 : onAuthError(camsError_1);
|
|
413
581
|
return [2 /*return*/];
|
|
414
582
|
}
|
|
415
583
|
camsError = new CAMSError(CAMSErrorType.API_VALIDATION_ERROR, "Login failed: " + err_1.message || err_1);
|
|
416
584
|
setError(camsError);
|
|
417
|
-
|
|
585
|
+
onAuthError === null || onAuthError === void 0 ? void 0 : onAuthError(camsError);
|
|
418
586
|
return [3 /*break*/, 4];
|
|
419
587
|
case 4: return [2 /*return*/];
|
|
420
588
|
}
|
|
421
589
|
});
|
|
422
|
-
}); }, [instance, scopes,
|
|
423
|
-
var completeMFA = useCallback(function (data) { return __awaiter(_this, void 0, void 0, function () {
|
|
424
|
-
return __generator(this, function (_a) {
|
|
590
|
+
}); }, [instance, scopes, prompt, appCode, MFAEndpoint, onAuthSuccess, onAuthError, storageKey, inProgress]);
|
|
591
|
+
var completeMFA = useCallback(function (data) { return __awaiter$1(_this, void 0, void 0, function () {
|
|
592
|
+
return __generator$1(this, function (_a) {
|
|
425
593
|
if (!mfaAuthenticator) {
|
|
426
594
|
throw new CAMSError(CAMSErrorType.API_VALIDATION_ERROR, "MFA Authenticator not initialized");
|
|
427
595
|
}
|
|
@@ -435,7 +603,7 @@ function useCAMSMSALAuth(options) {
|
|
|
435
603
|
accessToken: accessToken,
|
|
436
604
|
idToken: idToken,
|
|
437
605
|
}));
|
|
438
|
-
setCookie
|
|
606
|
+
setCookie("CAMS-MSAL-AUTH-SDK-PROFILE", JSON.stringify({ type: "AUTH_SUCCESS", userProfile: __assign({}, data) }), activeCookiePeriod);
|
|
439
607
|
setRequiresMFA(false);
|
|
440
608
|
// Set requiresMFA to false after storage update
|
|
441
609
|
Logger.debug("MFA completed successfully, storage updated", {
|
|
@@ -454,9 +622,9 @@ function useCAMSMSALAuth(options) {
|
|
|
454
622
|
}
|
|
455
623
|
return [2 /*return*/];
|
|
456
624
|
});
|
|
457
|
-
}); }, [mfaAuthenticator, accessToken, idToken, storageKey]);
|
|
458
|
-
var sendEmailOTP = useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
459
|
-
return __generator(this, function (_a) {
|
|
625
|
+
}); }, [mfaAuthenticator, accessToken, idToken, storageKey, activeCookiePeriod]);
|
|
626
|
+
var sendEmailOTP = useCallback(function () { return __awaiter$1(_this, void 0, void 0, function () {
|
|
627
|
+
return __generator$1(this, function (_a) {
|
|
460
628
|
switch (_a.label) {
|
|
461
629
|
case 0:
|
|
462
630
|
if (!mfaAuthenticator) {
|
|
@@ -467,9 +635,9 @@ function useCAMSMSALAuth(options) {
|
|
|
467
635
|
}
|
|
468
636
|
});
|
|
469
637
|
}); }, [mfaAuthenticator]);
|
|
470
|
-
var logout = useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
638
|
+
var logout = useCallback(function () { return __awaiter$1(_this, void 0, void 0, function () {
|
|
471
639
|
var err_2, camsError;
|
|
472
|
-
return __generator(this, function (_a) {
|
|
640
|
+
return __generator$1(this, function (_a) {
|
|
473
641
|
switch (_a.label) {
|
|
474
642
|
case 0:
|
|
475
643
|
_a.trys.push([0, 2, , 3]);
|
|
@@ -505,12 +673,13 @@ function useCAMSMSALAuth(options) {
|
|
|
505
673
|
error: error,
|
|
506
674
|
idToken: idToken,
|
|
507
675
|
accessToken: accessToken,
|
|
508
|
-
appCode:
|
|
676
|
+
appCode: appCode,
|
|
509
677
|
mfaAuthenticator: mfaAuthenticator,
|
|
510
678
|
requiresMFA: requiresMFA,
|
|
511
679
|
completeMFA: completeMFA,
|
|
512
680
|
sendEmailOTP: sendEmailOTP,
|
|
513
681
|
setRequiresMFA: setRequiresMFA,
|
|
682
|
+
activeCookiePeriod: activeCookiePeriod,
|
|
514
683
|
};
|
|
515
684
|
}
|
|
516
685
|
|
|
@@ -553,10 +722,10 @@ function arrayBufferToBase64url(buffer) {
|
|
|
553
722
|
* @returns A promise that resolves to a JSON-serializable representation of the PublicKeyCredential.
|
|
554
723
|
*/
|
|
555
724
|
function register(options) {
|
|
556
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
725
|
+
return __awaiter$1(this, void 0, void 0, function () {
|
|
557
726
|
var createOptions, credential, publicKeyCredential, attestationResponse, transports, err_1;
|
|
558
727
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
559
|
-
return __generator(this, function (_k) {
|
|
728
|
+
return __generator$1(this, function (_k) {
|
|
560
729
|
switch (_k.label) {
|
|
561
730
|
case 0:
|
|
562
731
|
_k.trys.push([0, 2, , 3]);
|
|
@@ -614,10 +783,10 @@ function register(options) {
|
|
|
614
783
|
* @returns A promise that resolves to a JSON-serializable representation of the PublicKeyCredential.
|
|
615
784
|
*/
|
|
616
785
|
function authenticate(options) {
|
|
617
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
786
|
+
return __awaiter$1(this, void 0, void 0, function () {
|
|
618
787
|
var getOptions, credential, publicKeyCredential, assertionResponse;
|
|
619
788
|
var _a;
|
|
620
|
-
return __generator(this, function (_b) {
|
|
789
|
+
return __generator$1(this, function (_b) {
|
|
621
790
|
switch (_b.label) {
|
|
622
791
|
case 0:
|
|
623
792
|
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) })); }) });
|
|
@@ -1103,24 +1272,6 @@ function ProtectedRoute(_a) {
|
|
|
1103
1272
|
}
|
|
1104
1273
|
|
|
1105
1274
|
var CAMSMSALContext = createContext(null);
|
|
1106
|
-
var setCookie = function (name, value, days) {
|
|
1107
|
-
var expires = new Date(Date.now() + days * 864e5).toUTCString();
|
|
1108
|
-
document.cookie = "".concat(name, "=").concat(encodeURIComponent(value), "; expires=").concat(expires, "; path=/; samesite=Lax");
|
|
1109
|
-
};
|
|
1110
|
-
var getCookie = function (name) {
|
|
1111
|
-
var _a;
|
|
1112
|
-
return ((_a = document.cookie
|
|
1113
|
-
.split("; ")
|
|
1114
|
-
.find(function (row) { return row.startsWith(name + "="); })) === null || _a === void 0 ? void 0 : _a.split("=")[1])
|
|
1115
|
-
? decodeURIComponent(document.cookie
|
|
1116
|
-
.split("; ")
|
|
1117
|
-
.find(function (row) { return row.startsWith(name + "="); })
|
|
1118
|
-
.split("=")[1])
|
|
1119
|
-
: null;
|
|
1120
|
-
};
|
|
1121
|
-
var deleteCookie = function (name) {
|
|
1122
|
-
document.cookie = name + "=; Max-Age=-99999999; path=/";
|
|
1123
|
-
};
|
|
1124
1275
|
var isTokenValid = function (token) {
|
|
1125
1276
|
try {
|
|
1126
1277
|
var payload = JSON.parse(atob(token.split(".")[1]));
|
|
@@ -1169,7 +1320,7 @@ function CAMSMSALProviderInner(_a) {
|
|
|
1169
1320
|
localStorage.setItem(auth.storageKey, JSON.stringify({
|
|
1170
1321
|
accessToken: auth.accessToken,
|
|
1171
1322
|
idToken: auth.idToken,
|
|
1172
|
-
appCode: auth.appCode
|
|
1323
|
+
appCode: auth.appCode,
|
|
1173
1324
|
}));
|
|
1174
1325
|
}
|
|
1175
1326
|
}, [auth.accessToken, auth.idToken, auth.storageKey]);
|
|
@@ -1185,8 +1336,8 @@ function CAMSMSALProviderInner(_a) {
|
|
|
1185
1336
|
}
|
|
1186
1337
|
}, [userProfile, profileStorageKey]);
|
|
1187
1338
|
// Enhanced logout that also clears profile
|
|
1188
|
-
var enhancedLogout = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
1189
|
-
return __generator(this, function (_a) {
|
|
1339
|
+
var enhancedLogout = function () { return __awaiter$1(_this, void 0, void 0, function () {
|
|
1340
|
+
return __generator$1(this, function (_a) {
|
|
1190
1341
|
switch (_a.label) {
|
|
1191
1342
|
case 0: return [4 /*yield*/, auth.logout()];
|
|
1192
1343
|
case 1:
|
|
@@ -1203,7 +1354,12 @@ function CAMSMSALProviderInner(_a) {
|
|
|
1203
1354
|
return (jsxRuntimeExports.jsx(CAMSMSALContext.Provider, { value: value, children: children }));
|
|
1204
1355
|
}
|
|
1205
1356
|
function CAMSMSALProvider(props) {
|
|
1357
|
+
var _a;
|
|
1206
1358
|
var msalConfig = props.msalConfig, msalInstance = props.msalInstance;
|
|
1359
|
+
// Ensure crypto is available before creating MSAL instance
|
|
1360
|
+
if (typeof window !== "undefined" && !((_a = window.crypto) === null || _a === void 0 ? void 0 : _a.subtle)) {
|
|
1361
|
+
throw new Error("Crypto API not available. Polyfill failed to load.");
|
|
1362
|
+
}
|
|
1207
1363
|
var instance = msalInstance || new PublicClientApplication(msalConfig);
|
|
1208
1364
|
return (jsxRuntimeExports.jsx(MsalProvider, { instance: instance, children: jsxRuntimeExports.jsx(CAMSMSALProviderInner, __assign({}, props)) }));
|
|
1209
1365
|
}
|
|
@@ -1253,7 +1409,7 @@ function CAMSProviderCore(props) {
|
|
|
1253
1409
|
if (typeof window === "undefined")
|
|
1254
1410
|
return null;
|
|
1255
1411
|
try {
|
|
1256
|
-
var storedProfile = getCookie
|
|
1412
|
+
var storedProfile = getCookie(profileStorageKey);
|
|
1257
1413
|
return storedProfile ? JSON.parse(storedProfile) : null;
|
|
1258
1414
|
}
|
|
1259
1415
|
catch (_a) {
|
|
@@ -1263,7 +1419,7 @@ function CAMSProviderCore(props) {
|
|
|
1263
1419
|
var _a = useState(getInitialProfile), userProfile = _a[0], setUserProfile = _a[1];
|
|
1264
1420
|
useEffect(function () {
|
|
1265
1421
|
if (typeof window !== "undefined") {
|
|
1266
|
-
var storedProfile = getCookie
|
|
1422
|
+
var storedProfile = getCookie(profileStorageKey);
|
|
1267
1423
|
if (storedProfile) {
|
|
1268
1424
|
try {
|
|
1269
1425
|
setUserProfile(JSON.parse(storedProfile));
|
|
@@ -1275,22 +1431,22 @@ function CAMSProviderCore(props) {
|
|
|
1275
1431
|
useEffect(function () {
|
|
1276
1432
|
if (typeof window !== "undefined") {
|
|
1277
1433
|
if (userProfile) {
|
|
1278
|
-
setCookie
|
|
1434
|
+
setCookie(profileStorageKey, JSON.stringify(userProfile), 1);
|
|
1279
1435
|
}
|
|
1280
1436
|
else {
|
|
1281
|
-
deleteCookie
|
|
1437
|
+
deleteCookie(profileStorageKey);
|
|
1282
1438
|
}
|
|
1283
1439
|
}
|
|
1284
1440
|
}, [userProfile, profileStorageKey]);
|
|
1285
|
-
var enhancedLogout = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
1286
|
-
return __generator(this, function (_a) {
|
|
1441
|
+
var enhancedLogout = function () { return __awaiter$1(_this, void 0, void 0, function () {
|
|
1442
|
+
return __generator$1(this, function (_a) {
|
|
1287
1443
|
switch (_a.label) {
|
|
1288
1444
|
case 0: return [4 /*yield*/, auth.logout()];
|
|
1289
1445
|
case 1:
|
|
1290
1446
|
_a.sent();
|
|
1291
1447
|
setUserProfile(null);
|
|
1292
1448
|
if (typeof window !== "undefined") {
|
|
1293
|
-
deleteCookie
|
|
1449
|
+
deleteCookie(profileStorageKey);
|
|
1294
1450
|
}
|
|
1295
1451
|
return [2 /*return*/];
|
|
1296
1452
|
}
|
|
@@ -1326,7 +1482,8 @@ function CAMSProviderCore(props) {
|
|
|
1326
1482
|
userProfile,
|
|
1327
1483
|
]);
|
|
1328
1484
|
var value = useMemo(function () {
|
|
1329
|
-
|
|
1485
|
+
auth.logout; var authRest = __rest(auth, ["logout"]);
|
|
1486
|
+
return __assign(__assign({}, authRest), { logout: enhancedLogout, userProfile: userProfile, setUserProfile: setUserProfile, authMode: mode });
|
|
1330
1487
|
}, [auth, userProfile, mode]);
|
|
1331
1488
|
return jsxRuntimeExports.jsx(CAMSContext.Provider, { value: value, children: children });
|
|
1332
1489
|
}
|
|
@@ -1334,7 +1491,7 @@ function UnifiedCAMSProvider(props) {
|
|
|
1334
1491
|
// Validate appCode is a valid GUID
|
|
1335
1492
|
var appCodeValidation = GuidSchema.safeParse(props.appCode);
|
|
1336
1493
|
if (!appCodeValidation.success) {
|
|
1337
|
-
throw new Error("Invalid
|
|
1494
|
+
throw new Error("Invalid CAS APP CODE: ".concat(appCodeValidation.error.issues[0].message));
|
|
1338
1495
|
}
|
|
1339
1496
|
if (props.mode === "MSAL") {
|
|
1340
1497
|
var msalConfig = props.msalConfig, msalInstance = props.msalInstance;
|
|
@@ -1702,7 +1859,7 @@ styleInject(css_248z);
|
|
|
1702
1859
|
|
|
1703
1860
|
var LoadingSpinner = function (_a) {
|
|
1704
1861
|
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..." }))] }));
|
|
1862
|
+
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
1863
|
};
|
|
1707
1864
|
|
|
1708
1865
|
var AuthSuccessAnimation = function (_a) {
|
|
@@ -1754,15 +1911,36 @@ var APIHeaders = {
|
|
|
1754
1911
|
"X-API-VERSION": "1.0",
|
|
1755
1912
|
};
|
|
1756
1913
|
|
|
1914
|
+
// Creates an Axios instance with a base URL determined by the environment (production or development).
|
|
1915
|
+
var axiosInstance = axios.create({
|
|
1916
|
+
httpsAgent: new https.Agent({ rejectUnauthorized: false }),
|
|
1917
|
+
headers: __assign({ "Content-Type": "application/json" }, APIHeaders),
|
|
1918
|
+
});
|
|
1919
|
+
// Intercepts outgoing requests to add authorization token, version header, and timeout settings.
|
|
1920
|
+
axiosInstance.interceptors.request.use(function (config) {
|
|
1921
|
+
var _a;
|
|
1922
|
+
config.timeout = Number((_a = process.env.NEXT_PUBLIC_API_TIMEOUT) !== null && _a !== void 0 ? _a : 605000);
|
|
1923
|
+
config.timeoutErrorMessage = "Operation Timed Out"; // Custom error message for timeouts.
|
|
1924
|
+
return config; // Returns the modified request configuration.
|
|
1925
|
+
}, function (axiosError) {
|
|
1926
|
+
var _a, _b;
|
|
1927
|
+
// Handles request errors.
|
|
1928
|
+
return {
|
|
1929
|
+
status: (_a = axiosError.response) === null || _a === void 0 ? void 0 : _a.status, // Extracts HTTP status from the error response.
|
|
1930
|
+
message: axiosError.message, // Extracts the error message.
|
|
1931
|
+
data: (_b = axiosError.response) === null || _b === void 0 ? void 0 : _b.data, // Extracts response data from the error.
|
|
1932
|
+
};
|
|
1933
|
+
});
|
|
1934
|
+
|
|
1757
1935
|
var MAX_ATTEMPTS = 3;
|
|
1758
1936
|
var useOTPHandler = function (_a) {
|
|
1759
1937
|
var provider = _a.provider, accessToken = _a.accessToken, idToken = _a.idToken, appCode = _a.appCode, authenticationType = _a.authenticationType, MFAEndpoint = _a.MFAEndpoint, onAuthComplete = _a.onAuthComplete;
|
|
1760
1938
|
var _b = useState(false), loading = _b[0], setLoading = _b[1];
|
|
1761
1939
|
var _c = useState(0), attemptCount = _c[0], setAttemptCount = _c[1];
|
|
1762
1940
|
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 () {
|
|
1941
|
+
var handleSubmitOTP = useMemo(function () { return function (authenticationValue) { return __awaiter$1(void 0, void 0, void 0, function () {
|
|
1764
1942
|
var currentAttempt, response, error_1, currentAttempt;
|
|
1765
|
-
return __generator(this, function (_a) {
|
|
1943
|
+
return __generator$1(this, function (_a) {
|
|
1766
1944
|
switch (_a.label) {
|
|
1767
1945
|
case 0:
|
|
1768
1946
|
if (isMaxAttemptsReached) {
|
|
@@ -1779,16 +1957,13 @@ var useOTPHandler = function (_a) {
|
|
|
1779
1957
|
setAttemptCount(currentAttempt);
|
|
1780
1958
|
if (authenticationType === null)
|
|
1781
1959
|
return [2 /*return*/, false];
|
|
1782
|
-
return [4 /*yield*/,
|
|
1960
|
+
return [4 /*yield*/, axiosInstance.post(MFAEndpoint || "/api/auth/verify-mfa", {
|
|
1783
1961
|
provider: provider,
|
|
1784
1962
|
accessToken: accessToken,
|
|
1785
1963
|
idToken: idToken,
|
|
1786
1964
|
authenticationType: authenticationType,
|
|
1787
1965
|
MFACode: authenticationValue,
|
|
1788
1966
|
appCode: appCode,
|
|
1789
|
-
}, {
|
|
1790
|
-
headers: APIHeaders,
|
|
1791
|
-
timeout: 605000,
|
|
1792
1967
|
})];
|
|
1793
1968
|
case 2:
|
|
1794
1969
|
response = (_a.sent()).data;
|
|
@@ -1855,23 +2030,20 @@ var useCredentialsHandler = function (onAuthComplete) {
|
|
|
1855
2030
|
var _b = useState(0), attemptCount = _b[0], setAttemptCount = _b[1];
|
|
1856
2031
|
var _c = useState(false), isMaxAttemptsReached = _c[0], setIsMaxAttemptsReached = _c[1];
|
|
1857
2032
|
var handleSubmitCredentials = useMemo(function () {
|
|
1858
|
-
return function (CredAuthEndpoint, credentials, appCode) { return __awaiter(void 0, void 0, void 0, function () {
|
|
2033
|
+
return function (CredAuthEndpoint, credentials, appCode) { return __awaiter$1(void 0, void 0, void 0, function () {
|
|
1859
2034
|
var currentAttempt, response, error_2, currentAttempt;
|
|
1860
|
-
return __generator(this, function (_a) {
|
|
2035
|
+
return __generator$1(this, function (_a) {
|
|
1861
2036
|
switch (_a.label) {
|
|
1862
2037
|
case 0:
|
|
1863
2038
|
_a.trys.push([0, 2, 3, 4]);
|
|
1864
2039
|
setLoading(true);
|
|
1865
2040
|
currentAttempt = attemptCount + 1;
|
|
1866
2041
|
setAttemptCount(currentAttempt);
|
|
1867
|
-
return [4 /*yield*/,
|
|
2042
|
+
return [4 /*yield*/, axiosInstance.post(CredAuthEndpoint, {
|
|
1868
2043
|
username: credentials.username,
|
|
1869
2044
|
password: credentials.password,
|
|
1870
2045
|
MFACode: credentials.MFACode,
|
|
1871
2046
|
appCode: appCode,
|
|
1872
|
-
}, {
|
|
1873
|
-
headers: APIHeaders,
|
|
1874
|
-
timeout: 605000,
|
|
1875
2047
|
})];
|
|
1876
2048
|
case 1:
|
|
1877
2049
|
response = (_a.sent()).data;
|
|
@@ -1932,23 +2104,21 @@ var MFAOptions = function (_a) {
|
|
|
1932
2104
|
var context = useCAMSContext();
|
|
1933
2105
|
var _f = context.authMode === "MSAL" && "sendEmailOTP" in context
|
|
1934
2106
|
? context
|
|
1935
|
-
: { sendEmailOTP: null, completeMFA: null, logout: function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
2107
|
+
: { sendEmailOTP: null, completeMFA: null, logout: function () { return __awaiter$1(void 0, void 0, void 0, function () { return __generator$1(this, function (_a) {
|
|
1936
2108
|
return [2 /*return*/];
|
|
1937
2109
|
}); }); } }, sendEmailOTP = _f.sendEmailOTP, completeMFA = _f.completeMFA, logout = _f.logout;
|
|
1938
2110
|
var accessToken = context.authMode === "MSAL" ? context.accessToken : "";
|
|
1939
2111
|
var idToken = context.authMode === "MSAL" ? context.idToken : "";
|
|
1940
2112
|
var authenticate = useWebAuthn().authenticate;
|
|
1941
|
-
var handleFIDOLogin = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
2113
|
+
var handleFIDOLogin = function () { return __awaiter$1(void 0, void 0, void 0, function () {
|
|
1942
2114
|
var options, assertionResponse, error_1;
|
|
1943
|
-
return __generator(this, function (_a) {
|
|
2115
|
+
return __generator$1(this, function (_a) {
|
|
1944
2116
|
switch (_a.label) {
|
|
1945
2117
|
case 0:
|
|
1946
2118
|
_a.trys.push([0, 4, , 5]);
|
|
1947
2119
|
// 1. Fetch authentication challenge from your server
|
|
1948
2120
|
console.log("Requesting authentication challenge from server...");
|
|
1949
|
-
return [4 /*yield*/,
|
|
1950
|
-
headers: APIHeaders,
|
|
1951
|
-
})];
|
|
2121
|
+
return [4 /*yield*/, axiosInstance.post(MFAEndpoints.RetrieveAuthChallenge, {})];
|
|
1952
2122
|
case 1:
|
|
1953
2123
|
options = (_a.sent()).data;
|
|
1954
2124
|
console.log("Received challenge:", options);
|
|
@@ -1960,9 +2130,7 @@ var MFAOptions = function (_a) {
|
|
|
1960
2130
|
console.log("Authentication assertion received from client:", assertionResponse);
|
|
1961
2131
|
// 3. Send the assertion back to the server for verification
|
|
1962
2132
|
console.log("Sending assertion to server for verification...");
|
|
1963
|
-
return [4 /*yield*/,
|
|
1964
|
-
headers: APIHeaders
|
|
1965
|
-
})];
|
|
2133
|
+
return [4 /*yield*/, axiosInstance.post(MFAEndpoints.AuthChallengeVerify, assertionResponse)];
|
|
1966
2134
|
case 3:
|
|
1967
2135
|
_a.sent();
|
|
1968
2136
|
toast.success("🔑 Sign-in successful!");
|
|
@@ -2024,12 +2192,12 @@ var MFAOptions = function (_a) {
|
|
|
2024
2192
|
}
|
|
2025
2193
|
var content = jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, {});
|
|
2026
2194
|
if (!authType) {
|
|
2027
|
-
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 () {
|
|
2195
|
+
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 () {
|
|
2028
2196
|
var success;
|
|
2029
|
-
return __generator(this, function (_a) {
|
|
2197
|
+
return __generator$1(this, function (_a) {
|
|
2030
2198
|
switch (_a.label) {
|
|
2031
2199
|
case 0:
|
|
2032
|
-
resetAttempts();
|
|
2200
|
+
// resetAttempts();
|
|
2033
2201
|
setAuthType("EmailOTP");
|
|
2034
2202
|
setOtpVisible(true);
|
|
2035
2203
|
if (!sendEmailOTP) return [3 /*break*/, 2];
|
|
@@ -2046,7 +2214,6 @@ var MFAOptions = function (_a) {
|
|
|
2046
2214
|
}
|
|
2047
2215
|
});
|
|
2048
2216
|
}); }, 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 () {
|
|
2049
|
-
resetAttempts();
|
|
2050
2217
|
setAuthType("AuthenticatorCode");
|
|
2051
2218
|
setOtpVisible(true);
|
|
2052
2219
|
}, 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",
|
|
@@ -2055,7 +2222,7 @@ var MFAOptions = function (_a) {
|
|
|
2055
2222
|
// setAuthType("AuthenticatorCode");
|
|
2056
2223
|
// setOtpVisible(true);
|
|
2057
2224
|
// }}
|
|
2058
|
-
onClick: handleFIDOLogin, disabled: context.isLoading, children: [jsxRuntimeExports.jsx(
|
|
2225
|
+
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" })] })] }))] })] }));
|
|
2059
2226
|
}
|
|
2060
2227
|
else if (authType === "EmailOTP") {
|
|
2061
2228
|
content = (jsxRuntimeExports.jsx(Dialog, { open: otpVisible, onOpenChange: function () {
|
|
@@ -2098,16 +2265,16 @@ var ADLoginModal = function (_a) {
|
|
|
2098
2265
|
resolver: a$1(credentialsSchema),
|
|
2099
2266
|
defaultValues: { username: "", password: "" },
|
|
2100
2267
|
});
|
|
2101
|
-
var handleCredentialsSubmit = function (values) { return __awaiter(void 0, void 0, void 0, function () {
|
|
2102
|
-
return __generator(this, function (_a) {
|
|
2268
|
+
var handleCredentialsSubmit = function (values) { return __awaiter$1(void 0, void 0, void 0, function () {
|
|
2269
|
+
return __generator$1(this, function (_a) {
|
|
2103
2270
|
setCredentials(values);
|
|
2104
2271
|
setStep("mfa");
|
|
2105
2272
|
return [2 /*return*/];
|
|
2106
2273
|
});
|
|
2107
2274
|
}); };
|
|
2108
|
-
var handleMFASubmit = function (code) { return __awaiter(void 0, void 0, void 0, function () {
|
|
2275
|
+
var handleMFASubmit = function (code) { return __awaiter$1(void 0, void 0, void 0, function () {
|
|
2109
2276
|
var error_1;
|
|
2110
|
-
return __generator(this, function (_a) {
|
|
2277
|
+
return __generator$1(this, function (_a) {
|
|
2111
2278
|
switch (_a.label) {
|
|
2112
2279
|
case 0:
|
|
2113
2280
|
setIsLoading(true);
|
|
@@ -2168,8 +2335,8 @@ var DefaultLoginPage = function (_a) {
|
|
|
2168
2335
|
var login = context.login, isLoading = context.isLoading, authMode = context.authMode;
|
|
2169
2336
|
var _b = useState(false), showADModal = _b[0], setShowADModal = _b[1];
|
|
2170
2337
|
var register = useWebAuthn().register;
|
|
2171
|
-
var _c = useCredentialsHandler(function (state, data) { return __awaiter(void 0, void 0, void 0, function () {
|
|
2172
|
-
return __generator(this, function (_a) {
|
|
2338
|
+
var _c = useCredentialsHandler(function (state, data) { return __awaiter$1(void 0, void 0, void 0, function () {
|
|
2339
|
+
return __generator$1(this, function (_a) {
|
|
2173
2340
|
console.log(data);
|
|
2174
2341
|
if (state && data) {
|
|
2175
2342
|
context.isAuthenticated = true;
|
|
@@ -2183,6 +2350,10 @@ var DefaultLoginPage = function (_a) {
|
|
|
2183
2350
|
});
|
|
2184
2351
|
}); }), handleSubmitCredentials = _c.handleSubmitCredentials, isCredAuthLoading = _c.loading, setIsCredAuthLoading = _c.setLoading;
|
|
2185
2352
|
var handleMSALLogin = function () {
|
|
2353
|
+
if (typeof window !== "undefined" && !window.crypto) {
|
|
2354
|
+
toast.error("Crypto API not available. Please use a modern browser.");
|
|
2355
|
+
return;
|
|
2356
|
+
}
|
|
2186
2357
|
if (authMode === "MSAL") {
|
|
2187
2358
|
login();
|
|
2188
2359
|
}
|
|
@@ -2191,17 +2362,15 @@ var DefaultLoginPage = function (_a) {
|
|
|
2191
2362
|
console.warn("Regular CAMS login requires configuration");
|
|
2192
2363
|
}
|
|
2193
2364
|
};
|
|
2194
|
-
var handleRegister = function (data) { return __awaiter(void 0, void 0, void 0, function () {
|
|
2365
|
+
var handleRegister = function (data) { return __awaiter$1(void 0, void 0, void 0, function () {
|
|
2195
2366
|
var options, attestationResponse, error_1;
|
|
2196
|
-
return __generator(this, function (_a) {
|
|
2367
|
+
return __generator$1(this, function (_a) {
|
|
2197
2368
|
switch (_a.label) {
|
|
2198
2369
|
case 0:
|
|
2199
2370
|
_a.trys.push([0, 4, , 5]);
|
|
2200
2371
|
// 1. Fetch challenge from your server
|
|
2201
2372
|
console.log("Requesting registration challenge from server...");
|
|
2202
|
-
return [4 /*yield*/,
|
|
2203
|
-
headers: APIHeaders,
|
|
2204
|
-
})];
|
|
2373
|
+
return [4 /*yield*/, axiosInstance.post(MFAEndpoints.RegisterNewChallenge, __assign({}, data))];
|
|
2205
2374
|
case 1:
|
|
2206
2375
|
options = (_a.sent()).data;
|
|
2207
2376
|
console.log("Received challenge:", options);
|
|
@@ -2213,9 +2382,7 @@ var DefaultLoginPage = function (_a) {
|
|
|
2213
2382
|
console.log("Passkey created on client:", attestationResponse);
|
|
2214
2383
|
// 3. Send the response back to the server for verification
|
|
2215
2384
|
console.log("Sending attestation to server for verification...");
|
|
2216
|
-
return [4 /*yield*/,
|
|
2217
|
-
headers: APIHeaders
|
|
2218
|
-
})];
|
|
2385
|
+
return [4 /*yield*/, axiosInstance.post(MFAEndpoints.RegisterVerify + "?username=".concat(data.username), attestationResponse)];
|
|
2219
2386
|
case 3:
|
|
2220
2387
|
_a.sent();
|
|
2221
2388
|
toast.success("✅ Registration successful! Passkey created.");
|
|
@@ -2229,15 +2396,15 @@ var DefaultLoginPage = function (_a) {
|
|
|
2229
2396
|
}
|
|
2230
2397
|
});
|
|
2231
2398
|
}); };
|
|
2232
|
-
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-
|
|
2399
|
+
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
|
|
2233
2400
|
// variant="outline"
|
|
2234
2401
|
, {
|
|
2235
2402
|
// variant="outline"
|
|
2236
2403
|
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
|
|
2237
2404
|
? "Logging in..."
|
|
2238
|
-
: "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) {
|
|
2405
|
+
: "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) {
|
|
2239
2406
|
var username = _b.username, password = _b.password, MFACode = _b.MFACode;
|
|
2240
|
-
return __generator(this, function (_c) {
|
|
2407
|
+
return __generator$1(this, function (_c) {
|
|
2241
2408
|
// Implement your AD login logic here
|
|
2242
2409
|
console.log("AD Login:", { username: username, password: password, MFACode: MFACode });
|
|
2243
2410
|
// Example: await adLoginService(username, password, mfaCode);
|
|
@@ -2278,8 +2445,8 @@ var MFAGate = function (_a) {
|
|
|
2278
2445
|
if (!success)
|
|
2279
2446
|
Logger.error("MFA authentication failed");
|
|
2280
2447
|
}, []);
|
|
2281
|
-
var handleAuthFailed = useCallback(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
2282
|
-
return __generator(this, function (_a) {
|
|
2448
|
+
var handleAuthFailed = useCallback(function () { return __awaiter$1(void 0, void 0, void 0, function () {
|
|
2449
|
+
return __generator$1(this, function (_a) {
|
|
2283
2450
|
switch (_a.label) {
|
|
2284
2451
|
case 0: return [4 /*yield*/, context.logout()];
|
|
2285
2452
|
case 1:
|
|
@@ -2288,7 +2455,6 @@ var MFAGate = function (_a) {
|
|
|
2288
2455
|
}
|
|
2289
2456
|
});
|
|
2290
2457
|
}); }, [context.logout]);
|
|
2291
|
-
Logger.debug("MFA Endpoint >>>", { MFAEndpoints: MFAEndpoints });
|
|
2292
2458
|
if (useADLogin && !CredentialsAuthEndpoint)
|
|
2293
2459
|
return jsxRuntimeExports.jsx(ErrorFallback, { message: "Invalid AD Login Configuration." });
|
|
2294
2460
|
if (!validatedMFAEndpoints)
|