@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.cjs.js
CHANGED
|
@@ -18,6 +18,7 @@ var DialogPrimitive = require('@radix-ui/react-dialog');
|
|
|
18
18
|
var sonner = require('sonner');
|
|
19
19
|
var framerMotion = require('framer-motion');
|
|
20
20
|
var axios = require('axios');
|
|
21
|
+
var https = require('https');
|
|
21
22
|
|
|
22
23
|
function _interopNamespaceDefault(e) {
|
|
23
24
|
var n = Object.create(null);
|
|
@@ -40,6 +41,118 @@ var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
|
40
41
|
var LabelPrimitive__namespace = /*#__PURE__*/_interopNamespaceDefault(LabelPrimitive);
|
|
41
42
|
var DialogPrimitive__namespace = /*#__PURE__*/_interopNamespaceDefault(DialogPrimitive);
|
|
42
43
|
|
|
44
|
+
// Crypto polyfill for MSAL browser compatibility
|
|
45
|
+
if (typeof window !== 'undefined') {
|
|
46
|
+
// Ensure crypto object exists
|
|
47
|
+
if (!window.crypto) {
|
|
48
|
+
window.crypto = {};
|
|
49
|
+
}
|
|
50
|
+
// Polyfill getRandomValues
|
|
51
|
+
if (!window.crypto.getRandomValues) {
|
|
52
|
+
window.crypto.getRandomValues = function (array) {
|
|
53
|
+
var bytes = new Uint8Array(array.buffer, array.byteOffset, array.byteLength);
|
|
54
|
+
for (var i = 0; i < bytes.length; i++) {
|
|
55
|
+
bytes[i] = Math.floor(Math.random() * 256);
|
|
56
|
+
}
|
|
57
|
+
return array;
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
// Polyfill crypto.subtle with SHA-256 (handles both undefined and null in non-HTTPS contexts)
|
|
61
|
+
if (!window.crypto.subtle || window.location.protocol === 'http:') {
|
|
62
|
+
var sha256_1 = function (data) { return __awaiter(void 0, void 0, void 0, function () {
|
|
63
|
+
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;
|
|
64
|
+
return __generator(this, function (_a) {
|
|
65
|
+
bytes = new Uint8Array(data);
|
|
66
|
+
hash = new Uint32Array(8);
|
|
67
|
+
k = new Uint32Array([
|
|
68
|
+
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
|
|
69
|
+
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
|
|
70
|
+
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
|
|
71
|
+
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
|
|
72
|
+
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
|
|
73
|
+
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
|
|
74
|
+
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
|
|
75
|
+
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
|
|
76
|
+
]);
|
|
77
|
+
hash[0] = 0x6a09e667;
|
|
78
|
+
hash[1] = 0xbb67ae85;
|
|
79
|
+
hash[2] = 0x3c6ef372;
|
|
80
|
+
hash[3] = 0xa54ff53a;
|
|
81
|
+
hash[4] = 0x510e527f;
|
|
82
|
+
hash[5] = 0x9b05688c;
|
|
83
|
+
hash[6] = 0x1f83d9ab;
|
|
84
|
+
hash[7] = 0x5be0cd19;
|
|
85
|
+
ml = bytes.length * 8;
|
|
86
|
+
msg = new Uint8Array(bytes.length + 64 + ((64 - ((bytes.length + 9) % 64)) % 64));
|
|
87
|
+
msg.set(bytes);
|
|
88
|
+
msg[bytes.length] = 0x80;
|
|
89
|
+
new DataView(msg.buffer).setUint32(msg.length - 4, ml, false);
|
|
90
|
+
for (i = 0; i < msg.length; i += 64) {
|
|
91
|
+
w = new Uint32Array(64);
|
|
92
|
+
for (j = 0; j < 16; j++)
|
|
93
|
+
w[j] = new DataView(msg.buffer).getUint32(i + j * 4, false);
|
|
94
|
+
for (j = 16; j < 64; j++) {
|
|
95
|
+
s0 = ((w[j - 15] >>> 7) | (w[j - 15] << 25)) ^ ((w[j - 15] >>> 18) | (w[j - 15] << 14)) ^ (w[j - 15] >>> 3);
|
|
96
|
+
s1 = ((w[j - 2] >>> 17) | (w[j - 2] << 15)) ^ ((w[j - 2] >>> 19) | (w[j - 2] << 13)) ^ (w[j - 2] >>> 10);
|
|
97
|
+
w[j] = (w[j - 16] + s0 + w[j - 7] + s1) >>> 0;
|
|
98
|
+
}
|
|
99
|
+
a = hash[0], b = hash[1], c = hash[2], d = hash[3], e = hash[4], f = hash[5], g = hash[6], h = hash[7];
|
|
100
|
+
for (j = 0; j < 64; j++) {
|
|
101
|
+
S1 = ((e >>> 6) | (e << 26)) ^ ((e >>> 11) | (e << 21)) ^ ((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)) ^ ((a >>> 13) | (a << 19)) ^ ((a >>> 22) | (a << 10));
|
|
105
|
+
maj = (a & b) ^ (a & c) ^ (b & c);
|
|
106
|
+
temp2 = (S0 + maj) >>> 0;
|
|
107
|
+
h = g;
|
|
108
|
+
g = f;
|
|
109
|
+
f = e;
|
|
110
|
+
e = (d + temp1) >>> 0;
|
|
111
|
+
d = c;
|
|
112
|
+
c = b;
|
|
113
|
+
b = a;
|
|
114
|
+
a = (temp1 + temp2) >>> 0;
|
|
115
|
+
}
|
|
116
|
+
hash[0] = (hash[0] + a) >>> 0;
|
|
117
|
+
hash[1] = (hash[1] + b) >>> 0;
|
|
118
|
+
hash[2] = (hash[2] + c) >>> 0;
|
|
119
|
+
hash[3] = (hash[3] + d) >>> 0;
|
|
120
|
+
hash[4] = (hash[4] + e) >>> 0;
|
|
121
|
+
hash[5] = (hash[5] + f) >>> 0;
|
|
122
|
+
hash[6] = (hash[6] + g) >>> 0;
|
|
123
|
+
hash[7] = (hash[7] + h) >>> 0;
|
|
124
|
+
}
|
|
125
|
+
result = new Uint8Array(32);
|
|
126
|
+
for (i = 0; i < 8; i++)
|
|
127
|
+
new DataView(result.buffer).setUint32(i * 4, hash[i], false);
|
|
128
|
+
return [2 /*return*/, result.buffer];
|
|
129
|
+
});
|
|
130
|
+
}); };
|
|
131
|
+
window.crypto.subtle = {
|
|
132
|
+
digest: function (algorithm, data) { return __awaiter(void 0, void 0, void 0, function () {
|
|
133
|
+
var alg;
|
|
134
|
+
return __generator(this, function (_a) {
|
|
135
|
+
alg = typeof algorithm === 'string' ? algorithm : algorithm.name;
|
|
136
|
+
if (alg === 'SHA-256')
|
|
137
|
+
return [2 /*return*/, sha256_1(data)];
|
|
138
|
+
console.error("Unsupported crypto algorithm: ".concat(alg));
|
|
139
|
+
throw new Error("Unsupported algorithm: ".concat(alg));
|
|
140
|
+
});
|
|
141
|
+
}); }
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
// Polyfill randomUUID
|
|
145
|
+
if (!window.crypto.randomUUID) {
|
|
146
|
+
window.crypto.randomUUID = function () {
|
|
147
|
+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
|
148
|
+
var r = (Math.random() * 16) | 0;
|
|
149
|
+
var v = c === 'x' ? r : (r & 0x3) | 0x8;
|
|
150
|
+
return v.toString(16);
|
|
151
|
+
});
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
43
156
|
/******************************************************************************
|
|
44
157
|
Copyright (c) Microsoft Corporation.
|
|
45
158
|
|
|
@@ -80,7 +193,7 @@ function __rest(s, e) {
|
|
|
80
193
|
return t;
|
|
81
194
|
}
|
|
82
195
|
|
|
83
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
196
|
+
function __awaiter$1(thisArg, _arguments, P, generator) {
|
|
84
197
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
85
198
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
86
199
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
@@ -90,7 +203,7 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
90
203
|
});
|
|
91
204
|
}
|
|
92
205
|
|
|
93
|
-
function __generator(thisArg, body) {
|
|
206
|
+
function __generator$1(thisArg, body) {
|
|
94
207
|
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
95
208
|
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
96
209
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
@@ -187,10 +300,10 @@ function useCAMSAuth(options) {
|
|
|
187
300
|
}
|
|
188
301
|
}
|
|
189
302
|
}, [options.storageKey]);
|
|
190
|
-
var login = React.useCallback(function (config) { return __awaiter(_this, void 0, void 0, function () {
|
|
303
|
+
var login = React.useCallback(function (config) { return __awaiter$1(_this, void 0, void 0, function () {
|
|
191
304
|
var loginConfig, userProfile, err_1, e, isPopupClosedError, restoredToken, userProfile;
|
|
192
305
|
var _a, _b, _c;
|
|
193
|
-
return __generator(this, function (_d) {
|
|
306
|
+
return __generator$1(this, function (_d) {
|
|
194
307
|
switch (_d.label) {
|
|
195
308
|
case 0:
|
|
196
309
|
if (!sessionManagerRef.current)
|
|
@@ -238,8 +351,8 @@ function useCAMSAuth(options) {
|
|
|
238
351
|
}
|
|
239
352
|
});
|
|
240
353
|
}); }, [options.idleTimeout]);
|
|
241
|
-
var logout = React.useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
242
|
-
return __generator(this, function (_a) {
|
|
354
|
+
var logout = React.useCallback(function () { return __awaiter$1(_this, void 0, void 0, function () {
|
|
355
|
+
return __generator$1(this, function (_a) {
|
|
243
356
|
switch (_a.label) {
|
|
244
357
|
case 0:
|
|
245
358
|
if (!sessionManagerRef.current)
|
|
@@ -270,6 +383,7 @@ function useCAMSAuth(options) {
|
|
|
270
383
|
}
|
|
271
384
|
|
|
272
385
|
var setCookie$1 = function (name, value, days) {
|
|
386
|
+
if (days === void 0) { days = 1; }
|
|
273
387
|
var expires = new Date(Date.now() + days * 24 * 60 * 60 * 1000).toUTCString();
|
|
274
388
|
document.cookie = "".concat(name, "=").concat(encodeURIComponent(value), "; expires=").concat(expires, "; path=/; samesite=Lax");
|
|
275
389
|
};
|
|
@@ -290,17 +404,18 @@ var deleteCookie$1 = function (name) {
|
|
|
290
404
|
|
|
291
405
|
function useCAMSMSALAuth(options) {
|
|
292
406
|
var _this = this;
|
|
293
|
-
var
|
|
294
|
-
var
|
|
407
|
+
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;
|
|
408
|
+
var storageKey = optStorageKey || "CAMS-MSAL-AUTH-SDK";
|
|
409
|
+
var _b = msalReact.useMsal(), instance = _b.instance, inProgress = _b.inProgress, accounts = _b.accounts;
|
|
295
410
|
var account = msalReact.useAccount(accounts[0] || {});
|
|
296
|
-
var
|
|
297
|
-
var
|
|
298
|
-
var
|
|
299
|
-
var
|
|
300
|
-
var
|
|
411
|
+
var _c = React.useState(null), error = _c[0], setError = _c[1];
|
|
412
|
+
var _d = React.useState(""), idToken = _d[0], setIdToken = _d[1];
|
|
413
|
+
var _e = React.useState(""), accessToken = _e[0], setAccessToken = _e[1];
|
|
414
|
+
var _f = React.useState(null), mfaAuthenticator = _f[0], setMfaAuthenticator = _f[1];
|
|
415
|
+
var _g = React.useState(false), requiresMFA = _g[0], setRequiresMFA = _g[1];
|
|
301
416
|
var isLoading = inProgress !== msalBrowser.InteractionStatus.None;
|
|
302
417
|
var isAuthenticated = !!account && !!accessToken && !requiresMFA;
|
|
303
|
-
var scopes =
|
|
418
|
+
var scopes = optScopes || ["openid", "profile", "email"];
|
|
304
419
|
var isTokenValid = function (token) {
|
|
305
420
|
try {
|
|
306
421
|
var payload = JSON.parse(atob(token.split(".")[1]));
|
|
@@ -324,15 +439,14 @@ function useCAMSMSALAuth(options) {
|
|
|
324
439
|
var mfaConfig = {
|
|
325
440
|
accessToken: accessToken_1,
|
|
326
441
|
idToken: idToken_1,
|
|
327
|
-
appCode:
|
|
442
|
+
appCode: appCode,
|
|
328
443
|
provider: "MSAL",
|
|
329
|
-
apiEndpoint:
|
|
444
|
+
apiEndpoint: MFAEndpoint,
|
|
330
445
|
};
|
|
331
446
|
var authenticator = new camsSdk.CAMSMFAAuthenticator(mfaConfig);
|
|
332
447
|
setMfaAuthenticator(authenticator);
|
|
333
448
|
setRequiresMFA(true);
|
|
334
449
|
}
|
|
335
|
-
camsSdk.Logger.debug("App Code", { ">>>": options.appCode });
|
|
336
450
|
}
|
|
337
451
|
else {
|
|
338
452
|
localStorage.removeItem(storageKey);
|
|
@@ -374,22 +488,26 @@ function useCAMSMSALAuth(options) {
|
|
|
374
488
|
// };
|
|
375
489
|
// handleRedirect();
|
|
376
490
|
// }, []);
|
|
377
|
-
var login = React.useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
491
|
+
var login = React.useCallback(function () { return __awaiter$1(_this, void 0, void 0, function () {
|
|
378
492
|
var response, mfaConfig, authenticator, err_1, camsError_1, camsError;
|
|
379
|
-
var _a
|
|
380
|
-
return __generator(this, function (
|
|
381
|
-
switch (
|
|
493
|
+
var _a;
|
|
494
|
+
return __generator$1(this, function (_b) {
|
|
495
|
+
switch (_b.label) {
|
|
382
496
|
case 0:
|
|
497
|
+
if (inProgress !== msalBrowser.InteractionStatus.None) {
|
|
498
|
+
camsSdk.Logger.warn("Authentication already in progress, ignoring duplicate call");
|
|
499
|
+
return [2 /*return*/];
|
|
500
|
+
}
|
|
383
501
|
setError(null);
|
|
384
|
-
|
|
502
|
+
_b.label = 1;
|
|
385
503
|
case 1:
|
|
386
|
-
|
|
504
|
+
_b.trys.push([1, 3, , 4]);
|
|
387
505
|
return [4 /*yield*/, instance.loginPopup({
|
|
388
506
|
scopes: scopes,
|
|
389
|
-
prompt:
|
|
507
|
+
prompt: prompt || "login",
|
|
390
508
|
})];
|
|
391
509
|
case 2:
|
|
392
|
-
response =
|
|
510
|
+
response = _b.sent();
|
|
393
511
|
console.log("Login Token response:", {
|
|
394
512
|
accessToken: response.accessToken,
|
|
395
513
|
idToken: response.idToken,
|
|
@@ -399,9 +517,9 @@ function useCAMSMSALAuth(options) {
|
|
|
399
517
|
mfaConfig = {
|
|
400
518
|
accessToken: response.accessToken,
|
|
401
519
|
idToken: response.idToken,
|
|
402
|
-
appCode:
|
|
520
|
+
appCode: appCode,
|
|
403
521
|
provider: "MSAL",
|
|
404
|
-
apiEndpoint:
|
|
522
|
+
apiEndpoint: MFAEndpoint,
|
|
405
523
|
};
|
|
406
524
|
authenticator = new camsSdk.CAMSMFAAuthenticator(mfaConfig);
|
|
407
525
|
setMfaAuthenticator(authenticator);
|
|
@@ -415,10 +533,15 @@ function useCAMSMSALAuth(options) {
|
|
|
415
533
|
idToken: response.idToken,
|
|
416
534
|
}));
|
|
417
535
|
}
|
|
418
|
-
|
|
536
|
+
onAuthSuccess === null || onAuthSuccess === void 0 ? void 0 : onAuthSuccess(response.accessToken);
|
|
419
537
|
return [3 /*break*/, 4];
|
|
420
538
|
case 3:
|
|
421
|
-
err_1 =
|
|
539
|
+
err_1 = _b.sent();
|
|
540
|
+
// Handle interaction_in_progress error
|
|
541
|
+
if (err_1.errorCode === "interaction_in_progress") {
|
|
542
|
+
camsSdk.Logger.warn("Interaction already in progress, please wait");
|
|
543
|
+
return [2 /*return*/];
|
|
544
|
+
}
|
|
422
545
|
// Handle user cancellation gracefully
|
|
423
546
|
if (err_1.errorCode === "user_cancelled") {
|
|
424
547
|
camsSdk.Logger.error("User cancelled login");
|
|
@@ -427,22 +550,22 @@ function useCAMSMSALAuth(options) {
|
|
|
427
550
|
}
|
|
428
551
|
// If popup is blocked
|
|
429
552
|
if (err_1.errorCode === "popup_window_error" ||
|
|
430
|
-
((
|
|
553
|
+
((_a = err_1.message) === null || _a === void 0 ? void 0 : _a.includes("popup"))) {
|
|
431
554
|
camsError_1 = new camsSdk.CAMSError(camsSdk.CAMSErrorType.POPUP_BLOCKED, "Popup blocked by browser. Please allow popups and try again.");
|
|
432
555
|
setError(camsError_1);
|
|
433
|
-
|
|
556
|
+
onAuthError === null || onAuthError === void 0 ? void 0 : onAuthError(camsError_1);
|
|
434
557
|
return [2 /*return*/];
|
|
435
558
|
}
|
|
436
559
|
camsError = new camsSdk.CAMSError(camsSdk.CAMSErrorType.API_VALIDATION_ERROR, "Login failed: " + err_1.message || err_1);
|
|
437
560
|
setError(camsError);
|
|
438
|
-
|
|
561
|
+
onAuthError === null || onAuthError === void 0 ? void 0 : onAuthError(camsError);
|
|
439
562
|
return [3 /*break*/, 4];
|
|
440
563
|
case 4: return [2 /*return*/];
|
|
441
564
|
}
|
|
442
565
|
});
|
|
443
|
-
}); }, [instance, scopes,
|
|
444
|
-
var completeMFA = React.useCallback(function (data) { return __awaiter(_this, void 0, void 0, function () {
|
|
445
|
-
return __generator(this, function (_a) {
|
|
566
|
+
}); }, [instance, scopes, prompt, appCode, MFAEndpoint, onAuthSuccess, onAuthError, storageKey, inProgress]);
|
|
567
|
+
var completeMFA = React.useCallback(function (data) { return __awaiter$1(_this, void 0, void 0, function () {
|
|
568
|
+
return __generator$1(this, function (_a) {
|
|
446
569
|
if (!mfaAuthenticator) {
|
|
447
570
|
throw new camsSdk.CAMSError(camsSdk.CAMSErrorType.API_VALIDATION_ERROR, "MFA Authenticator not initialized");
|
|
448
571
|
}
|
|
@@ -456,7 +579,7 @@ function useCAMSMSALAuth(options) {
|
|
|
456
579
|
accessToken: accessToken,
|
|
457
580
|
idToken: idToken,
|
|
458
581
|
}));
|
|
459
|
-
setCookie$1("CAMS-MSAL-AUTH-SDK-PROFILE", JSON.stringify({ type: "AUTH_SUCCESS", userProfile: __assign({}, data) }),
|
|
582
|
+
setCookie$1("CAMS-MSAL-AUTH-SDK-PROFILE", JSON.stringify({ type: "AUTH_SUCCESS", userProfile: __assign({}, data) }), activeCookiePeriod);
|
|
460
583
|
setRequiresMFA(false);
|
|
461
584
|
// Set requiresMFA to false after storage update
|
|
462
585
|
camsSdk.Logger.debug("MFA completed successfully, storage updated", {
|
|
@@ -475,9 +598,9 @@ function useCAMSMSALAuth(options) {
|
|
|
475
598
|
}
|
|
476
599
|
return [2 /*return*/];
|
|
477
600
|
});
|
|
478
|
-
}); }, [mfaAuthenticator, accessToken, idToken, storageKey]);
|
|
479
|
-
var sendEmailOTP = React.useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
480
|
-
return __generator(this, function (_a) {
|
|
601
|
+
}); }, [mfaAuthenticator, accessToken, idToken, storageKey, activeCookiePeriod]);
|
|
602
|
+
var sendEmailOTP = React.useCallback(function () { return __awaiter$1(_this, void 0, void 0, function () {
|
|
603
|
+
return __generator$1(this, function (_a) {
|
|
481
604
|
switch (_a.label) {
|
|
482
605
|
case 0:
|
|
483
606
|
if (!mfaAuthenticator) {
|
|
@@ -488,9 +611,9 @@ function useCAMSMSALAuth(options) {
|
|
|
488
611
|
}
|
|
489
612
|
});
|
|
490
613
|
}); }, [mfaAuthenticator]);
|
|
491
|
-
var logout = React.useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
614
|
+
var logout = React.useCallback(function () { return __awaiter$1(_this, void 0, void 0, function () {
|
|
492
615
|
var err_2, camsError;
|
|
493
|
-
return __generator(this, function (_a) {
|
|
616
|
+
return __generator$1(this, function (_a) {
|
|
494
617
|
switch (_a.label) {
|
|
495
618
|
case 0:
|
|
496
619
|
_a.trys.push([0, 2, , 3]);
|
|
@@ -526,12 +649,13 @@ function useCAMSMSALAuth(options) {
|
|
|
526
649
|
error: error,
|
|
527
650
|
idToken: idToken,
|
|
528
651
|
accessToken: accessToken,
|
|
529
|
-
appCode:
|
|
652
|
+
appCode: appCode,
|
|
530
653
|
mfaAuthenticator: mfaAuthenticator,
|
|
531
654
|
requiresMFA: requiresMFA,
|
|
532
655
|
completeMFA: completeMFA,
|
|
533
656
|
sendEmailOTP: sendEmailOTP,
|
|
534
657
|
setRequiresMFA: setRequiresMFA,
|
|
658
|
+
activeCookiePeriod: activeCookiePeriod,
|
|
535
659
|
};
|
|
536
660
|
}
|
|
537
661
|
|
|
@@ -574,10 +698,10 @@ function arrayBufferToBase64url(buffer) {
|
|
|
574
698
|
* @returns A promise that resolves to a JSON-serializable representation of the PublicKeyCredential.
|
|
575
699
|
*/
|
|
576
700
|
function register(options) {
|
|
577
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
701
|
+
return __awaiter$1(this, void 0, void 0, function () {
|
|
578
702
|
var createOptions, credential, publicKeyCredential, attestationResponse, transports, err_1;
|
|
579
703
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
580
|
-
return __generator(this, function (_k) {
|
|
704
|
+
return __generator$1(this, function (_k) {
|
|
581
705
|
switch (_k.label) {
|
|
582
706
|
case 0:
|
|
583
707
|
_k.trys.push([0, 2, , 3]);
|
|
@@ -635,10 +759,10 @@ function register(options) {
|
|
|
635
759
|
* @returns A promise that resolves to a JSON-serializable representation of the PublicKeyCredential.
|
|
636
760
|
*/
|
|
637
761
|
function authenticate(options) {
|
|
638
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
762
|
+
return __awaiter$1(this, void 0, void 0, function () {
|
|
639
763
|
var getOptions, credential, publicKeyCredential, assertionResponse;
|
|
640
764
|
var _a;
|
|
641
|
-
return __generator(this, function (_b) {
|
|
765
|
+
return __generator$1(this, function (_b) {
|
|
642
766
|
switch (_b.label) {
|
|
643
767
|
case 0:
|
|
644
768
|
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) })); }) });
|
|
@@ -1125,7 +1249,9 @@ function ProtectedRoute(_a) {
|
|
|
1125
1249
|
|
|
1126
1250
|
var CAMSMSALContext = React.createContext(null);
|
|
1127
1251
|
var setCookie = function (name, value, days) {
|
|
1252
|
+
if (days === void 0) { days = 1; }
|
|
1128
1253
|
var expires = new Date(Date.now() + days * 864e5).toUTCString();
|
|
1254
|
+
camsSdk.Logger.debug("Auth Cookie Expires >>>", { name: name, value: value, expires: expires });
|
|
1129
1255
|
document.cookie = "".concat(name, "=").concat(encodeURIComponent(value), "; expires=").concat(expires, "; path=/; samesite=Lax");
|
|
1130
1256
|
};
|
|
1131
1257
|
var getCookie = function (name) {
|
|
@@ -1190,7 +1316,7 @@ function CAMSMSALProviderInner(_a) {
|
|
|
1190
1316
|
localStorage.setItem(auth.storageKey, JSON.stringify({
|
|
1191
1317
|
accessToken: auth.accessToken,
|
|
1192
1318
|
idToken: auth.idToken,
|
|
1193
|
-
appCode: auth.appCode
|
|
1319
|
+
appCode: auth.appCode,
|
|
1194
1320
|
}));
|
|
1195
1321
|
}
|
|
1196
1322
|
}, [auth.accessToken, auth.idToken, auth.storageKey]);
|
|
@@ -1198,7 +1324,7 @@ function CAMSMSALProviderInner(_a) {
|
|
|
1198
1324
|
React.useEffect(function () {
|
|
1199
1325
|
if (typeof window !== "undefined") {
|
|
1200
1326
|
if (userProfile) {
|
|
1201
|
-
setCookie(profileStorageKey, JSON.stringify(userProfile),
|
|
1327
|
+
setCookie(profileStorageKey, JSON.stringify(userProfile), auth.activeCookiePeriod); // Store for 1 day
|
|
1202
1328
|
}
|
|
1203
1329
|
else {
|
|
1204
1330
|
deleteCookie(profileStorageKey);
|
|
@@ -1206,8 +1332,8 @@ function CAMSMSALProviderInner(_a) {
|
|
|
1206
1332
|
}
|
|
1207
1333
|
}, [userProfile, profileStorageKey]);
|
|
1208
1334
|
// Enhanced logout that also clears profile
|
|
1209
|
-
var enhancedLogout = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
1210
|
-
return __generator(this, function (_a) {
|
|
1335
|
+
var enhancedLogout = function () { return __awaiter$1(_this, void 0, void 0, function () {
|
|
1336
|
+
return __generator$1(this, function (_a) {
|
|
1211
1337
|
switch (_a.label) {
|
|
1212
1338
|
case 0: return [4 /*yield*/, auth.logout()];
|
|
1213
1339
|
case 1:
|
|
@@ -1225,7 +1351,9 @@ function CAMSMSALProviderInner(_a) {
|
|
|
1225
1351
|
}
|
|
1226
1352
|
function CAMSMSALProvider(props) {
|
|
1227
1353
|
var msalConfig = props.msalConfig, msalInstance = props.msalInstance;
|
|
1228
|
-
var instance =
|
|
1354
|
+
var instance = typeof window !== "undefined"
|
|
1355
|
+
? msalInstance || new msalBrowser.PublicClientApplication(msalConfig)
|
|
1356
|
+
: null;
|
|
1229
1357
|
return (jsxRuntimeExports.jsx(msalReact.MsalProvider, { instance: instance, children: jsxRuntimeExports.jsx(CAMSMSALProviderInner, __assign({}, props)) }));
|
|
1230
1358
|
}
|
|
1231
1359
|
function useCAMSMSALContext() {
|
|
@@ -1303,8 +1431,8 @@ function CAMSProviderCore(props) {
|
|
|
1303
1431
|
}
|
|
1304
1432
|
}
|
|
1305
1433
|
}, [userProfile, profileStorageKey]);
|
|
1306
|
-
var enhancedLogout = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
1307
|
-
return __generator(this, function (_a) {
|
|
1434
|
+
var enhancedLogout = function () { return __awaiter$1(_this, void 0, void 0, function () {
|
|
1435
|
+
return __generator$1(this, function (_a) {
|
|
1308
1436
|
switch (_a.label) {
|
|
1309
1437
|
case 0: return [4 /*yield*/, auth.logout()];
|
|
1310
1438
|
case 1:
|
|
@@ -1347,7 +1475,8 @@ function CAMSProviderCore(props) {
|
|
|
1347
1475
|
userProfile,
|
|
1348
1476
|
]);
|
|
1349
1477
|
var value = React.useMemo(function () {
|
|
1350
|
-
|
|
1478
|
+
auth.logout; var authRest = __rest(auth, ["logout"]);
|
|
1479
|
+
return __assign(__assign({}, authRest), { logout: enhancedLogout, userProfile: userProfile, setUserProfile: setUserProfile, authMode: mode });
|
|
1351
1480
|
}, [auth, userProfile, mode]);
|
|
1352
1481
|
return jsxRuntimeExports.jsx(CAMSContext.Provider, { value: value, children: children });
|
|
1353
1482
|
}
|
|
@@ -1359,7 +1488,9 @@ function UnifiedCAMSProvider(props) {
|
|
|
1359
1488
|
}
|
|
1360
1489
|
if (props.mode === "MSAL") {
|
|
1361
1490
|
var msalConfig = props.msalConfig, msalInstance = props.msalInstance;
|
|
1362
|
-
var instance =
|
|
1491
|
+
var instance = typeof window !== "undefined"
|
|
1492
|
+
? msalInstance || new msalBrowser.PublicClientApplication(msalConfig)
|
|
1493
|
+
: null;
|
|
1363
1494
|
return (jsxRuntimeExports.jsx(msalReact.MsalProvider, { instance: instance, children: jsxRuntimeExports.jsx(CAMSProviderCore, __assign({}, props)) }));
|
|
1364
1495
|
}
|
|
1365
1496
|
return (jsxRuntimeExports.jsx(ClientOnly, { fallback: jsxRuntimeExports.jsx("div", { children: "Loading..." }), children: jsxRuntimeExports.jsx(CAMSProviderCore, __assign({}, props)) }));
|
|
@@ -1723,7 +1854,7 @@ styleInject(css_248z);
|
|
|
1723
1854
|
|
|
1724
1855
|
var LoadingSpinner = function (_a) {
|
|
1725
1856
|
var loadingText = _a.loadingText;
|
|
1726
|
-
return (jsxRuntimeExports.jsxs("div", { className: "flex flex-col justify-center items-center", children: [jsxRuntimeExports.jsx("script", { type: "module", defer: true, src: "https://cdn.jsdelivr.net/npm/ldrs/dist/auto/waveform.js" }), jsxRuntimeExports.jsx(r, { size: "35", stroke: "3.5", speed: "1", color: "green" }), loadingText && (jsxRuntimeExports.jsx("p", { className: "text-center font-semibold mt-3", children: "Loading..." }))] }));
|
|
1857
|
+
return (jsxRuntimeExports.jsxs("div", { className: "flex flex-col justify-center items-center h-full w-full py-10", children: [jsxRuntimeExports.jsx("script", { type: "module", defer: true, src: "https://cdn.jsdelivr.net/npm/ldrs/dist/auto/waveform.js" }), jsxRuntimeExports.jsx(r, { size: "35", stroke: "3.5", speed: "1", color: "green" }), loadingText && (jsxRuntimeExports.jsx("p", { className: "text-center font-semibold mt-3", children: "Loading..." }))] }));
|
|
1727
1858
|
};
|
|
1728
1859
|
|
|
1729
1860
|
var AuthSuccessAnimation = function (_a) {
|
|
@@ -1775,15 +1906,36 @@ var APIHeaders = {
|
|
|
1775
1906
|
"X-API-VERSION": "1.0",
|
|
1776
1907
|
};
|
|
1777
1908
|
|
|
1909
|
+
// Creates an Axios instance with a base URL determined by the environment (production or development).
|
|
1910
|
+
var axiosInstance = axios.create({
|
|
1911
|
+
httpsAgent: new https.Agent({ rejectUnauthorized: false }),
|
|
1912
|
+
headers: __assign({ "Content-Type": "application/json" }, APIHeaders),
|
|
1913
|
+
});
|
|
1914
|
+
// Intercepts outgoing requests to add authorization token, version header, and timeout settings.
|
|
1915
|
+
axiosInstance.interceptors.request.use(function (config) {
|
|
1916
|
+
var _a;
|
|
1917
|
+
config.timeout = Number((_a = process.env.NEXT_PUBLIC_API_TIMEOUT) !== null && _a !== void 0 ? _a : 605000);
|
|
1918
|
+
config.timeoutErrorMessage = "Operation Timed Out"; // Custom error message for timeouts.
|
|
1919
|
+
return config; // Returns the modified request configuration.
|
|
1920
|
+
}, function (axiosError) {
|
|
1921
|
+
var _a, _b;
|
|
1922
|
+
// Handles request errors.
|
|
1923
|
+
return {
|
|
1924
|
+
status: (_a = axiosError.response) === null || _a === void 0 ? void 0 : _a.status, // Extracts HTTP status from the error response.
|
|
1925
|
+
message: axiosError.message, // Extracts the error message.
|
|
1926
|
+
data: (_b = axiosError.response) === null || _b === void 0 ? void 0 : _b.data, // Extracts response data from the error.
|
|
1927
|
+
};
|
|
1928
|
+
});
|
|
1929
|
+
|
|
1778
1930
|
var MAX_ATTEMPTS = 3;
|
|
1779
1931
|
var useOTPHandler = function (_a) {
|
|
1780
1932
|
var provider = _a.provider, accessToken = _a.accessToken, idToken = _a.idToken, appCode = _a.appCode, authenticationType = _a.authenticationType, MFAEndpoint = _a.MFAEndpoint, onAuthComplete = _a.onAuthComplete;
|
|
1781
1933
|
var _b = React.useState(false), loading = _b[0], setLoading = _b[1];
|
|
1782
1934
|
var _c = React.useState(0), attemptCount = _c[0], setAttemptCount = _c[1];
|
|
1783
1935
|
var _d = React.useState(false), isMaxAttemptsReached = _d[0], setIsMaxAttemptsReached = _d[1];
|
|
1784
|
-
var handleSubmitOTP = React.useMemo(function () { return function (authenticationValue) { return __awaiter(void 0, void 0, void 0, function () {
|
|
1936
|
+
var handleSubmitOTP = React.useMemo(function () { return function (authenticationValue) { return __awaiter$1(void 0, void 0, void 0, function () {
|
|
1785
1937
|
var currentAttempt, response, error_1, currentAttempt;
|
|
1786
|
-
return __generator(this, function (_a) {
|
|
1938
|
+
return __generator$1(this, function (_a) {
|
|
1787
1939
|
switch (_a.label) {
|
|
1788
1940
|
case 0:
|
|
1789
1941
|
if (isMaxAttemptsReached) {
|
|
@@ -1800,16 +1952,13 @@ var useOTPHandler = function (_a) {
|
|
|
1800
1952
|
setAttemptCount(currentAttempt);
|
|
1801
1953
|
if (authenticationType === null)
|
|
1802
1954
|
return [2 /*return*/, false];
|
|
1803
|
-
return [4 /*yield*/,
|
|
1955
|
+
return [4 /*yield*/, axiosInstance.post(MFAEndpoint || "/api/auth/verify-mfa", {
|
|
1804
1956
|
provider: provider,
|
|
1805
1957
|
accessToken: accessToken,
|
|
1806
1958
|
idToken: idToken,
|
|
1807
1959
|
authenticationType: authenticationType,
|
|
1808
1960
|
MFACode: authenticationValue,
|
|
1809
1961
|
appCode: appCode,
|
|
1810
|
-
}, {
|
|
1811
|
-
headers: APIHeaders,
|
|
1812
|
-
timeout: 605000,
|
|
1813
1962
|
})];
|
|
1814
1963
|
case 2:
|
|
1815
1964
|
response = (_a.sent()).data;
|
|
@@ -1876,23 +2025,20 @@ var useCredentialsHandler = function (onAuthComplete) {
|
|
|
1876
2025
|
var _b = React.useState(0), attemptCount = _b[0], setAttemptCount = _b[1];
|
|
1877
2026
|
var _c = React.useState(false), isMaxAttemptsReached = _c[0], setIsMaxAttemptsReached = _c[1];
|
|
1878
2027
|
var handleSubmitCredentials = React.useMemo(function () {
|
|
1879
|
-
return function (CredAuthEndpoint, credentials, appCode) { return __awaiter(void 0, void 0, void 0, function () {
|
|
2028
|
+
return function (CredAuthEndpoint, credentials, appCode) { return __awaiter$1(void 0, void 0, void 0, function () {
|
|
1880
2029
|
var currentAttempt, response, error_2, currentAttempt;
|
|
1881
|
-
return __generator(this, function (_a) {
|
|
2030
|
+
return __generator$1(this, function (_a) {
|
|
1882
2031
|
switch (_a.label) {
|
|
1883
2032
|
case 0:
|
|
1884
2033
|
_a.trys.push([0, 2, 3, 4]);
|
|
1885
2034
|
setLoading(true);
|
|
1886
2035
|
currentAttempt = attemptCount + 1;
|
|
1887
2036
|
setAttemptCount(currentAttempt);
|
|
1888
|
-
return [4 /*yield*/,
|
|
2037
|
+
return [4 /*yield*/, axiosInstance.post(CredAuthEndpoint, {
|
|
1889
2038
|
username: credentials.username,
|
|
1890
2039
|
password: credentials.password,
|
|
1891
2040
|
MFACode: credentials.MFACode,
|
|
1892
2041
|
appCode: appCode,
|
|
1893
|
-
}, {
|
|
1894
|
-
headers: APIHeaders,
|
|
1895
|
-
timeout: 605000,
|
|
1896
2042
|
})];
|
|
1897
2043
|
case 1:
|
|
1898
2044
|
response = (_a.sent()).data;
|
|
@@ -1953,23 +2099,21 @@ var MFAOptions = function (_a) {
|
|
|
1953
2099
|
var context = useCAMSContext();
|
|
1954
2100
|
var _f = context.authMode === "MSAL" && "sendEmailOTP" in context
|
|
1955
2101
|
? context
|
|
1956
|
-
: { sendEmailOTP: null, completeMFA: null, logout: function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
2102
|
+
: { sendEmailOTP: null, completeMFA: null, logout: function () { return __awaiter$1(void 0, void 0, void 0, function () { return __generator$1(this, function (_a) {
|
|
1957
2103
|
return [2 /*return*/];
|
|
1958
2104
|
}); }); } }, sendEmailOTP = _f.sendEmailOTP, completeMFA = _f.completeMFA, logout = _f.logout;
|
|
1959
2105
|
var accessToken = context.authMode === "MSAL" ? context.accessToken : "";
|
|
1960
2106
|
var idToken = context.authMode === "MSAL" ? context.idToken : "";
|
|
1961
2107
|
var authenticate = useWebAuthn().authenticate;
|
|
1962
|
-
var handleFIDOLogin = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
2108
|
+
var handleFIDOLogin = function () { return __awaiter$1(void 0, void 0, void 0, function () {
|
|
1963
2109
|
var options, assertionResponse, error_1;
|
|
1964
|
-
return __generator(this, function (_a) {
|
|
2110
|
+
return __generator$1(this, function (_a) {
|
|
1965
2111
|
switch (_a.label) {
|
|
1966
2112
|
case 0:
|
|
1967
2113
|
_a.trys.push([0, 4, , 5]);
|
|
1968
2114
|
// 1. Fetch authentication challenge from your server
|
|
1969
2115
|
console.log("Requesting authentication challenge from server...");
|
|
1970
|
-
return [4 /*yield*/,
|
|
1971
|
-
headers: APIHeaders,
|
|
1972
|
-
})];
|
|
2116
|
+
return [4 /*yield*/, axiosInstance.post(MFAEndpoints.RetrieveAuthChallenge, {})];
|
|
1973
2117
|
case 1:
|
|
1974
2118
|
options = (_a.sent()).data;
|
|
1975
2119
|
console.log("Received challenge:", options);
|
|
@@ -1981,10 +2125,7 @@ var MFAOptions = function (_a) {
|
|
|
1981
2125
|
console.log("Authentication assertion received from client:", assertionResponse);
|
|
1982
2126
|
// 3. Send the assertion back to the server for verification
|
|
1983
2127
|
console.log("Sending assertion to server for verification...");
|
|
1984
|
-
return [4 /*yield*/,
|
|
1985
|
-
headers: APIHeaders,
|
|
1986
|
-
withCredentials: true, // credentials: 'include'
|
|
1987
|
-
})];
|
|
2128
|
+
return [4 /*yield*/, axiosInstance.post(MFAEndpoints.AuthChallengeVerify, assertionResponse)];
|
|
1988
2129
|
case 3:
|
|
1989
2130
|
_a.sent();
|
|
1990
2131
|
sonner.toast.success("🔑 Sign-in successful!");
|
|
@@ -2046,12 +2187,12 @@ var MFAOptions = function (_a) {
|
|
|
2046
2187
|
}
|
|
2047
2188
|
var content = jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, {});
|
|
2048
2189
|
if (!authType) {
|
|
2049
|
-
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 () {
|
|
2190
|
+
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 () {
|
|
2050
2191
|
var success;
|
|
2051
|
-
return __generator(this, function (_a) {
|
|
2192
|
+
return __generator$1(this, function (_a) {
|
|
2052
2193
|
switch (_a.label) {
|
|
2053
2194
|
case 0:
|
|
2054
|
-
resetAttempts();
|
|
2195
|
+
// resetAttempts();
|
|
2055
2196
|
setAuthType("EmailOTP");
|
|
2056
2197
|
setOtpVisible(true);
|
|
2057
2198
|
if (!sendEmailOTP) return [3 /*break*/, 2];
|
|
@@ -2068,7 +2209,6 @@ var MFAOptions = function (_a) {
|
|
|
2068
2209
|
}
|
|
2069
2210
|
});
|
|
2070
2211
|
}); }, children: [jsxRuntimeExports.jsx(lucideReact.Mail, { className: "w-5 h-5" }), jsxRuntimeExports.jsxs("div", { className: "text-left", children: [jsxRuntimeExports.jsx("div", { className: "font-medium", children: "Email OTP" }), jsxRuntimeExports.jsx("div", { className: "text-sm text-gray-500", children: "Send code to your email" })] })] }), jsxRuntimeExports.jsxs(Button, { variant: "outline", className: "w-full flex items-center justify-start gap-3 p-4 h-auto border-2 hover:border-[#506f4a] hover:bg-[#506f4a]/5 transition-all", onClick: function () {
|
|
2071
|
-
resetAttempts();
|
|
2072
2212
|
setAuthType("AuthenticatorCode");
|
|
2073
2213
|
setOtpVisible(true);
|
|
2074
2214
|
}, children: [jsxRuntimeExports.jsx("img", { src: MicrosoftAuthenticatorImg, alt: "Authenticator", className: "rounded-full", width: 24, height: 24, onError: function () { return jsxRuntimeExports.jsx(lucideReact.Shield, {}); } }), jsxRuntimeExports.jsxs("div", { className: "text-left", children: [jsxRuntimeExports.jsx("div", { className: "font-medium", children: "Authenticator App" }), jsxRuntimeExports.jsx("div", { className: "text-sm text-gray-500", children: "Use Authenticator App" })] })] }), usePassKey && (jsxRuntimeExports.jsxs(Button, { variant: "outline", className: "w-full flex items-center justify-start gap-3 p-4 h-auto border-2 hover:border-[#506f4a] hover:bg-[#506f4a]/5 transition-all",
|
|
@@ -2077,7 +2217,7 @@ var MFAOptions = function (_a) {
|
|
|
2077
2217
|
// setAuthType("AuthenticatorCode");
|
|
2078
2218
|
// setOtpVisible(true);
|
|
2079
2219
|
// }}
|
|
2080
|
-
onClick: handleFIDOLogin, disabled: context.isLoading, children: [jsxRuntimeExports.jsx(
|
|
2220
|
+
onClick: handleFIDOLogin, disabled: context.isLoading, children: [jsxRuntimeExports.jsx(lucideReact.KeyIcon, { className: "text-[#506f4a]", size: 48 }), jsxRuntimeExports.jsxs("div", { className: "text-left", children: [jsxRuntimeExports.jsx("div", { className: "font-medium", children: "Continue with Passkey" }), jsxRuntimeExports.jsx("div", { className: "text-sm text-gray-500", children: "Passkey" })] })] }))] })] }));
|
|
2081
2221
|
}
|
|
2082
2222
|
else if (authType === "EmailOTP") {
|
|
2083
2223
|
content = (jsxRuntimeExports.jsx(Dialog, { open: otpVisible, onOpenChange: function () {
|
|
@@ -2120,16 +2260,16 @@ var ADLoginModal = function (_a) {
|
|
|
2120
2260
|
resolver: a$1(credentialsSchema),
|
|
2121
2261
|
defaultValues: { username: "", password: "" },
|
|
2122
2262
|
});
|
|
2123
|
-
var handleCredentialsSubmit = function (values) { return __awaiter(void 0, void 0, void 0, function () {
|
|
2124
|
-
return __generator(this, function (_a) {
|
|
2263
|
+
var handleCredentialsSubmit = function (values) { return __awaiter$1(void 0, void 0, void 0, function () {
|
|
2264
|
+
return __generator$1(this, function (_a) {
|
|
2125
2265
|
setCredentials(values);
|
|
2126
2266
|
setStep("mfa");
|
|
2127
2267
|
return [2 /*return*/];
|
|
2128
2268
|
});
|
|
2129
2269
|
}); };
|
|
2130
|
-
var handleMFASubmit = function (code) { return __awaiter(void 0, void 0, void 0, function () {
|
|
2270
|
+
var handleMFASubmit = function (code) { return __awaiter$1(void 0, void 0, void 0, function () {
|
|
2131
2271
|
var error_1;
|
|
2132
|
-
return __generator(this, function (_a) {
|
|
2272
|
+
return __generator$1(this, function (_a) {
|
|
2133
2273
|
switch (_a.label) {
|
|
2134
2274
|
case 0:
|
|
2135
2275
|
setIsLoading(true);
|
|
@@ -2165,7 +2305,7 @@ var ADLoginModal = function (_a) {
|
|
|
2165
2305
|
form.reset();
|
|
2166
2306
|
setMfaCode("");
|
|
2167
2307
|
};
|
|
2168
|
-
return (jsxRuntimeExports.jsx(Dialog, { open: open, onOpenChange: handleClose, children: jsxRuntimeExports.jsxs(DialogContent, { className: "
|
|
2308
|
+
return (jsxRuntimeExports.jsx(Dialog, { open: open, onOpenChange: handleClose, children: jsxRuntimeExports.jsxs(DialogContent, { className: "min-w-[50vw] max-w-[70vw]", children: [jsxRuntimeExports.jsx(DialogHeader, { children: jsxRuntimeExports.jsxs("div", { className: "flex items-center gap-2", children: [jsxRuntimeExports.jsx(lucideReact.KeyIcon, { className: "w-8 h-8 text-[#506f4a]" }), jsxRuntimeExports.jsx(DialogTitle, { className: "text-2xl", children: "Sign in with AD" })] }) }), step === "credentials" ? (jsxRuntimeExports.jsx(Form, __assign({}, form, { children: jsxRuntimeExports.jsxs("form", { onSubmit: form.handleSubmit(handleCredentialsSubmit), className: "space-y-4", children: [jsxRuntimeExports.jsx(FormField, { control: form.control, name: "username", render: function (_a) {
|
|
2169
2309
|
var field = _a.field;
|
|
2170
2310
|
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, {})] }));
|
|
2171
2311
|
} }), jsxRuntimeExports.jsx(FormField, { control: form.control, name: "password", render: function (_a) {
|
|
@@ -2190,8 +2330,8 @@ var DefaultLoginPage = function (_a) {
|
|
|
2190
2330
|
var login = context.login, isLoading = context.isLoading, authMode = context.authMode;
|
|
2191
2331
|
var _b = React.useState(false), showADModal = _b[0], setShowADModal = _b[1];
|
|
2192
2332
|
var register = useWebAuthn().register;
|
|
2193
|
-
var _c = useCredentialsHandler(function (state, data) { return __awaiter(void 0, void 0, void 0, function () {
|
|
2194
|
-
return __generator(this, function (_a) {
|
|
2333
|
+
var _c = useCredentialsHandler(function (state, data) { return __awaiter$1(void 0, void 0, void 0, function () {
|
|
2334
|
+
return __generator$1(this, function (_a) {
|
|
2195
2335
|
console.log(data);
|
|
2196
2336
|
if (state && data) {
|
|
2197
2337
|
context.isAuthenticated = true;
|
|
@@ -2205,6 +2345,10 @@ var DefaultLoginPage = function (_a) {
|
|
|
2205
2345
|
});
|
|
2206
2346
|
}); }), handleSubmitCredentials = _c.handleSubmitCredentials, isCredAuthLoading = _c.loading, setIsCredAuthLoading = _c.setLoading;
|
|
2207
2347
|
var handleMSALLogin = function () {
|
|
2348
|
+
if (typeof window !== "undefined" && !window.crypto) {
|
|
2349
|
+
sonner.toast.error("Crypto API not available. Please use a modern browser.");
|
|
2350
|
+
return;
|
|
2351
|
+
}
|
|
2208
2352
|
if (authMode === "MSAL") {
|
|
2209
2353
|
login();
|
|
2210
2354
|
}
|
|
@@ -2213,17 +2357,15 @@ var DefaultLoginPage = function (_a) {
|
|
|
2213
2357
|
console.warn("Regular CAMS login requires configuration");
|
|
2214
2358
|
}
|
|
2215
2359
|
};
|
|
2216
|
-
var handleRegister = function (data) { return __awaiter(void 0, void 0, void 0, function () {
|
|
2360
|
+
var handleRegister = function (data) { return __awaiter$1(void 0, void 0, void 0, function () {
|
|
2217
2361
|
var options, attestationResponse, error_1;
|
|
2218
|
-
return __generator(this, function (_a) {
|
|
2362
|
+
return __generator$1(this, function (_a) {
|
|
2219
2363
|
switch (_a.label) {
|
|
2220
2364
|
case 0:
|
|
2221
2365
|
_a.trys.push([0, 4, , 5]);
|
|
2222
2366
|
// 1. Fetch challenge from your server
|
|
2223
2367
|
console.log("Requesting registration challenge from server...");
|
|
2224
|
-
return [4 /*yield*/,
|
|
2225
|
-
headers: APIHeaders,
|
|
2226
|
-
})];
|
|
2368
|
+
return [4 /*yield*/, axiosInstance.post(MFAEndpoints.RegisterNewChallenge, __assign({}, data))];
|
|
2227
2369
|
case 1:
|
|
2228
2370
|
options = (_a.sent()).data;
|
|
2229
2371
|
console.log("Received challenge:", options);
|
|
@@ -2235,10 +2377,7 @@ var DefaultLoginPage = function (_a) {
|
|
|
2235
2377
|
console.log("Passkey created on client:", attestationResponse);
|
|
2236
2378
|
// 3. Send the response back to the server for verification
|
|
2237
2379
|
console.log("Sending attestation to server for verification...");
|
|
2238
|
-
return [4 /*yield*/,
|
|
2239
|
-
headers: APIHeaders,
|
|
2240
|
-
withCredentials: true, // credentials: 'include'
|
|
2241
|
-
})];
|
|
2380
|
+
return [4 /*yield*/, axiosInstance.post(MFAEndpoints.RegisterVerify + "?username=".concat(data.username), attestationResponse)];
|
|
2242
2381
|
case 3:
|
|
2243
2382
|
_a.sent();
|
|
2244
2383
|
sonner.toast.success("✅ Registration successful! Passkey created.");
|
|
@@ -2252,15 +2391,15 @@ var DefaultLoginPage = function (_a) {
|
|
|
2252
2391
|
}
|
|
2253
2392
|
});
|
|
2254
2393
|
}); };
|
|
2255
|
-
return (jsxRuntimeExports.jsxs("main", { className: "min-h-screen bg-gray-50", children: [jsxRuntimeExports.jsx(framerMotion.motion.div, { initial: { opacity: 0 }, animate: { opacity: 1 }, exit: { opacity: 0 }, transition: { duration: 0.5 }, children: jsxRuntimeExports.jsx("div", { className: "flex h-screen items-center justify-center", children: jsxRuntimeExports.jsxs(framerMotion.motion.div, { variants: cardVariants, initial: "hidden", animate: "visible", exit: "exit", className: "w-full max-w-md p-6 space-y-4 bg-gray-50 rounded-2xl shadow-2xl --dark:bg-gray-800", children: [jsxRuntimeExports.jsxs(CardHeader, { className: "text-center space-y-3", children: [jsxRuntimeExports.jsx("div", { className: "w-full flex items-center justify-center", children: jsxRuntimeExports.jsx("img", { src: NIBSSLogo, alt: "NIBSS Logo", width: 265, height: 265 }) }), jsxRuntimeExports.jsx(CardTitle, { className: "text-3xl font-bold --text-gray-900 --dark:text-white", children: "NIBSS CAMS" }), jsxRuntimeExports.jsx(CardTitle, { className: "text-gray-500 dark:text-gray-400 font-bold text-lg", children: "Centralized Authentication" })] }), jsxRuntimeExports.jsxs(CardAction, { className: "w-full flex flex-col items-center justify-center text-center text-gray-500 dark:text-gray-400 mb-
|
|
2394
|
+
return (jsxRuntimeExports.jsxs("main", { className: "min-h-screen bg-gray-50", children: [jsxRuntimeExports.jsx(framerMotion.motion.div, { initial: { opacity: 0 }, animate: { opacity: 1 }, exit: { opacity: 0 }, transition: { duration: 0.5 }, children: jsxRuntimeExports.jsx("div", { className: "flex h-screen items-center justify-center", children: jsxRuntimeExports.jsxs(framerMotion.motion.div, { variants: cardVariants, initial: "hidden", animate: "visible", exit: "exit", className: "w-full max-w-md p-6 space-y-4 bg-gray-50 rounded-2xl shadow-2xl --dark:bg-gray-800", children: [jsxRuntimeExports.jsxs(CardHeader, { className: "text-center space-y-3", children: [jsxRuntimeExports.jsx("div", { className: "w-full flex items-center justify-center", children: jsxRuntimeExports.jsx("img", { src: NIBSSLogo, alt: "NIBSS Logo", width: 265, height: 265 }) }), jsxRuntimeExports.jsx(CardTitle, { className: "text-3xl font-bold --text-gray-900 --dark:text-white", children: "NIBSS CAMS" }), jsxRuntimeExports.jsx(CardTitle, { className: "text-gray-500 dark:text-gray-400 font-bold text-lg", children: "Centralized Authentication" })] }), jsxRuntimeExports.jsxs(CardAction, { className: "w-full flex flex-col items-center justify-center text-center text-gray-500 dark:text-gray-400 mb-8", children: [jsxRuntimeExports.jsx("img", { src: AuthLogo, alt: "Auth Logo", width: 365, height: 365 }), "Use Below Identity Providers To Authenticate"] }), jsxRuntimeExports.jsxs("div", { className: "space-y-4", children: [jsxRuntimeExports.jsxs(Button
|
|
2256
2395
|
// variant="outline"
|
|
2257
2396
|
, {
|
|
2258
2397
|
// variant="outline"
|
|
2259
2398
|
className: "w-full flex items-center justify-center cursor-pointer bg-[#506f4a] hover:bg-[#506f4a] rounded-lg border border-transparent px-5 py-8 text-base font-medium transition-colors duration-250", onClick: handleMSALLogin, disabled: isLoading, children: [jsxRuntimeExports.jsx("img", { src: MicrosoftLogo, alt: "Microsoft Logo", width: 35, height: 35 }), jsxRuntimeExports.jsx("span", { className: "ml-2", children: isLoading ? "Logging in..." : "Sign in with Microsoft" })] }), useADLogin && (jsxRuntimeExports.jsxs(Button, { className: "w-full flex items-center justify-center cursor-pointer bg-[#506f4a] hover:bg-[#506f4a] rounded-lg border border-transparent px-5 py-8 text-base font-medium transition-colors duration-250", onClick: function () { return setShowADModal(true); }, disabled: isLoading, children: [jsxRuntimeExports.jsx(lucideReact.KeyIcon, { className: "text-[#506f4a]", size: 64 }), jsxRuntimeExports.jsx("span", { children: isLoading
|
|
2260
2399
|
? "Logging in..."
|
|
2261
|
-
: "Sign in with ActiveDirectory" })] })), usePassKey && (jsxRuntimeExports.jsxs(Button, { className: "w-full flex items-center justify-center cursor-pointer bg-[#506f4a] hover:bg-[#506f4a] rounded-lg border border-transparent px-5 py-8 text-base font-medium transition-colors duration-250", onClick: function () { return handleRegister(PassKeysRegisterProps); }, disabled: isLoading, children: [jsxRuntimeExports.jsx(lucideReact.KeyIcon, { className: "text-[#506f4a]", size: 64 }), jsxRuntimeExports.jsx("span", { children: "Create a Passkey" })] }))] }), jsxRuntimeExports.jsxs(CardFooter, { className: "flex items-center justify-center mt-6 space-x-2 text-gray-400 text-sm", children: [jsxRuntimeExports.jsx(lucideReact.ShieldCheck, { className: "w-4 h-4 text-[#506f4a] pulse-glow" }), jsxRuntimeExports.jsx("span", { children: "Powered By NIBSS" })] })] }) }) }, "landing"), jsxRuntimeExports.jsx(ADLoginModal, { open: showADModal, onOpenChange: setShowADModal, isLoading: isCredAuthLoading, setIsLoading: setIsCredAuthLoading, onLogin: function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
|
|
2400
|
+
: "Sign in with ActiveDirectory" })] })), usePassKey && (jsxRuntimeExports.jsxs(Button, { className: "w-full flex items-center justify-center cursor-pointer bg-[#506f4a] hover:bg-[#506f4a] rounded-lg border border-transparent px-5 py-8 text-base font-medium transition-colors duration-250", onClick: function () { return handleRegister(PassKeysRegisterProps); }, disabled: isLoading, children: [jsxRuntimeExports.jsx(lucideReact.KeyIcon, { className: "text-[#506f4a]", size: 64 }), jsxRuntimeExports.jsx("span", { children: "Create a Passkey" })] }))] }), jsxRuntimeExports.jsxs(CardFooter, { className: "flex items-center justify-center mt-6 space-x-2 text-gray-400 text-sm", children: [jsxRuntimeExports.jsx(lucideReact.ShieldCheck, { className: "w-4 h-4 text-[#506f4a] pulse-glow" }), jsxRuntimeExports.jsx("span", { children: "Powered By NIBSS" })] })] }) }) }, "landing"), jsxRuntimeExports.jsx(ADLoginModal, { open: showADModal, onOpenChange: setShowADModal, isLoading: isCredAuthLoading, setIsLoading: setIsCredAuthLoading, onLogin: function (_a) { return __awaiter$1(void 0, [_a], void 0, function (_b) {
|
|
2262
2401
|
var username = _b.username, password = _b.password, MFACode = _b.MFACode;
|
|
2263
|
-
return __generator(this, function (_c) {
|
|
2402
|
+
return __generator$1(this, function (_c) {
|
|
2264
2403
|
// Implement your AD login logic here
|
|
2265
2404
|
console.log("AD Login:", { username: username, password: password, MFACode: MFACode });
|
|
2266
2405
|
// Example: await adLoginService(username, password, mfaCode);
|
|
@@ -2301,8 +2440,8 @@ var MFAGate = function (_a) {
|
|
|
2301
2440
|
if (!success)
|
|
2302
2441
|
camsSdk.Logger.error("MFA authentication failed");
|
|
2303
2442
|
}, []);
|
|
2304
|
-
var handleAuthFailed = React.useCallback(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
2305
|
-
return __generator(this, function (_a) {
|
|
2443
|
+
var handleAuthFailed = React.useCallback(function () { return __awaiter$1(void 0, void 0, void 0, function () {
|
|
2444
|
+
return __generator$1(this, function (_a) {
|
|
2306
2445
|
switch (_a.label) {
|
|
2307
2446
|
case 0: return [4 /*yield*/, context.logout()];
|
|
2308
2447
|
case 1:
|
|
@@ -2311,7 +2450,6 @@ var MFAGate = function (_a) {
|
|
|
2311
2450
|
}
|
|
2312
2451
|
});
|
|
2313
2452
|
}); }, [context.logout]);
|
|
2314
|
-
camsSdk.Logger.debug("MFA Endpoint >>>", { MFAEndpoints: MFAEndpoints });
|
|
2315
2453
|
if (useADLogin && !CredentialsAuthEndpoint)
|
|
2316
2454
|
return jsxRuntimeExports.jsx(ErrorFallback, { message: "Invalid AD Login Configuration." });
|
|
2317
2455
|
if (!validatedMFAEndpoints)
|