@nibssplc/cams-sdk-react 1.0.0-rc.4 → 1.0.0-rc.40
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 +289 -126
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.esm.js +289 -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.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,164 @@ 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
|
+
(function () {
|
|
46
|
+
var _this = this;
|
|
47
|
+
if (typeof window === "undefined")
|
|
48
|
+
return;
|
|
49
|
+
// Ensure crypto object exists
|
|
50
|
+
if (!window.crypto) {
|
|
51
|
+
window.crypto = {};
|
|
52
|
+
}
|
|
53
|
+
// Polyfill getRandomValues
|
|
54
|
+
if (!window.crypto.getRandomValues) {
|
|
55
|
+
window.crypto.getRandomValues = function (array) {
|
|
56
|
+
var bytes = new Uint8Array(array.buffer, array.byteOffset, array.byteLength);
|
|
57
|
+
for (var i = 0; i < bytes.length; i++) {
|
|
58
|
+
bytes[i] = Math.floor(Math.random() * 256);
|
|
59
|
+
}
|
|
60
|
+
return array;
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
var sha256 = function (data) { return __awaiter(_this, void 0, void 0, function () {
|
|
64
|
+
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;
|
|
65
|
+
return __generator(this, function (_a) {
|
|
66
|
+
toUint8 = function (src) {
|
|
67
|
+
if (src instanceof ArrayBuffer)
|
|
68
|
+
return new Uint8Array(src);
|
|
69
|
+
if (ArrayBuffer.isView(src)) {
|
|
70
|
+
var view = src;
|
|
71
|
+
return new Uint8Array(view.buffer, view.byteOffset || 0, view.byteLength);
|
|
72
|
+
}
|
|
73
|
+
throw new TypeError("Unsupported BufferSource");
|
|
74
|
+
};
|
|
75
|
+
bytes = toUint8(data);
|
|
76
|
+
hash = new Uint32Array(8);
|
|
77
|
+
k = new Uint32Array([
|
|
78
|
+
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1,
|
|
79
|
+
0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
|
|
80
|
+
0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786,
|
|
81
|
+
0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
|
|
82
|
+
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147,
|
|
83
|
+
0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
|
|
84
|
+
0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 0xa2bfe8a1, 0xa81a664b,
|
|
85
|
+
0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
|
|
86
|
+
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a,
|
|
87
|
+
0x5b9cca4f, 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
|
|
88
|
+
0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,
|
|
89
|
+
]);
|
|
90
|
+
hash[0] = 0x6a09e667;
|
|
91
|
+
hash[1] = 0xbb67ae85;
|
|
92
|
+
hash[2] = 0x3c6ef372;
|
|
93
|
+
hash[3] = 0xa54ff53a;
|
|
94
|
+
hash[4] = 0x510e527f;
|
|
95
|
+
hash[5] = 0x9b05688c;
|
|
96
|
+
hash[6] = 0x1f83d9ab;
|
|
97
|
+
hash[7] = 0x5be0cd19;
|
|
98
|
+
ml = bytes.length * 8;
|
|
99
|
+
msg = new Uint8Array(bytes.length + 64 + ((64 - ((bytes.length + 9) % 64)) % 64));
|
|
100
|
+
msg.set(bytes);
|
|
101
|
+
msg[bytes.length] = 0x80;
|
|
102
|
+
dv = new DataView(msg.buffer);
|
|
103
|
+
high = Math.floor(ml / 0x100000000);
|
|
104
|
+
low = ml >>> 0;
|
|
105
|
+
dv.setUint32(msg.length - 8, high, false);
|
|
106
|
+
dv.setUint32(msg.length - 4, low, false);
|
|
107
|
+
for (i = 0; i < msg.length; i += 64) {
|
|
108
|
+
w = new Uint32Array(64);
|
|
109
|
+
for (j = 0; j < 16; j++)
|
|
110
|
+
w[j] = new DataView(msg.buffer).getUint32(i + j * 4, false);
|
|
111
|
+
for (j = 16; j < 64; j++) {
|
|
112
|
+
s0 = ((w[j - 15] >>> 7) | (w[j - 15] << 25)) ^
|
|
113
|
+
((w[j - 15] >>> 18) | (w[j - 15] << 14)) ^
|
|
114
|
+
(w[j - 15] >>> 3);
|
|
115
|
+
s1 = ((w[j - 2] >>> 17) | (w[j - 2] << 15)) ^
|
|
116
|
+
((w[j - 2] >>> 19) | (w[j - 2] << 13)) ^
|
|
117
|
+
(w[j - 2] >>> 10);
|
|
118
|
+
w[j] = (w[j - 16] + s0 + w[j - 7] + s1) >>> 0;
|
|
119
|
+
}
|
|
120
|
+
a = hash[0], b = hash[1], c = hash[2], d = hash[3], e = hash[4], f = hash[5], g = hash[6], h = hash[7];
|
|
121
|
+
for (j = 0; j < 64; j++) {
|
|
122
|
+
S1 = ((e >>> 6) | (e << 26)) ^
|
|
123
|
+
((e >>> 11) | (e << 21)) ^
|
|
124
|
+
((e >>> 25) | (e << 7));
|
|
125
|
+
ch = (e & f) ^ (~e & g);
|
|
126
|
+
temp1 = (h + S1 + ch + k[j] + w[j]) >>> 0;
|
|
127
|
+
S0 = ((a >>> 2) | (a << 30)) ^
|
|
128
|
+
((a >>> 13) | (a << 19)) ^
|
|
129
|
+
((a >>> 22) | (a << 10));
|
|
130
|
+
maj = (a & b) ^ (a & c) ^ (b & c);
|
|
131
|
+
temp2 = (S0 + maj) >>> 0;
|
|
132
|
+
h = g;
|
|
133
|
+
g = f;
|
|
134
|
+
f = e;
|
|
135
|
+
e = (d + temp1) >>> 0;
|
|
136
|
+
d = c;
|
|
137
|
+
c = b;
|
|
138
|
+
b = a;
|
|
139
|
+
a = (temp1 + temp2) >>> 0;
|
|
140
|
+
}
|
|
141
|
+
hash[0] = (hash[0] + a) >>> 0;
|
|
142
|
+
hash[1] = (hash[1] + b) >>> 0;
|
|
143
|
+
hash[2] = (hash[2] + c) >>> 0;
|
|
144
|
+
hash[3] = (hash[3] + d) >>> 0;
|
|
145
|
+
hash[4] = (hash[4] + e) >>> 0;
|
|
146
|
+
hash[5] = (hash[5] + f) >>> 0;
|
|
147
|
+
hash[6] = (hash[6] + g) >>> 0;
|
|
148
|
+
hash[7] = (hash[7] + h) >>> 0;
|
|
149
|
+
}
|
|
150
|
+
result = new Uint8Array(32);
|
|
151
|
+
for (i = 0; i < 8; i++)
|
|
152
|
+
new DataView(result.buffer).setUint32(i * 4, hash[i], false);
|
|
153
|
+
return [2 /*return*/, result.buffer];
|
|
154
|
+
});
|
|
155
|
+
}); };
|
|
156
|
+
// Store reference to original subtle if it exists
|
|
157
|
+
var originalSubtle = window.crypto.subtle;
|
|
158
|
+
// Create the polyfilled subtle object
|
|
159
|
+
var polyfillSubtle = {
|
|
160
|
+
digest: function (algorithm, data) { return __awaiter(_this, void 0, void 0, function () {
|
|
161
|
+
var alg;
|
|
162
|
+
return __generator(this, function (_a) {
|
|
163
|
+
alg = typeof algorithm === "string"
|
|
164
|
+
? algorithm
|
|
165
|
+
: algorithm.name;
|
|
166
|
+
if (alg === "SHA-256")
|
|
167
|
+
return [2 /*return*/, sha256(data)];
|
|
168
|
+
if (originalSubtle === null || originalSubtle === void 0 ? void 0 : originalSubtle.digest)
|
|
169
|
+
return [2 /*return*/, originalSubtle.digest(algorithm, data)];
|
|
170
|
+
throw new Error("Unsupported algorithm: ".concat(alg));
|
|
171
|
+
});
|
|
172
|
+
}); },
|
|
173
|
+
};
|
|
174
|
+
// Try to define the property, fallback to assignment if needed
|
|
175
|
+
try {
|
|
176
|
+
Object.defineProperty(window.crypto, "subtle", {
|
|
177
|
+
configurable: true,
|
|
178
|
+
enumerable: true,
|
|
179
|
+
writable: true,
|
|
180
|
+
value: polyfillSubtle,
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
catch (_a) {
|
|
184
|
+
// Some environments prevent redefining built-ins
|
|
185
|
+
window.crypto.subtle = polyfillSubtle;
|
|
186
|
+
}
|
|
187
|
+
// Polyfill randomUUID
|
|
188
|
+
if (!window.crypto.randomUUID) {
|
|
189
|
+
window.crypto.randomUUID =
|
|
190
|
+
function () {
|
|
191
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
|
|
192
|
+
var r = (Math.random() * 16) | 0;
|
|
193
|
+
var v = c === "x" ? r : (r & 0x3) | 0x8;
|
|
194
|
+
return v.toString(16);
|
|
195
|
+
});
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
// Log success for debugging
|
|
199
|
+
console.log("Crypto polyfill loaded successfully");
|
|
200
|
+
})();
|
|
201
|
+
|
|
43
202
|
/******************************************************************************
|
|
44
203
|
Copyright (c) Microsoft Corporation.
|
|
45
204
|
|
|
@@ -80,7 +239,7 @@ function __rest(s, e) {
|
|
|
80
239
|
return t;
|
|
81
240
|
}
|
|
82
241
|
|
|
83
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
242
|
+
function __awaiter$1(thisArg, _arguments, P, generator) {
|
|
84
243
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
85
244
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
86
245
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
@@ -90,7 +249,7 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
90
249
|
});
|
|
91
250
|
}
|
|
92
251
|
|
|
93
|
-
function __generator(thisArg, body) {
|
|
252
|
+
function __generator$1(thisArg, body) {
|
|
94
253
|
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
254
|
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
96
255
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
@@ -187,10 +346,10 @@ function useCAMSAuth(options) {
|
|
|
187
346
|
}
|
|
188
347
|
}
|
|
189
348
|
}, [options.storageKey]);
|
|
190
|
-
var login = React.useCallback(function (config) { return __awaiter(_this, void 0, void 0, function () {
|
|
349
|
+
var login = React.useCallback(function (config) { return __awaiter$1(_this, void 0, void 0, function () {
|
|
191
350
|
var loginConfig, userProfile, err_1, e, isPopupClosedError, restoredToken, userProfile;
|
|
192
351
|
var _a, _b, _c;
|
|
193
|
-
return __generator(this, function (_d) {
|
|
352
|
+
return __generator$1(this, function (_d) {
|
|
194
353
|
switch (_d.label) {
|
|
195
354
|
case 0:
|
|
196
355
|
if (!sessionManagerRef.current)
|
|
@@ -238,8 +397,8 @@ function useCAMSAuth(options) {
|
|
|
238
397
|
}
|
|
239
398
|
});
|
|
240
399
|
}); }, [options.idleTimeout]);
|
|
241
|
-
var logout = React.useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
242
|
-
return __generator(this, function (_a) {
|
|
400
|
+
var logout = React.useCallback(function () { return __awaiter$1(_this, void 0, void 0, function () {
|
|
401
|
+
return __generator$1(this, function (_a) {
|
|
243
402
|
switch (_a.label) {
|
|
244
403
|
case 0:
|
|
245
404
|
if (!sessionManagerRef.current)
|
|
@@ -269,11 +428,13 @@ function useCAMSAuth(options) {
|
|
|
269
428
|
};
|
|
270
429
|
}
|
|
271
430
|
|
|
272
|
-
var setCookie
|
|
431
|
+
var setCookie = function (name, value, days) {
|
|
432
|
+
if (days === void 0) { days = 1; }
|
|
273
433
|
var expires = new Date(Date.now() + days * 24 * 60 * 60 * 1000).toUTCString();
|
|
434
|
+
console.log("Auth Cookie Expires >>>", { name: name, value: value, expires: expires });
|
|
274
435
|
document.cookie = "".concat(name, "=").concat(encodeURIComponent(value), "; expires=").concat(expires, "; path=/; samesite=Lax");
|
|
275
436
|
};
|
|
276
|
-
var getCookie
|
|
437
|
+
var getCookie = function (name) {
|
|
277
438
|
var _a;
|
|
278
439
|
return ((_a = document.cookie
|
|
279
440
|
.split("; ")
|
|
@@ -284,23 +445,24 @@ var getCookie$1 = function (name) {
|
|
|
284
445
|
.split("=")[1])
|
|
285
446
|
: null;
|
|
286
447
|
};
|
|
287
|
-
var deleteCookie
|
|
448
|
+
var deleteCookie = function (name) {
|
|
288
449
|
document.cookie = name + "=; Max-Age=-99999999; path=/";
|
|
289
450
|
};
|
|
290
451
|
|
|
291
452
|
function useCAMSMSALAuth(options) {
|
|
292
453
|
var _this = this;
|
|
293
|
-
var
|
|
294
|
-
var
|
|
454
|
+
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;
|
|
455
|
+
var storageKey = optStorageKey || "CAMS-MSAL-AUTH-SDK";
|
|
456
|
+
var _b = msalReact.useMsal(), instance = _b.instance, inProgress = _b.inProgress, accounts = _b.accounts;
|
|
295
457
|
var account = msalReact.useAccount(accounts[0] || {});
|
|
296
|
-
var
|
|
297
|
-
var
|
|
298
|
-
var
|
|
299
|
-
var
|
|
300
|
-
var
|
|
458
|
+
var _c = React.useState(null), error = _c[0], setError = _c[1];
|
|
459
|
+
var _d = React.useState(""), idToken = _d[0], setIdToken = _d[1];
|
|
460
|
+
var _e = React.useState(""), accessToken = _e[0], setAccessToken = _e[1];
|
|
461
|
+
var _f = React.useState(null), mfaAuthenticator = _f[0], setMfaAuthenticator = _f[1];
|
|
462
|
+
var _g = React.useState(false), requiresMFA = _g[0], setRequiresMFA = _g[1];
|
|
301
463
|
var isLoading = inProgress !== msalBrowser.InteractionStatus.None;
|
|
302
464
|
var isAuthenticated = !!account && !!accessToken && !requiresMFA;
|
|
303
|
-
var scopes =
|
|
465
|
+
var scopes = optScopes || ["openid", "profile", "email"];
|
|
304
466
|
var isTokenValid = function (token) {
|
|
305
467
|
try {
|
|
306
468
|
var payload = JSON.parse(atob(token.split(".")[1]));
|
|
@@ -324,15 +486,14 @@ function useCAMSMSALAuth(options) {
|
|
|
324
486
|
var mfaConfig = {
|
|
325
487
|
accessToken: accessToken_1,
|
|
326
488
|
idToken: idToken_1,
|
|
327
|
-
appCode:
|
|
489
|
+
appCode: appCode,
|
|
328
490
|
provider: "MSAL",
|
|
329
|
-
apiEndpoint:
|
|
491
|
+
apiEndpoint: MFAEndpoint,
|
|
330
492
|
};
|
|
331
493
|
var authenticator = new camsSdk.CAMSMFAAuthenticator(mfaConfig);
|
|
332
494
|
setMfaAuthenticator(authenticator);
|
|
333
495
|
setRequiresMFA(true);
|
|
334
496
|
}
|
|
335
|
-
camsSdk.Logger.debug("App Code", { ">>>": options.appCode });
|
|
336
497
|
}
|
|
337
498
|
else {
|
|
338
499
|
localStorage.removeItem(storageKey);
|
|
@@ -374,22 +535,26 @@ function useCAMSMSALAuth(options) {
|
|
|
374
535
|
// };
|
|
375
536
|
// handleRedirect();
|
|
376
537
|
// }, []);
|
|
377
|
-
var login = React.useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
538
|
+
var login = React.useCallback(function () { return __awaiter$1(_this, void 0, void 0, function () {
|
|
378
539
|
var response, mfaConfig, authenticator, err_1, camsError_1, camsError;
|
|
379
|
-
var _a
|
|
380
|
-
return __generator(this, function (
|
|
381
|
-
switch (
|
|
540
|
+
var _a;
|
|
541
|
+
return __generator$1(this, function (_b) {
|
|
542
|
+
switch (_b.label) {
|
|
382
543
|
case 0:
|
|
544
|
+
if (inProgress !== msalBrowser.InteractionStatus.None) {
|
|
545
|
+
camsSdk.Logger.warn("Authentication already in progress, ignoring duplicate call");
|
|
546
|
+
return [2 /*return*/];
|
|
547
|
+
}
|
|
383
548
|
setError(null);
|
|
384
|
-
|
|
549
|
+
_b.label = 1;
|
|
385
550
|
case 1:
|
|
386
|
-
|
|
551
|
+
_b.trys.push([1, 3, , 4]);
|
|
387
552
|
return [4 /*yield*/, instance.loginPopup({
|
|
388
553
|
scopes: scopes,
|
|
389
|
-
prompt:
|
|
554
|
+
prompt: prompt || "login",
|
|
390
555
|
})];
|
|
391
556
|
case 2:
|
|
392
|
-
response =
|
|
557
|
+
response = _b.sent();
|
|
393
558
|
console.log("Login Token response:", {
|
|
394
559
|
accessToken: response.accessToken,
|
|
395
560
|
idToken: response.idToken,
|
|
@@ -399,9 +564,9 @@ function useCAMSMSALAuth(options) {
|
|
|
399
564
|
mfaConfig = {
|
|
400
565
|
accessToken: response.accessToken,
|
|
401
566
|
idToken: response.idToken,
|
|
402
|
-
appCode:
|
|
567
|
+
appCode: appCode,
|
|
403
568
|
provider: "MSAL",
|
|
404
|
-
apiEndpoint:
|
|
569
|
+
apiEndpoint: MFAEndpoint,
|
|
405
570
|
};
|
|
406
571
|
authenticator = new camsSdk.CAMSMFAAuthenticator(mfaConfig);
|
|
407
572
|
setMfaAuthenticator(authenticator);
|
|
@@ -415,10 +580,15 @@ function useCAMSMSALAuth(options) {
|
|
|
415
580
|
idToken: response.idToken,
|
|
416
581
|
}));
|
|
417
582
|
}
|
|
418
|
-
|
|
583
|
+
onAuthSuccess === null || onAuthSuccess === void 0 ? void 0 : onAuthSuccess(response.accessToken);
|
|
419
584
|
return [3 /*break*/, 4];
|
|
420
585
|
case 3:
|
|
421
|
-
err_1 =
|
|
586
|
+
err_1 = _b.sent();
|
|
587
|
+
// Handle interaction_in_progress error
|
|
588
|
+
if (err_1.errorCode === "interaction_in_progress") {
|
|
589
|
+
camsSdk.Logger.warn("Interaction already in progress, please wait");
|
|
590
|
+
return [2 /*return*/];
|
|
591
|
+
}
|
|
422
592
|
// Handle user cancellation gracefully
|
|
423
593
|
if (err_1.errorCode === "user_cancelled") {
|
|
424
594
|
camsSdk.Logger.error("User cancelled login");
|
|
@@ -427,22 +597,22 @@ function useCAMSMSALAuth(options) {
|
|
|
427
597
|
}
|
|
428
598
|
// If popup is blocked
|
|
429
599
|
if (err_1.errorCode === "popup_window_error" ||
|
|
430
|
-
((
|
|
600
|
+
((_a = err_1.message) === null || _a === void 0 ? void 0 : _a.includes("popup"))) {
|
|
431
601
|
camsError_1 = new camsSdk.CAMSError(camsSdk.CAMSErrorType.POPUP_BLOCKED, "Popup blocked by browser. Please allow popups and try again.");
|
|
432
602
|
setError(camsError_1);
|
|
433
|
-
|
|
603
|
+
onAuthError === null || onAuthError === void 0 ? void 0 : onAuthError(camsError_1);
|
|
434
604
|
return [2 /*return*/];
|
|
435
605
|
}
|
|
436
606
|
camsError = new camsSdk.CAMSError(camsSdk.CAMSErrorType.API_VALIDATION_ERROR, "Login failed: " + err_1.message || err_1);
|
|
437
607
|
setError(camsError);
|
|
438
|
-
|
|
608
|
+
onAuthError === null || onAuthError === void 0 ? void 0 : onAuthError(camsError);
|
|
439
609
|
return [3 /*break*/, 4];
|
|
440
610
|
case 4: return [2 /*return*/];
|
|
441
611
|
}
|
|
442
612
|
});
|
|
443
|
-
}); }, [instance, scopes,
|
|
444
|
-
var completeMFA = React.useCallback(function (data) { return __awaiter(_this, void 0, void 0, function () {
|
|
445
|
-
return __generator(this, function (_a) {
|
|
613
|
+
}); }, [instance, scopes, prompt, appCode, MFAEndpoint, onAuthSuccess, onAuthError, storageKey, inProgress]);
|
|
614
|
+
var completeMFA = React.useCallback(function (data) { return __awaiter$1(_this, void 0, void 0, function () {
|
|
615
|
+
return __generator$1(this, function (_a) {
|
|
446
616
|
if (!mfaAuthenticator) {
|
|
447
617
|
throw new camsSdk.CAMSError(camsSdk.CAMSErrorType.API_VALIDATION_ERROR, "MFA Authenticator not initialized");
|
|
448
618
|
}
|
|
@@ -456,7 +626,7 @@ function useCAMSMSALAuth(options) {
|
|
|
456
626
|
accessToken: accessToken,
|
|
457
627
|
idToken: idToken,
|
|
458
628
|
}));
|
|
459
|
-
setCookie
|
|
629
|
+
setCookie("CAMS-MSAL-AUTH-SDK-PROFILE", JSON.stringify({ type: "AUTH_SUCCESS", userProfile: __assign({}, data) }), activeCookiePeriod);
|
|
460
630
|
setRequiresMFA(false);
|
|
461
631
|
// Set requiresMFA to false after storage update
|
|
462
632
|
camsSdk.Logger.debug("MFA completed successfully, storage updated", {
|
|
@@ -475,9 +645,9 @@ function useCAMSMSALAuth(options) {
|
|
|
475
645
|
}
|
|
476
646
|
return [2 /*return*/];
|
|
477
647
|
});
|
|
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) {
|
|
648
|
+
}); }, [mfaAuthenticator, accessToken, idToken, storageKey, activeCookiePeriod]);
|
|
649
|
+
var sendEmailOTP = React.useCallback(function () { return __awaiter$1(_this, void 0, void 0, function () {
|
|
650
|
+
return __generator$1(this, function (_a) {
|
|
481
651
|
switch (_a.label) {
|
|
482
652
|
case 0:
|
|
483
653
|
if (!mfaAuthenticator) {
|
|
@@ -488,9 +658,9 @@ function useCAMSMSALAuth(options) {
|
|
|
488
658
|
}
|
|
489
659
|
});
|
|
490
660
|
}); }, [mfaAuthenticator]);
|
|
491
|
-
var logout = React.useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
661
|
+
var logout = React.useCallback(function () { return __awaiter$1(_this, void 0, void 0, function () {
|
|
492
662
|
var err_2, camsError;
|
|
493
|
-
return __generator(this, function (_a) {
|
|
663
|
+
return __generator$1(this, function (_a) {
|
|
494
664
|
switch (_a.label) {
|
|
495
665
|
case 0:
|
|
496
666
|
_a.trys.push([0, 2, , 3]);
|
|
@@ -526,12 +696,13 @@ function useCAMSMSALAuth(options) {
|
|
|
526
696
|
error: error,
|
|
527
697
|
idToken: idToken,
|
|
528
698
|
accessToken: accessToken,
|
|
529
|
-
appCode:
|
|
699
|
+
appCode: appCode,
|
|
530
700
|
mfaAuthenticator: mfaAuthenticator,
|
|
531
701
|
requiresMFA: requiresMFA,
|
|
532
702
|
completeMFA: completeMFA,
|
|
533
703
|
sendEmailOTP: sendEmailOTP,
|
|
534
704
|
setRequiresMFA: setRequiresMFA,
|
|
705
|
+
activeCookiePeriod: activeCookiePeriod,
|
|
535
706
|
};
|
|
536
707
|
}
|
|
537
708
|
|
|
@@ -574,10 +745,10 @@ function arrayBufferToBase64url(buffer) {
|
|
|
574
745
|
* @returns A promise that resolves to a JSON-serializable representation of the PublicKeyCredential.
|
|
575
746
|
*/
|
|
576
747
|
function register(options) {
|
|
577
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
748
|
+
return __awaiter$1(this, void 0, void 0, function () {
|
|
578
749
|
var createOptions, credential, publicKeyCredential, attestationResponse, transports, err_1;
|
|
579
750
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
580
|
-
return __generator(this, function (_k) {
|
|
751
|
+
return __generator$1(this, function (_k) {
|
|
581
752
|
switch (_k.label) {
|
|
582
753
|
case 0:
|
|
583
754
|
_k.trys.push([0, 2, , 3]);
|
|
@@ -635,10 +806,10 @@ function register(options) {
|
|
|
635
806
|
* @returns A promise that resolves to a JSON-serializable representation of the PublicKeyCredential.
|
|
636
807
|
*/
|
|
637
808
|
function authenticate(options) {
|
|
638
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
809
|
+
return __awaiter$1(this, void 0, void 0, function () {
|
|
639
810
|
var getOptions, credential, publicKeyCredential, assertionResponse;
|
|
640
811
|
var _a;
|
|
641
|
-
return __generator(this, function (_b) {
|
|
812
|
+
return __generator$1(this, function (_b) {
|
|
642
813
|
switch (_b.label) {
|
|
643
814
|
case 0:
|
|
644
815
|
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) })); }) });
|
|
@@ -1124,24 +1295,6 @@ function ProtectedRoute(_a) {
|
|
|
1124
1295
|
}
|
|
1125
1296
|
|
|
1126
1297
|
var CAMSMSALContext = React.createContext(null);
|
|
1127
|
-
var setCookie = function (name, value, days) {
|
|
1128
|
-
var expires = new Date(Date.now() + days * 864e5).toUTCString();
|
|
1129
|
-
document.cookie = "".concat(name, "=").concat(encodeURIComponent(value), "; expires=").concat(expires, "; path=/; samesite=Lax");
|
|
1130
|
-
};
|
|
1131
|
-
var getCookie = function (name) {
|
|
1132
|
-
var _a;
|
|
1133
|
-
return ((_a = document.cookie
|
|
1134
|
-
.split("; ")
|
|
1135
|
-
.find(function (row) { return row.startsWith(name + "="); })) === null || _a === void 0 ? void 0 : _a.split("=")[1])
|
|
1136
|
-
? decodeURIComponent(document.cookie
|
|
1137
|
-
.split("; ")
|
|
1138
|
-
.find(function (row) { return row.startsWith(name + "="); })
|
|
1139
|
-
.split("=")[1])
|
|
1140
|
-
: null;
|
|
1141
|
-
};
|
|
1142
|
-
var deleteCookie = function (name) {
|
|
1143
|
-
document.cookie = name + "=; Max-Age=-99999999; path=/";
|
|
1144
|
-
};
|
|
1145
1298
|
var isTokenValid = function (token) {
|
|
1146
1299
|
try {
|
|
1147
1300
|
var payload = JSON.parse(atob(token.split(".")[1]));
|
|
@@ -1190,7 +1343,7 @@ function CAMSMSALProviderInner(_a) {
|
|
|
1190
1343
|
localStorage.setItem(auth.storageKey, JSON.stringify({
|
|
1191
1344
|
accessToken: auth.accessToken,
|
|
1192
1345
|
idToken: auth.idToken,
|
|
1193
|
-
appCode: auth.appCode
|
|
1346
|
+
appCode: auth.appCode,
|
|
1194
1347
|
}));
|
|
1195
1348
|
}
|
|
1196
1349
|
}, [auth.accessToken, auth.idToken, auth.storageKey]);
|
|
@@ -1206,8 +1359,8 @@ function CAMSMSALProviderInner(_a) {
|
|
|
1206
1359
|
}
|
|
1207
1360
|
}, [userProfile, profileStorageKey]);
|
|
1208
1361
|
// Enhanced logout that also clears profile
|
|
1209
|
-
var enhancedLogout = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
1210
|
-
return __generator(this, function (_a) {
|
|
1362
|
+
var enhancedLogout = function () { return __awaiter$1(_this, void 0, void 0, function () {
|
|
1363
|
+
return __generator$1(this, function (_a) {
|
|
1211
1364
|
switch (_a.label) {
|
|
1212
1365
|
case 0: return [4 /*yield*/, auth.logout()];
|
|
1213
1366
|
case 1:
|
|
@@ -1274,7 +1427,7 @@ function CAMSProviderCore(props) {
|
|
|
1274
1427
|
if (typeof window === "undefined")
|
|
1275
1428
|
return null;
|
|
1276
1429
|
try {
|
|
1277
|
-
var storedProfile = getCookie
|
|
1430
|
+
var storedProfile = getCookie(profileStorageKey);
|
|
1278
1431
|
return storedProfile ? JSON.parse(storedProfile) : null;
|
|
1279
1432
|
}
|
|
1280
1433
|
catch (_a) {
|
|
@@ -1284,7 +1437,7 @@ function CAMSProviderCore(props) {
|
|
|
1284
1437
|
var _a = React.useState(getInitialProfile), userProfile = _a[0], setUserProfile = _a[1];
|
|
1285
1438
|
React.useEffect(function () {
|
|
1286
1439
|
if (typeof window !== "undefined") {
|
|
1287
|
-
var storedProfile = getCookie
|
|
1440
|
+
var storedProfile = getCookie(profileStorageKey);
|
|
1288
1441
|
if (storedProfile) {
|
|
1289
1442
|
try {
|
|
1290
1443
|
setUserProfile(JSON.parse(storedProfile));
|
|
@@ -1296,22 +1449,22 @@ function CAMSProviderCore(props) {
|
|
|
1296
1449
|
React.useEffect(function () {
|
|
1297
1450
|
if (typeof window !== "undefined") {
|
|
1298
1451
|
if (userProfile) {
|
|
1299
|
-
setCookie
|
|
1452
|
+
setCookie(profileStorageKey, JSON.stringify(userProfile), 1);
|
|
1300
1453
|
}
|
|
1301
1454
|
else {
|
|
1302
|
-
deleteCookie
|
|
1455
|
+
deleteCookie(profileStorageKey);
|
|
1303
1456
|
}
|
|
1304
1457
|
}
|
|
1305
1458
|
}, [userProfile, profileStorageKey]);
|
|
1306
|
-
var enhancedLogout = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
1307
|
-
return __generator(this, function (_a) {
|
|
1459
|
+
var enhancedLogout = function () { return __awaiter$1(_this, void 0, void 0, function () {
|
|
1460
|
+
return __generator$1(this, function (_a) {
|
|
1308
1461
|
switch (_a.label) {
|
|
1309
1462
|
case 0: return [4 /*yield*/, auth.logout()];
|
|
1310
1463
|
case 1:
|
|
1311
1464
|
_a.sent();
|
|
1312
1465
|
setUserProfile(null);
|
|
1313
1466
|
if (typeof window !== "undefined") {
|
|
1314
|
-
deleteCookie
|
|
1467
|
+
deleteCookie(profileStorageKey);
|
|
1315
1468
|
}
|
|
1316
1469
|
return [2 /*return*/];
|
|
1317
1470
|
}
|
|
@@ -1347,7 +1500,8 @@ function CAMSProviderCore(props) {
|
|
|
1347
1500
|
userProfile,
|
|
1348
1501
|
]);
|
|
1349
1502
|
var value = React.useMemo(function () {
|
|
1350
|
-
|
|
1503
|
+
auth.logout; var authRest = __rest(auth, ["logout"]);
|
|
1504
|
+
return __assign(__assign({}, authRest), { logout: enhancedLogout, userProfile: userProfile, setUserProfile: setUserProfile, authMode: mode });
|
|
1351
1505
|
}, [auth, userProfile, mode]);
|
|
1352
1506
|
return jsxRuntimeExports.jsx(CAMSContext.Provider, { value: value, children: children });
|
|
1353
1507
|
}
|
|
@@ -1355,7 +1509,7 @@ function UnifiedCAMSProvider(props) {
|
|
|
1355
1509
|
// Validate appCode is a valid GUID
|
|
1356
1510
|
var appCodeValidation = GuidSchema.safeParse(props.appCode);
|
|
1357
1511
|
if (!appCodeValidation.success) {
|
|
1358
|
-
throw new Error("Invalid
|
|
1512
|
+
throw new Error("Invalid CAS APP CODE: ".concat(appCodeValidation.error.issues[0].message));
|
|
1359
1513
|
}
|
|
1360
1514
|
if (props.mode === "MSAL") {
|
|
1361
1515
|
var msalConfig = props.msalConfig, msalInstance = props.msalInstance;
|
|
@@ -1723,7 +1877,7 @@ styleInject(css_248z);
|
|
|
1723
1877
|
|
|
1724
1878
|
var LoadingSpinner = function (_a) {
|
|
1725
1879
|
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..." }))] }));
|
|
1880
|
+
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
1881
|
};
|
|
1728
1882
|
|
|
1729
1883
|
var AuthSuccessAnimation = function (_a) {
|
|
@@ -1775,15 +1929,36 @@ var APIHeaders = {
|
|
|
1775
1929
|
"X-API-VERSION": "1.0",
|
|
1776
1930
|
};
|
|
1777
1931
|
|
|
1932
|
+
// Creates an Axios instance with a base URL determined by the environment (production or development).
|
|
1933
|
+
var axiosInstance = axios.create({
|
|
1934
|
+
httpsAgent: new https.Agent({ rejectUnauthorized: false }),
|
|
1935
|
+
headers: __assign({ "Content-Type": "application/json" }, APIHeaders),
|
|
1936
|
+
});
|
|
1937
|
+
// Intercepts outgoing requests to add authorization token, version header, and timeout settings.
|
|
1938
|
+
axiosInstance.interceptors.request.use(function (config) {
|
|
1939
|
+
var _a;
|
|
1940
|
+
config.timeout = Number((_a = process.env.NEXT_PUBLIC_API_TIMEOUT) !== null && _a !== void 0 ? _a : 605000);
|
|
1941
|
+
config.timeoutErrorMessage = "Operation Timed Out"; // Custom error message for timeouts.
|
|
1942
|
+
return config; // Returns the modified request configuration.
|
|
1943
|
+
}, function (axiosError) {
|
|
1944
|
+
var _a, _b;
|
|
1945
|
+
// Handles request errors.
|
|
1946
|
+
return {
|
|
1947
|
+
status: (_a = axiosError.response) === null || _a === void 0 ? void 0 : _a.status, // Extracts HTTP status from the error response.
|
|
1948
|
+
message: axiosError.message, // Extracts the error message.
|
|
1949
|
+
data: (_b = axiosError.response) === null || _b === void 0 ? void 0 : _b.data, // Extracts response data from the error.
|
|
1950
|
+
};
|
|
1951
|
+
});
|
|
1952
|
+
|
|
1778
1953
|
var MAX_ATTEMPTS = 3;
|
|
1779
1954
|
var useOTPHandler = function (_a) {
|
|
1780
1955
|
var provider = _a.provider, accessToken = _a.accessToken, idToken = _a.idToken, appCode = _a.appCode, authenticationType = _a.authenticationType, MFAEndpoint = _a.MFAEndpoint, onAuthComplete = _a.onAuthComplete;
|
|
1781
1956
|
var _b = React.useState(false), loading = _b[0], setLoading = _b[1];
|
|
1782
1957
|
var _c = React.useState(0), attemptCount = _c[0], setAttemptCount = _c[1];
|
|
1783
1958
|
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 () {
|
|
1959
|
+
var handleSubmitOTP = React.useMemo(function () { return function (authenticationValue) { return __awaiter$1(void 0, void 0, void 0, function () {
|
|
1785
1960
|
var currentAttempt, response, error_1, currentAttempt;
|
|
1786
|
-
return __generator(this, function (_a) {
|
|
1961
|
+
return __generator$1(this, function (_a) {
|
|
1787
1962
|
switch (_a.label) {
|
|
1788
1963
|
case 0:
|
|
1789
1964
|
if (isMaxAttemptsReached) {
|
|
@@ -1800,16 +1975,13 @@ var useOTPHandler = function (_a) {
|
|
|
1800
1975
|
setAttemptCount(currentAttempt);
|
|
1801
1976
|
if (authenticationType === null)
|
|
1802
1977
|
return [2 /*return*/, false];
|
|
1803
|
-
return [4 /*yield*/,
|
|
1978
|
+
return [4 /*yield*/, axiosInstance.post(MFAEndpoint || "/api/auth/verify-mfa", {
|
|
1804
1979
|
provider: provider,
|
|
1805
1980
|
accessToken: accessToken,
|
|
1806
1981
|
idToken: idToken,
|
|
1807
1982
|
authenticationType: authenticationType,
|
|
1808
1983
|
MFACode: authenticationValue,
|
|
1809
1984
|
appCode: appCode,
|
|
1810
|
-
}, {
|
|
1811
|
-
headers: APIHeaders,
|
|
1812
|
-
timeout: 605000,
|
|
1813
1985
|
})];
|
|
1814
1986
|
case 2:
|
|
1815
1987
|
response = (_a.sent()).data;
|
|
@@ -1876,23 +2048,20 @@ var useCredentialsHandler = function (onAuthComplete) {
|
|
|
1876
2048
|
var _b = React.useState(0), attemptCount = _b[0], setAttemptCount = _b[1];
|
|
1877
2049
|
var _c = React.useState(false), isMaxAttemptsReached = _c[0], setIsMaxAttemptsReached = _c[1];
|
|
1878
2050
|
var handleSubmitCredentials = React.useMemo(function () {
|
|
1879
|
-
return function (CredAuthEndpoint, credentials, appCode) { return __awaiter(void 0, void 0, void 0, function () {
|
|
2051
|
+
return function (CredAuthEndpoint, credentials, appCode) { return __awaiter$1(void 0, void 0, void 0, function () {
|
|
1880
2052
|
var currentAttempt, response, error_2, currentAttempt;
|
|
1881
|
-
return __generator(this, function (_a) {
|
|
2053
|
+
return __generator$1(this, function (_a) {
|
|
1882
2054
|
switch (_a.label) {
|
|
1883
2055
|
case 0:
|
|
1884
2056
|
_a.trys.push([0, 2, 3, 4]);
|
|
1885
2057
|
setLoading(true);
|
|
1886
2058
|
currentAttempt = attemptCount + 1;
|
|
1887
2059
|
setAttemptCount(currentAttempt);
|
|
1888
|
-
return [4 /*yield*/,
|
|
2060
|
+
return [4 /*yield*/, axiosInstance.post(CredAuthEndpoint, {
|
|
1889
2061
|
username: credentials.username,
|
|
1890
2062
|
password: credentials.password,
|
|
1891
2063
|
MFACode: credentials.MFACode,
|
|
1892
2064
|
appCode: appCode,
|
|
1893
|
-
}, {
|
|
1894
|
-
headers: APIHeaders,
|
|
1895
|
-
timeout: 605000,
|
|
1896
2065
|
})];
|
|
1897
2066
|
case 1:
|
|
1898
2067
|
response = (_a.sent()).data;
|
|
@@ -1953,23 +2122,21 @@ var MFAOptions = function (_a) {
|
|
|
1953
2122
|
var context = useCAMSContext();
|
|
1954
2123
|
var _f = context.authMode === "MSAL" && "sendEmailOTP" in context
|
|
1955
2124
|
? context
|
|
1956
|
-
: { sendEmailOTP: null, completeMFA: null, logout: function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
2125
|
+
: { sendEmailOTP: null, completeMFA: null, logout: function () { return __awaiter$1(void 0, void 0, void 0, function () { return __generator$1(this, function (_a) {
|
|
1957
2126
|
return [2 /*return*/];
|
|
1958
2127
|
}); }); } }, sendEmailOTP = _f.sendEmailOTP, completeMFA = _f.completeMFA, logout = _f.logout;
|
|
1959
2128
|
var accessToken = context.authMode === "MSAL" ? context.accessToken : "";
|
|
1960
2129
|
var idToken = context.authMode === "MSAL" ? context.idToken : "";
|
|
1961
2130
|
var authenticate = useWebAuthn().authenticate;
|
|
1962
|
-
var handleFIDOLogin = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
2131
|
+
var handleFIDOLogin = function () { return __awaiter$1(void 0, void 0, void 0, function () {
|
|
1963
2132
|
var options, assertionResponse, error_1;
|
|
1964
|
-
return __generator(this, function (_a) {
|
|
2133
|
+
return __generator$1(this, function (_a) {
|
|
1965
2134
|
switch (_a.label) {
|
|
1966
2135
|
case 0:
|
|
1967
2136
|
_a.trys.push([0, 4, , 5]);
|
|
1968
2137
|
// 1. Fetch authentication challenge from your server
|
|
1969
2138
|
console.log("Requesting authentication challenge from server...");
|
|
1970
|
-
return [4 /*yield*/,
|
|
1971
|
-
headers: APIHeaders,
|
|
1972
|
-
})];
|
|
2139
|
+
return [4 /*yield*/, axiosInstance.post(MFAEndpoints.RetrieveAuthChallenge, {})];
|
|
1973
2140
|
case 1:
|
|
1974
2141
|
options = (_a.sent()).data;
|
|
1975
2142
|
console.log("Received challenge:", options);
|
|
@@ -1981,9 +2148,7 @@ var MFAOptions = function (_a) {
|
|
|
1981
2148
|
console.log("Authentication assertion received from client:", assertionResponse);
|
|
1982
2149
|
// 3. Send the assertion back to the server for verification
|
|
1983
2150
|
console.log("Sending assertion to server for verification...");
|
|
1984
|
-
return [4 /*yield*/,
|
|
1985
|
-
headers: APIHeaders
|
|
1986
|
-
})];
|
|
2151
|
+
return [4 /*yield*/, axiosInstance.post(MFAEndpoints.AuthChallengeVerify, assertionResponse)];
|
|
1987
2152
|
case 3:
|
|
1988
2153
|
_a.sent();
|
|
1989
2154
|
sonner.toast.success("🔑 Sign-in successful!");
|
|
@@ -2045,12 +2210,12 @@ var MFAOptions = function (_a) {
|
|
|
2045
2210
|
}
|
|
2046
2211
|
var content = jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, {});
|
|
2047
2212
|
if (!authType) {
|
|
2048
|
-
content = (jsxRuntimeExports.jsxs("div", { className: "space-y-4", children: [jsxRuntimeExports.jsx("p", { className: "text-sm text-gray-600 text-center mb-6", children: "Choose your preferred authentication method:" }), jsxRuntimeExports.jsxs("div", { className: "flex flex-col gap-3", children: [jsxRuntimeExports.jsxs(Button, { variant: "outline", className: "w-full flex items-center justify-start gap-3 p-4 h-auto border-2 hover:border-[#506f4a] hover:bg-[#506f4a]/5 transition-all", onClick: function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
2213
|
+
content = (jsxRuntimeExports.jsxs("div", { className: "space-y-4", children: [jsxRuntimeExports.jsx("p", { className: "text-sm text-gray-600 text-center mb-6", children: "Choose your preferred authentication method:" }), jsxRuntimeExports.jsxs("div", { className: "flex flex-col gap-3", children: [jsxRuntimeExports.jsxs(Button, { variant: "outline", className: "w-full flex items-center justify-start gap-3 p-4 h-auto border-2 hover:border-[#506f4a] hover:bg-[#506f4a]/5 transition-all", onClick: function () { return __awaiter$1(void 0, void 0, void 0, function () {
|
|
2049
2214
|
var success;
|
|
2050
|
-
return __generator(this, function (_a) {
|
|
2215
|
+
return __generator$1(this, function (_a) {
|
|
2051
2216
|
switch (_a.label) {
|
|
2052
2217
|
case 0:
|
|
2053
|
-
resetAttempts();
|
|
2218
|
+
// resetAttempts();
|
|
2054
2219
|
setAuthType("EmailOTP");
|
|
2055
2220
|
setOtpVisible(true);
|
|
2056
2221
|
if (!sendEmailOTP) return [3 /*break*/, 2];
|
|
@@ -2067,7 +2232,6 @@ var MFAOptions = function (_a) {
|
|
|
2067
2232
|
}
|
|
2068
2233
|
});
|
|
2069
2234
|
}); }, children: [jsxRuntimeExports.jsx(lucideReact.Mail, { className: "w-5 h-5" }), jsxRuntimeExports.jsxs("div", { className: "text-left", children: [jsxRuntimeExports.jsx("div", { className: "font-medium", children: "Email OTP" }), jsxRuntimeExports.jsx("div", { className: "text-sm text-gray-500", children: "Send code to your email" })] })] }), jsxRuntimeExports.jsxs(Button, { variant: "outline", className: "w-full flex items-center justify-start gap-3 p-4 h-auto border-2 hover:border-[#506f4a] hover:bg-[#506f4a]/5 transition-all", onClick: function () {
|
|
2070
|
-
resetAttempts();
|
|
2071
2235
|
setAuthType("AuthenticatorCode");
|
|
2072
2236
|
setOtpVisible(true);
|
|
2073
2237
|
}, children: [jsxRuntimeExports.jsx("img", { src: MicrosoftAuthenticatorImg, alt: "Authenticator", className: "rounded-full", width: 24, height: 24, onError: function () { return jsxRuntimeExports.jsx(lucideReact.Shield, {}); } }), jsxRuntimeExports.jsxs("div", { className: "text-left", children: [jsxRuntimeExports.jsx("div", { className: "font-medium", children: "Authenticator App" }), jsxRuntimeExports.jsx("div", { className: "text-sm text-gray-500", children: "Use Authenticator App" })] })] }), usePassKey && (jsxRuntimeExports.jsxs(Button, { variant: "outline", className: "w-full flex items-center justify-start gap-3 p-4 h-auto border-2 hover:border-[#506f4a] hover:bg-[#506f4a]/5 transition-all",
|
|
@@ -2076,7 +2240,7 @@ var MFAOptions = function (_a) {
|
|
|
2076
2240
|
// setAuthType("AuthenticatorCode");
|
|
2077
2241
|
// setOtpVisible(true);
|
|
2078
2242
|
// }}
|
|
2079
|
-
onClick: handleFIDOLogin, disabled: context.isLoading, children: [jsxRuntimeExports.jsx(
|
|
2243
|
+
onClick: handleFIDOLogin, disabled: context.isLoading, children: [jsxRuntimeExports.jsx(lucideReact.KeyIcon, { className: "text-[#506f4a]", size: 48 }), jsxRuntimeExports.jsxs("div", { className: "text-left", children: [jsxRuntimeExports.jsx("div", { className: "font-medium", children: "Continue with Passkey" }), jsxRuntimeExports.jsx("div", { className: "text-sm text-gray-500", children: "Passkey" })] })] }))] })] }));
|
|
2080
2244
|
}
|
|
2081
2245
|
else if (authType === "EmailOTP") {
|
|
2082
2246
|
content = (jsxRuntimeExports.jsx(Dialog, { open: otpVisible, onOpenChange: function () {
|
|
@@ -2119,16 +2283,16 @@ var ADLoginModal = function (_a) {
|
|
|
2119
2283
|
resolver: a$1(credentialsSchema),
|
|
2120
2284
|
defaultValues: { username: "", password: "" },
|
|
2121
2285
|
});
|
|
2122
|
-
var handleCredentialsSubmit = function (values) { return __awaiter(void 0, void 0, void 0, function () {
|
|
2123
|
-
return __generator(this, function (_a) {
|
|
2286
|
+
var handleCredentialsSubmit = function (values) { return __awaiter$1(void 0, void 0, void 0, function () {
|
|
2287
|
+
return __generator$1(this, function (_a) {
|
|
2124
2288
|
setCredentials(values);
|
|
2125
2289
|
setStep("mfa");
|
|
2126
2290
|
return [2 /*return*/];
|
|
2127
2291
|
});
|
|
2128
2292
|
}); };
|
|
2129
|
-
var handleMFASubmit = function (code) { return __awaiter(void 0, void 0, void 0, function () {
|
|
2293
|
+
var handleMFASubmit = function (code) { return __awaiter$1(void 0, void 0, void 0, function () {
|
|
2130
2294
|
var error_1;
|
|
2131
|
-
return __generator(this, function (_a) {
|
|
2295
|
+
return __generator$1(this, function (_a) {
|
|
2132
2296
|
switch (_a.label) {
|
|
2133
2297
|
case 0:
|
|
2134
2298
|
setIsLoading(true);
|
|
@@ -2189,8 +2353,8 @@ var DefaultLoginPage = function (_a) {
|
|
|
2189
2353
|
var login = context.login, isLoading = context.isLoading, authMode = context.authMode;
|
|
2190
2354
|
var _b = React.useState(false), showADModal = _b[0], setShowADModal = _b[1];
|
|
2191
2355
|
var register = useWebAuthn().register;
|
|
2192
|
-
var _c = useCredentialsHandler(function (state, data) { return __awaiter(void 0, void 0, void 0, function () {
|
|
2193
|
-
return __generator(this, function (_a) {
|
|
2356
|
+
var _c = useCredentialsHandler(function (state, data) { return __awaiter$1(void 0, void 0, void 0, function () {
|
|
2357
|
+
return __generator$1(this, function (_a) {
|
|
2194
2358
|
console.log(data);
|
|
2195
2359
|
if (state && data) {
|
|
2196
2360
|
context.isAuthenticated = true;
|
|
@@ -2204,6 +2368,10 @@ var DefaultLoginPage = function (_a) {
|
|
|
2204
2368
|
});
|
|
2205
2369
|
}); }), handleSubmitCredentials = _c.handleSubmitCredentials, isCredAuthLoading = _c.loading, setIsCredAuthLoading = _c.setLoading;
|
|
2206
2370
|
var handleMSALLogin = function () {
|
|
2371
|
+
if (typeof window !== "undefined" && !window.crypto) {
|
|
2372
|
+
sonner.toast.error("Crypto API not available. Please use a modern browser.");
|
|
2373
|
+
return;
|
|
2374
|
+
}
|
|
2207
2375
|
if (authMode === "MSAL") {
|
|
2208
2376
|
login();
|
|
2209
2377
|
}
|
|
@@ -2212,17 +2380,15 @@ var DefaultLoginPage = function (_a) {
|
|
|
2212
2380
|
console.warn("Regular CAMS login requires configuration");
|
|
2213
2381
|
}
|
|
2214
2382
|
};
|
|
2215
|
-
var handleRegister = function (data) { return __awaiter(void 0, void 0, void 0, function () {
|
|
2383
|
+
var handleRegister = function (data) { return __awaiter$1(void 0, void 0, void 0, function () {
|
|
2216
2384
|
var options, attestationResponse, error_1;
|
|
2217
|
-
return __generator(this, function (_a) {
|
|
2385
|
+
return __generator$1(this, function (_a) {
|
|
2218
2386
|
switch (_a.label) {
|
|
2219
2387
|
case 0:
|
|
2220
2388
|
_a.trys.push([0, 4, , 5]);
|
|
2221
2389
|
// 1. Fetch challenge from your server
|
|
2222
2390
|
console.log("Requesting registration challenge from server...");
|
|
2223
|
-
return [4 /*yield*/,
|
|
2224
|
-
headers: APIHeaders,
|
|
2225
|
-
})];
|
|
2391
|
+
return [4 /*yield*/, axiosInstance.post(MFAEndpoints.RegisterNewChallenge, __assign({}, data))];
|
|
2226
2392
|
case 1:
|
|
2227
2393
|
options = (_a.sent()).data;
|
|
2228
2394
|
console.log("Received challenge:", options);
|
|
@@ -2234,9 +2400,7 @@ var DefaultLoginPage = function (_a) {
|
|
|
2234
2400
|
console.log("Passkey created on client:", attestationResponse);
|
|
2235
2401
|
// 3. Send the response back to the server for verification
|
|
2236
2402
|
console.log("Sending attestation to server for verification...");
|
|
2237
|
-
return [4 /*yield*/,
|
|
2238
|
-
headers: APIHeaders
|
|
2239
|
-
})];
|
|
2403
|
+
return [4 /*yield*/, axiosInstance.post(MFAEndpoints.RegisterVerify + "?username=".concat(data.username), attestationResponse)];
|
|
2240
2404
|
case 3:
|
|
2241
2405
|
_a.sent();
|
|
2242
2406
|
sonner.toast.success("✅ Registration successful! Passkey created.");
|
|
@@ -2250,15 +2414,15 @@ var DefaultLoginPage = function (_a) {
|
|
|
2250
2414
|
}
|
|
2251
2415
|
});
|
|
2252
2416
|
}); };
|
|
2253
|
-
return (jsxRuntimeExports.jsxs("main", { className: "min-h-screen bg-gray-50", children: [jsxRuntimeExports.jsx(framerMotion.motion.div, { initial: { opacity: 0 }, animate: { opacity: 1 }, exit: { opacity: 0 }, transition: { duration: 0.5 }, children: jsxRuntimeExports.jsx("div", { className: "flex h-screen items-center justify-center", children: jsxRuntimeExports.jsxs(framerMotion.motion.div, { variants: cardVariants, initial: "hidden", animate: "visible", exit: "exit", className: "w-full max-w-md p-6 space-y-4 bg-gray-50 rounded-2xl shadow-2xl --dark:bg-gray-800", children: [jsxRuntimeExports.jsxs(CardHeader, { className: "text-center space-y-3", children: [jsxRuntimeExports.jsx("div", { className: "w-full flex items-center justify-center", children: jsxRuntimeExports.jsx("img", { src: NIBSSLogo, alt: "NIBSS Logo", width: 265, height: 265 }) }), jsxRuntimeExports.jsx(CardTitle, { className: "text-3xl font-bold --text-gray-900 --dark:text-white", children: "NIBSS CAMS" }), jsxRuntimeExports.jsx(CardTitle, { className: "text-gray-500 dark:text-gray-400 font-bold text-lg", children: "Centralized Authentication" })] }), jsxRuntimeExports.jsxs(CardAction, { className: "w-full flex flex-col items-center justify-center text-center text-gray-500 dark:text-gray-400 mb-
|
|
2417
|
+
return (jsxRuntimeExports.jsxs("main", { className: "min-h-screen bg-gray-50", children: [jsxRuntimeExports.jsx(framerMotion.motion.div, { initial: { opacity: 0 }, animate: { opacity: 1 }, exit: { opacity: 0 }, transition: { duration: 0.5 }, children: jsxRuntimeExports.jsx("div", { className: "flex h-screen items-center justify-center", children: jsxRuntimeExports.jsxs(framerMotion.motion.div, { variants: cardVariants, initial: "hidden", animate: "visible", exit: "exit", className: "w-full max-w-md p-6 space-y-4 bg-gray-50 rounded-2xl shadow-2xl --dark:bg-gray-800", children: [jsxRuntimeExports.jsxs(CardHeader, { className: "text-center space-y-3", children: [jsxRuntimeExports.jsx("div", { className: "w-full flex items-center justify-center", children: jsxRuntimeExports.jsx("img", { src: NIBSSLogo, alt: "NIBSS Logo", width: 265, height: 265 }) }), jsxRuntimeExports.jsx(CardTitle, { className: "text-3xl font-bold --text-gray-900 --dark:text-white", children: "NIBSS CAMS" }), jsxRuntimeExports.jsx(CardTitle, { className: "text-gray-500 dark:text-gray-400 font-bold text-lg", children: "Centralized Authentication" })] }), jsxRuntimeExports.jsxs(CardAction, { className: "w-full flex flex-col items-center justify-center text-center text-gray-500 dark:text-gray-400 mb-8", children: [jsxRuntimeExports.jsx("img", { src: AuthLogo, alt: "Auth Logo", width: 365, height: 365 }), "Use Below Identity Providers To Authenticate"] }), jsxRuntimeExports.jsxs("div", { className: "space-y-4", children: [jsxRuntimeExports.jsxs(Button
|
|
2254
2418
|
// variant="outline"
|
|
2255
2419
|
, {
|
|
2256
2420
|
// variant="outline"
|
|
2257
2421
|
className: "w-full flex items-center justify-center cursor-pointer bg-[#506f4a] hover:bg-[#506f4a] rounded-lg border border-transparent px-5 py-8 text-base font-medium transition-colors duration-250", onClick: handleMSALLogin, disabled: isLoading, children: [jsxRuntimeExports.jsx("img", { src: MicrosoftLogo, alt: "Microsoft Logo", width: 35, height: 35 }), jsxRuntimeExports.jsx("span", { className: "ml-2", children: isLoading ? "Logging in..." : "Sign in with Microsoft" })] }), useADLogin && (jsxRuntimeExports.jsxs(Button, { className: "w-full flex items-center justify-center cursor-pointer bg-[#506f4a] hover:bg-[#506f4a] rounded-lg border border-transparent px-5 py-8 text-base font-medium transition-colors duration-250", onClick: function () { return setShowADModal(true); }, disabled: isLoading, children: [jsxRuntimeExports.jsx(lucideReact.KeyIcon, { className: "text-[#506f4a]", size: 64 }), jsxRuntimeExports.jsx("span", { children: isLoading
|
|
2258
2422
|
? "Logging in..."
|
|
2259
|
-
: "Sign in with ActiveDirectory" })] })), usePassKey && (jsxRuntimeExports.jsxs(Button, { className: "w-full flex items-center justify-center cursor-pointer bg-[#506f4a] hover:bg-[#506f4a] rounded-lg border border-transparent px-5 py-8 text-base font-medium transition-colors duration-250", onClick: function () { return handleRegister(PassKeysRegisterProps); }, disabled: isLoading, children: [jsxRuntimeExports.jsx(lucideReact.KeyIcon, { className: "text-[#506f4a]", size: 64 }), jsxRuntimeExports.jsx("span", { children: "Create a Passkey" })] }))] }), jsxRuntimeExports.jsxs(CardFooter, { className: "flex items-center justify-center mt-6 space-x-2 text-gray-400 text-sm", children: [jsxRuntimeExports.jsx(lucideReact.ShieldCheck, { className: "w-4 h-4 text-[#506f4a] pulse-glow" }), jsxRuntimeExports.jsx("span", { children: "Powered By NIBSS" })] })] }) }) }, "landing"), jsxRuntimeExports.jsx(ADLoginModal, { open: showADModal, onOpenChange: setShowADModal, isLoading: isCredAuthLoading, setIsLoading: setIsCredAuthLoading, onLogin: function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
|
|
2423
|
+
: "Sign in with ActiveDirectory" })] })), usePassKey && (jsxRuntimeExports.jsxs(Button, { className: "w-full flex items-center justify-center cursor-pointer bg-[#506f4a] hover:bg-[#506f4a] rounded-lg border border-transparent px-5 py-8 text-base font-medium transition-colors duration-250", onClick: function () { return handleRegister(PassKeysRegisterProps); }, disabled: isLoading, children: [jsxRuntimeExports.jsx(lucideReact.KeyIcon, { className: "text-[#506f4a]", size: 64 }), jsxRuntimeExports.jsx("span", { children: "Create a Passkey" })] }))] }), jsxRuntimeExports.jsxs(CardFooter, { className: "flex items-center justify-center mt-6 space-x-2 text-gray-400 text-sm", children: [jsxRuntimeExports.jsx(lucideReact.ShieldCheck, { className: "w-4 h-4 text-[#506f4a] pulse-glow" }), jsxRuntimeExports.jsx("span", { children: "Powered By NIBSS" })] })] }) }) }, "landing"), jsxRuntimeExports.jsx(ADLoginModal, { open: showADModal, onOpenChange: setShowADModal, isLoading: isCredAuthLoading, setIsLoading: setIsCredAuthLoading, onLogin: function (_a) { return __awaiter$1(void 0, [_a], void 0, function (_b) {
|
|
2260
2424
|
var username = _b.username, password = _b.password, MFACode = _b.MFACode;
|
|
2261
|
-
return __generator(this, function (_c) {
|
|
2425
|
+
return __generator$1(this, function (_c) {
|
|
2262
2426
|
// Implement your AD login logic here
|
|
2263
2427
|
console.log("AD Login:", { username: username, password: password, MFACode: MFACode });
|
|
2264
2428
|
// Example: await adLoginService(username, password, mfaCode);
|
|
@@ -2299,8 +2463,8 @@ var MFAGate = function (_a) {
|
|
|
2299
2463
|
if (!success)
|
|
2300
2464
|
camsSdk.Logger.error("MFA authentication failed");
|
|
2301
2465
|
}, []);
|
|
2302
|
-
var handleAuthFailed = React.useCallback(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
2303
|
-
return __generator(this, function (_a) {
|
|
2466
|
+
var handleAuthFailed = React.useCallback(function () { return __awaiter$1(void 0, void 0, void 0, function () {
|
|
2467
|
+
return __generator$1(this, function (_a) {
|
|
2304
2468
|
switch (_a.label) {
|
|
2305
2469
|
case 0: return [4 /*yield*/, context.logout()];
|
|
2306
2470
|
case 1:
|
|
@@ -2309,7 +2473,6 @@ var MFAGate = function (_a) {
|
|
|
2309
2473
|
}
|
|
2310
2474
|
});
|
|
2311
2475
|
}); }, [context.logout]);
|
|
2312
|
-
camsSdk.Logger.debug("MFA Endpoint >>>", { MFAEndpoints: MFAEndpoints });
|
|
2313
2476
|
if (useADLogin && !CredentialsAuthEndpoint)
|
|
2314
2477
|
return jsxRuntimeExports.jsx(ErrorFallback, { message: "Invalid AD Login Configuration." });
|
|
2315
2478
|
if (!validatedMFAEndpoints)
|