@nibssplc/cams-sdk-react 1.0.0-rc.3 → 1.0.0-rc.31
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 +282 -128
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.esm.js +282 -128
- 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,157 @@ 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
|
+
try {
|
|
49
|
+
Object.defineProperty(window, 'crypto', {
|
|
50
|
+
value: {},
|
|
51
|
+
writable: true,
|
|
52
|
+
configurable: true
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
catch (e) {
|
|
56
|
+
// Ignore if crypto cannot be defined
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
// Polyfill getRandomValues
|
|
60
|
+
if (window.crypto && !window.crypto.getRandomValues) {
|
|
61
|
+
try {
|
|
62
|
+
Object.defineProperty(window.crypto, 'getRandomValues', {
|
|
63
|
+
value: function (array) {
|
|
64
|
+
var bytes = new Uint8Array(array.buffer, array.byteOffset, array.byteLength);
|
|
65
|
+
for (var i = 0; i < bytes.length; i++) {
|
|
66
|
+
bytes[i] = Math.floor(Math.random() * 256);
|
|
67
|
+
}
|
|
68
|
+
return array;
|
|
69
|
+
},
|
|
70
|
+
writable: true,
|
|
71
|
+
configurable: true
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
catch (e) {
|
|
75
|
+
// Ignore if getRandomValues cannot be defined
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
// Force polyfill crypto.subtle on localhost and non-HTTPS contexts
|
|
79
|
+
if (window.crypto) {
|
|
80
|
+
var sha256_1 = function (data) { return __awaiter(void 0, void 0, void 0, function () {
|
|
81
|
+
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;
|
|
82
|
+
return __generator(this, function (_a) {
|
|
83
|
+
bytes = new Uint8Array(data);
|
|
84
|
+
hash = new Uint32Array(8);
|
|
85
|
+
k = new Uint32Array([
|
|
86
|
+
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
|
|
87
|
+
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
|
|
88
|
+
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
|
|
89
|
+
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
|
|
90
|
+
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
|
|
91
|
+
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
|
|
92
|
+
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
|
|
93
|
+
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
|
|
94
|
+
]);
|
|
95
|
+
hash[0] = 0x6a09e667;
|
|
96
|
+
hash[1] = 0xbb67ae85;
|
|
97
|
+
hash[2] = 0x3c6ef372;
|
|
98
|
+
hash[3] = 0xa54ff53a;
|
|
99
|
+
hash[4] = 0x510e527f;
|
|
100
|
+
hash[5] = 0x9b05688c;
|
|
101
|
+
hash[6] = 0x1f83d9ab;
|
|
102
|
+
hash[7] = 0x5be0cd19;
|
|
103
|
+
ml = bytes.length * 8;
|
|
104
|
+
msg = new Uint8Array(bytes.length + 64 + ((64 - ((bytes.length + 9) % 64)) % 64));
|
|
105
|
+
msg.set(bytes);
|
|
106
|
+
msg[bytes.length] = 0x80;
|
|
107
|
+
new DataView(msg.buffer).setUint32(msg.length - 4, ml, false);
|
|
108
|
+
for (i = 0; i < msg.length; i += 64) {
|
|
109
|
+
w = new Uint32Array(64);
|
|
110
|
+
for (j = 0; j < 16; j++)
|
|
111
|
+
w[j] = new DataView(msg.buffer).getUint32(i + j * 4, false);
|
|
112
|
+
for (j = 16; j < 64; j++) {
|
|
113
|
+
s0 = ((w[j - 15] >>> 7) | (w[j - 15] << 25)) ^ ((w[j - 15] >>> 18) | (w[j - 15] << 14)) ^ (w[j - 15] >>> 3);
|
|
114
|
+
s1 = ((w[j - 2] >>> 17) | (w[j - 2] << 15)) ^ ((w[j - 2] >>> 19) | (w[j - 2] << 13)) ^ (w[j - 2] >>> 10);
|
|
115
|
+
w[j] = (w[j - 16] + s0 + w[j - 7] + s1) >>> 0;
|
|
116
|
+
}
|
|
117
|
+
a = hash[0], b = hash[1], c = hash[2], d = hash[3], e = hash[4], f = hash[5], g = hash[6], h = hash[7];
|
|
118
|
+
for (j = 0; j < 64; j++) {
|
|
119
|
+
S1 = ((e >>> 6) | (e << 26)) ^ ((e >>> 11) | (e << 21)) ^ ((e >>> 25) | (e << 7));
|
|
120
|
+
ch = (e & f) ^ (~e & g);
|
|
121
|
+
temp1 = (h + S1 + ch + k[j] + w[j]) >>> 0;
|
|
122
|
+
S0 = ((a >>> 2) | (a << 30)) ^ ((a >>> 13) | (a << 19)) ^ ((a >>> 22) | (a << 10));
|
|
123
|
+
maj = (a & b) ^ (a & c) ^ (b & c);
|
|
124
|
+
temp2 = (S0 + maj) >>> 0;
|
|
125
|
+
h = g;
|
|
126
|
+
g = f;
|
|
127
|
+
f = e;
|
|
128
|
+
e = (d + temp1) >>> 0;
|
|
129
|
+
d = c;
|
|
130
|
+
c = b;
|
|
131
|
+
b = a;
|
|
132
|
+
a = (temp1 + temp2) >>> 0;
|
|
133
|
+
}
|
|
134
|
+
hash[0] = (hash[0] + a) >>> 0;
|
|
135
|
+
hash[1] = (hash[1] + b) >>> 0;
|
|
136
|
+
hash[2] = (hash[2] + c) >>> 0;
|
|
137
|
+
hash[3] = (hash[3] + d) >>> 0;
|
|
138
|
+
hash[4] = (hash[4] + e) >>> 0;
|
|
139
|
+
hash[5] = (hash[5] + f) >>> 0;
|
|
140
|
+
hash[6] = (hash[6] + g) >>> 0;
|
|
141
|
+
hash[7] = (hash[7] + h) >>> 0;
|
|
142
|
+
}
|
|
143
|
+
result = new Uint8Array(32);
|
|
144
|
+
for (i = 0; i < 8; i++)
|
|
145
|
+
new DataView(result.buffer).setUint32(i * 4, hash[i], false);
|
|
146
|
+
return [2 /*return*/, result.buffer];
|
|
147
|
+
});
|
|
148
|
+
}); };
|
|
149
|
+
var originalSubtle_1 = window.crypto.subtle;
|
|
150
|
+
try {
|
|
151
|
+
Object.defineProperty(window.crypto, 'subtle', {
|
|
152
|
+
value: {
|
|
153
|
+
digest: function (algorithm, data) { return __awaiter(void 0, void 0, void 0, function () {
|
|
154
|
+
var alg;
|
|
155
|
+
return __generator(this, function (_a) {
|
|
156
|
+
alg = typeof algorithm === 'string' ? algorithm : algorithm.name;
|
|
157
|
+
if (alg === 'SHA-256')
|
|
158
|
+
return [2 /*return*/, sha256_1(data)];
|
|
159
|
+
// Fallback to original if available
|
|
160
|
+
if (originalSubtle_1 === null || originalSubtle_1 === void 0 ? void 0 : originalSubtle_1.digest)
|
|
161
|
+
return [2 /*return*/, originalSubtle_1.digest(algorithm, data)];
|
|
162
|
+
throw new Error("Unsupported algorithm: ".concat(alg));
|
|
163
|
+
});
|
|
164
|
+
}); }
|
|
165
|
+
},
|
|
166
|
+
writable: true,
|
|
167
|
+
configurable: true
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
catch (e) {
|
|
171
|
+
// Ignore if subtle cannot be defined
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
// Polyfill randomUUID
|
|
175
|
+
if (window.crypto && !window.crypto.randomUUID) {
|
|
176
|
+
try {
|
|
177
|
+
Object.defineProperty(window.crypto, 'randomUUID', {
|
|
178
|
+
value: function () {
|
|
179
|
+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
|
180
|
+
var r = (Math.random() * 16) | 0;
|
|
181
|
+
var v = c === 'x' ? r : (r & 0x3) | 0x8;
|
|
182
|
+
return v.toString(16);
|
|
183
|
+
});
|
|
184
|
+
},
|
|
185
|
+
writable: true,
|
|
186
|
+
configurable: true
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
catch (e) {
|
|
190
|
+
// Ignore if randomUUID cannot be defined
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
43
195
|
/******************************************************************************
|
|
44
196
|
Copyright (c) Microsoft Corporation.
|
|
45
197
|
|
|
@@ -80,7 +232,7 @@ function __rest(s, e) {
|
|
|
80
232
|
return t;
|
|
81
233
|
}
|
|
82
234
|
|
|
83
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
235
|
+
function __awaiter$1(thisArg, _arguments, P, generator) {
|
|
84
236
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
85
237
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
86
238
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
@@ -90,7 +242,7 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
90
242
|
});
|
|
91
243
|
}
|
|
92
244
|
|
|
93
|
-
function __generator(thisArg, body) {
|
|
245
|
+
function __generator$1(thisArg, body) {
|
|
94
246
|
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
247
|
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
96
248
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
@@ -187,10 +339,10 @@ function useCAMSAuth(options) {
|
|
|
187
339
|
}
|
|
188
340
|
}
|
|
189
341
|
}, [options.storageKey]);
|
|
190
|
-
var login = React.useCallback(function (config) { return __awaiter(_this, void 0, void 0, function () {
|
|
342
|
+
var login = React.useCallback(function (config) { return __awaiter$1(_this, void 0, void 0, function () {
|
|
191
343
|
var loginConfig, userProfile, err_1, e, isPopupClosedError, restoredToken, userProfile;
|
|
192
344
|
var _a, _b, _c;
|
|
193
|
-
return __generator(this, function (_d) {
|
|
345
|
+
return __generator$1(this, function (_d) {
|
|
194
346
|
switch (_d.label) {
|
|
195
347
|
case 0:
|
|
196
348
|
if (!sessionManagerRef.current)
|
|
@@ -238,8 +390,8 @@ function useCAMSAuth(options) {
|
|
|
238
390
|
}
|
|
239
391
|
});
|
|
240
392
|
}); }, [options.idleTimeout]);
|
|
241
|
-
var logout = React.useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
242
|
-
return __generator(this, function (_a) {
|
|
393
|
+
var logout = React.useCallback(function () { return __awaiter$1(_this, void 0, void 0, function () {
|
|
394
|
+
return __generator$1(this, function (_a) {
|
|
243
395
|
switch (_a.label) {
|
|
244
396
|
case 0:
|
|
245
397
|
if (!sessionManagerRef.current)
|
|
@@ -269,11 +421,13 @@ function useCAMSAuth(options) {
|
|
|
269
421
|
};
|
|
270
422
|
}
|
|
271
423
|
|
|
272
|
-
var setCookie
|
|
424
|
+
var setCookie = function (name, value, days) {
|
|
425
|
+
if (days === void 0) { days = 1; }
|
|
273
426
|
var expires = new Date(Date.now() + days * 24 * 60 * 60 * 1000).toUTCString();
|
|
427
|
+
console.log("Auth Cookie Expires >>>", { name: name, value: value, expires: expires });
|
|
274
428
|
document.cookie = "".concat(name, "=").concat(encodeURIComponent(value), "; expires=").concat(expires, "; path=/; samesite=Lax");
|
|
275
429
|
};
|
|
276
|
-
var getCookie
|
|
430
|
+
var getCookie = function (name) {
|
|
277
431
|
var _a;
|
|
278
432
|
return ((_a = document.cookie
|
|
279
433
|
.split("; ")
|
|
@@ -284,23 +438,24 @@ var getCookie$1 = function (name) {
|
|
|
284
438
|
.split("=")[1])
|
|
285
439
|
: null;
|
|
286
440
|
};
|
|
287
|
-
var deleteCookie
|
|
441
|
+
var deleteCookie = function (name) {
|
|
288
442
|
document.cookie = name + "=; Max-Age=-99999999; path=/";
|
|
289
443
|
};
|
|
290
444
|
|
|
291
445
|
function useCAMSMSALAuth(options) {
|
|
292
446
|
var _this = this;
|
|
293
|
-
var
|
|
294
|
-
var
|
|
447
|
+
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;
|
|
448
|
+
var storageKey = optStorageKey || "CAMS-MSAL-AUTH-SDK";
|
|
449
|
+
var _b = msalReact.useMsal(), instance = _b.instance, inProgress = _b.inProgress, accounts = _b.accounts;
|
|
295
450
|
var account = msalReact.useAccount(accounts[0] || {});
|
|
296
|
-
var
|
|
297
|
-
var
|
|
298
|
-
var
|
|
299
|
-
var
|
|
300
|
-
var
|
|
451
|
+
var _c = React.useState(null), error = _c[0], setError = _c[1];
|
|
452
|
+
var _d = React.useState(""), idToken = _d[0], setIdToken = _d[1];
|
|
453
|
+
var _e = React.useState(""), accessToken = _e[0], setAccessToken = _e[1];
|
|
454
|
+
var _f = React.useState(null), mfaAuthenticator = _f[0], setMfaAuthenticator = _f[1];
|
|
455
|
+
var _g = React.useState(false), requiresMFA = _g[0], setRequiresMFA = _g[1];
|
|
301
456
|
var isLoading = inProgress !== msalBrowser.InteractionStatus.None;
|
|
302
457
|
var isAuthenticated = !!account && !!accessToken && !requiresMFA;
|
|
303
|
-
var scopes =
|
|
458
|
+
var scopes = optScopes || ["openid", "profile", "email"];
|
|
304
459
|
var isTokenValid = function (token) {
|
|
305
460
|
try {
|
|
306
461
|
var payload = JSON.parse(atob(token.split(".")[1]));
|
|
@@ -324,15 +479,14 @@ function useCAMSMSALAuth(options) {
|
|
|
324
479
|
var mfaConfig = {
|
|
325
480
|
accessToken: accessToken_1,
|
|
326
481
|
idToken: idToken_1,
|
|
327
|
-
appCode:
|
|
482
|
+
appCode: appCode,
|
|
328
483
|
provider: "MSAL",
|
|
329
|
-
apiEndpoint:
|
|
484
|
+
apiEndpoint: MFAEndpoint,
|
|
330
485
|
};
|
|
331
486
|
var authenticator = new camsSdk.CAMSMFAAuthenticator(mfaConfig);
|
|
332
487
|
setMfaAuthenticator(authenticator);
|
|
333
488
|
setRequiresMFA(true);
|
|
334
489
|
}
|
|
335
|
-
camsSdk.Logger.debug("App Code", { ">>>": options.appCode });
|
|
336
490
|
}
|
|
337
491
|
else {
|
|
338
492
|
localStorage.removeItem(storageKey);
|
|
@@ -374,22 +528,26 @@ function useCAMSMSALAuth(options) {
|
|
|
374
528
|
// };
|
|
375
529
|
// handleRedirect();
|
|
376
530
|
// }, []);
|
|
377
|
-
var login = React.useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
531
|
+
var login = React.useCallback(function () { return __awaiter$1(_this, void 0, void 0, function () {
|
|
378
532
|
var response, mfaConfig, authenticator, err_1, camsError_1, camsError;
|
|
379
|
-
var _a
|
|
380
|
-
return __generator(this, function (
|
|
381
|
-
switch (
|
|
533
|
+
var _a;
|
|
534
|
+
return __generator$1(this, function (_b) {
|
|
535
|
+
switch (_b.label) {
|
|
382
536
|
case 0:
|
|
537
|
+
if (inProgress !== msalBrowser.InteractionStatus.None) {
|
|
538
|
+
camsSdk.Logger.warn("Authentication already in progress, ignoring duplicate call");
|
|
539
|
+
return [2 /*return*/];
|
|
540
|
+
}
|
|
383
541
|
setError(null);
|
|
384
|
-
|
|
542
|
+
_b.label = 1;
|
|
385
543
|
case 1:
|
|
386
|
-
|
|
544
|
+
_b.trys.push([1, 3, , 4]);
|
|
387
545
|
return [4 /*yield*/, instance.loginPopup({
|
|
388
546
|
scopes: scopes,
|
|
389
|
-
prompt:
|
|
547
|
+
prompt: prompt || "login",
|
|
390
548
|
})];
|
|
391
549
|
case 2:
|
|
392
|
-
response =
|
|
550
|
+
response = _b.sent();
|
|
393
551
|
console.log("Login Token response:", {
|
|
394
552
|
accessToken: response.accessToken,
|
|
395
553
|
idToken: response.idToken,
|
|
@@ -399,9 +557,9 @@ function useCAMSMSALAuth(options) {
|
|
|
399
557
|
mfaConfig = {
|
|
400
558
|
accessToken: response.accessToken,
|
|
401
559
|
idToken: response.idToken,
|
|
402
|
-
appCode:
|
|
560
|
+
appCode: appCode,
|
|
403
561
|
provider: "MSAL",
|
|
404
|
-
apiEndpoint:
|
|
562
|
+
apiEndpoint: MFAEndpoint,
|
|
405
563
|
};
|
|
406
564
|
authenticator = new camsSdk.CAMSMFAAuthenticator(mfaConfig);
|
|
407
565
|
setMfaAuthenticator(authenticator);
|
|
@@ -415,10 +573,15 @@ function useCAMSMSALAuth(options) {
|
|
|
415
573
|
idToken: response.idToken,
|
|
416
574
|
}));
|
|
417
575
|
}
|
|
418
|
-
|
|
576
|
+
onAuthSuccess === null || onAuthSuccess === void 0 ? void 0 : onAuthSuccess(response.accessToken);
|
|
419
577
|
return [3 /*break*/, 4];
|
|
420
578
|
case 3:
|
|
421
|
-
err_1 =
|
|
579
|
+
err_1 = _b.sent();
|
|
580
|
+
// Handle interaction_in_progress error
|
|
581
|
+
if (err_1.errorCode === "interaction_in_progress") {
|
|
582
|
+
camsSdk.Logger.warn("Interaction already in progress, please wait");
|
|
583
|
+
return [2 /*return*/];
|
|
584
|
+
}
|
|
422
585
|
// Handle user cancellation gracefully
|
|
423
586
|
if (err_1.errorCode === "user_cancelled") {
|
|
424
587
|
camsSdk.Logger.error("User cancelled login");
|
|
@@ -427,22 +590,22 @@ function useCAMSMSALAuth(options) {
|
|
|
427
590
|
}
|
|
428
591
|
// If popup is blocked
|
|
429
592
|
if (err_1.errorCode === "popup_window_error" ||
|
|
430
|
-
((
|
|
593
|
+
((_a = err_1.message) === null || _a === void 0 ? void 0 : _a.includes("popup"))) {
|
|
431
594
|
camsError_1 = new camsSdk.CAMSError(camsSdk.CAMSErrorType.POPUP_BLOCKED, "Popup blocked by browser. Please allow popups and try again.");
|
|
432
595
|
setError(camsError_1);
|
|
433
|
-
|
|
596
|
+
onAuthError === null || onAuthError === void 0 ? void 0 : onAuthError(camsError_1);
|
|
434
597
|
return [2 /*return*/];
|
|
435
598
|
}
|
|
436
599
|
camsError = new camsSdk.CAMSError(camsSdk.CAMSErrorType.API_VALIDATION_ERROR, "Login failed: " + err_1.message || err_1);
|
|
437
600
|
setError(camsError);
|
|
438
|
-
|
|
601
|
+
onAuthError === null || onAuthError === void 0 ? void 0 : onAuthError(camsError);
|
|
439
602
|
return [3 /*break*/, 4];
|
|
440
603
|
case 4: return [2 /*return*/];
|
|
441
604
|
}
|
|
442
605
|
});
|
|
443
|
-
}); }, [instance, scopes,
|
|
444
|
-
var completeMFA = React.useCallback(function (data) { return __awaiter(_this, void 0, void 0, function () {
|
|
445
|
-
return __generator(this, function (_a) {
|
|
606
|
+
}); }, [instance, scopes, prompt, appCode, MFAEndpoint, onAuthSuccess, onAuthError, storageKey, inProgress]);
|
|
607
|
+
var completeMFA = React.useCallback(function (data) { return __awaiter$1(_this, void 0, void 0, function () {
|
|
608
|
+
return __generator$1(this, function (_a) {
|
|
446
609
|
if (!mfaAuthenticator) {
|
|
447
610
|
throw new camsSdk.CAMSError(camsSdk.CAMSErrorType.API_VALIDATION_ERROR, "MFA Authenticator not initialized");
|
|
448
611
|
}
|
|
@@ -456,7 +619,7 @@ function useCAMSMSALAuth(options) {
|
|
|
456
619
|
accessToken: accessToken,
|
|
457
620
|
idToken: idToken,
|
|
458
621
|
}));
|
|
459
|
-
setCookie
|
|
622
|
+
setCookie("CAMS-MSAL-AUTH-SDK-PROFILE", JSON.stringify({ type: "AUTH_SUCCESS", userProfile: __assign({}, data) }), activeCookiePeriod);
|
|
460
623
|
setRequiresMFA(false);
|
|
461
624
|
// Set requiresMFA to false after storage update
|
|
462
625
|
camsSdk.Logger.debug("MFA completed successfully, storage updated", {
|
|
@@ -475,9 +638,9 @@ function useCAMSMSALAuth(options) {
|
|
|
475
638
|
}
|
|
476
639
|
return [2 /*return*/];
|
|
477
640
|
});
|
|
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) {
|
|
641
|
+
}); }, [mfaAuthenticator, accessToken, idToken, storageKey, activeCookiePeriod]);
|
|
642
|
+
var sendEmailOTP = React.useCallback(function () { return __awaiter$1(_this, void 0, void 0, function () {
|
|
643
|
+
return __generator$1(this, function (_a) {
|
|
481
644
|
switch (_a.label) {
|
|
482
645
|
case 0:
|
|
483
646
|
if (!mfaAuthenticator) {
|
|
@@ -488,9 +651,9 @@ function useCAMSMSALAuth(options) {
|
|
|
488
651
|
}
|
|
489
652
|
});
|
|
490
653
|
}); }, [mfaAuthenticator]);
|
|
491
|
-
var logout = React.useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
654
|
+
var logout = React.useCallback(function () { return __awaiter$1(_this, void 0, void 0, function () {
|
|
492
655
|
var err_2, camsError;
|
|
493
|
-
return __generator(this, function (_a) {
|
|
656
|
+
return __generator$1(this, function (_a) {
|
|
494
657
|
switch (_a.label) {
|
|
495
658
|
case 0:
|
|
496
659
|
_a.trys.push([0, 2, , 3]);
|
|
@@ -526,12 +689,13 @@ function useCAMSMSALAuth(options) {
|
|
|
526
689
|
error: error,
|
|
527
690
|
idToken: idToken,
|
|
528
691
|
accessToken: accessToken,
|
|
529
|
-
appCode:
|
|
692
|
+
appCode: appCode,
|
|
530
693
|
mfaAuthenticator: mfaAuthenticator,
|
|
531
694
|
requiresMFA: requiresMFA,
|
|
532
695
|
completeMFA: completeMFA,
|
|
533
696
|
sendEmailOTP: sendEmailOTP,
|
|
534
697
|
setRequiresMFA: setRequiresMFA,
|
|
698
|
+
activeCookiePeriod: activeCookiePeriod,
|
|
535
699
|
};
|
|
536
700
|
}
|
|
537
701
|
|
|
@@ -574,10 +738,10 @@ function arrayBufferToBase64url(buffer) {
|
|
|
574
738
|
* @returns A promise that resolves to a JSON-serializable representation of the PublicKeyCredential.
|
|
575
739
|
*/
|
|
576
740
|
function register(options) {
|
|
577
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
741
|
+
return __awaiter$1(this, void 0, void 0, function () {
|
|
578
742
|
var createOptions, credential, publicKeyCredential, attestationResponse, transports, err_1;
|
|
579
743
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
580
|
-
return __generator(this, function (_k) {
|
|
744
|
+
return __generator$1(this, function (_k) {
|
|
581
745
|
switch (_k.label) {
|
|
582
746
|
case 0:
|
|
583
747
|
_k.trys.push([0, 2, , 3]);
|
|
@@ -635,10 +799,10 @@ function register(options) {
|
|
|
635
799
|
* @returns A promise that resolves to a JSON-serializable representation of the PublicKeyCredential.
|
|
636
800
|
*/
|
|
637
801
|
function authenticate(options) {
|
|
638
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
802
|
+
return __awaiter$1(this, void 0, void 0, function () {
|
|
639
803
|
var getOptions, credential, publicKeyCredential, assertionResponse;
|
|
640
804
|
var _a;
|
|
641
|
-
return __generator(this, function (_b) {
|
|
805
|
+
return __generator$1(this, function (_b) {
|
|
642
806
|
switch (_b.label) {
|
|
643
807
|
case 0:
|
|
644
808
|
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 +1288,6 @@ function ProtectedRoute(_a) {
|
|
|
1124
1288
|
}
|
|
1125
1289
|
|
|
1126
1290
|
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
1291
|
var isTokenValid = function (token) {
|
|
1146
1292
|
try {
|
|
1147
1293
|
var payload = JSON.parse(atob(token.split(".")[1]));
|
|
@@ -1190,7 +1336,7 @@ function CAMSMSALProviderInner(_a) {
|
|
|
1190
1336
|
localStorage.setItem(auth.storageKey, JSON.stringify({
|
|
1191
1337
|
accessToken: auth.accessToken,
|
|
1192
1338
|
idToken: auth.idToken,
|
|
1193
|
-
appCode: auth.appCode
|
|
1339
|
+
appCode: auth.appCode,
|
|
1194
1340
|
}));
|
|
1195
1341
|
}
|
|
1196
1342
|
}, [auth.accessToken, auth.idToken, auth.storageKey]);
|
|
@@ -1206,8 +1352,8 @@ function CAMSMSALProviderInner(_a) {
|
|
|
1206
1352
|
}
|
|
1207
1353
|
}, [userProfile, profileStorageKey]);
|
|
1208
1354
|
// Enhanced logout that also clears profile
|
|
1209
|
-
var enhancedLogout = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
1210
|
-
return __generator(this, function (_a) {
|
|
1355
|
+
var enhancedLogout = function () { return __awaiter$1(_this, void 0, void 0, function () {
|
|
1356
|
+
return __generator$1(this, function (_a) {
|
|
1211
1357
|
switch (_a.label) {
|
|
1212
1358
|
case 0: return [4 /*yield*/, auth.logout()];
|
|
1213
1359
|
case 1:
|
|
@@ -1274,7 +1420,7 @@ function CAMSProviderCore(props) {
|
|
|
1274
1420
|
if (typeof window === "undefined")
|
|
1275
1421
|
return null;
|
|
1276
1422
|
try {
|
|
1277
|
-
var storedProfile = getCookie
|
|
1423
|
+
var storedProfile = getCookie(profileStorageKey);
|
|
1278
1424
|
return storedProfile ? JSON.parse(storedProfile) : null;
|
|
1279
1425
|
}
|
|
1280
1426
|
catch (_a) {
|
|
@@ -1284,7 +1430,7 @@ function CAMSProviderCore(props) {
|
|
|
1284
1430
|
var _a = React.useState(getInitialProfile), userProfile = _a[0], setUserProfile = _a[1];
|
|
1285
1431
|
React.useEffect(function () {
|
|
1286
1432
|
if (typeof window !== "undefined") {
|
|
1287
|
-
var storedProfile = getCookie
|
|
1433
|
+
var storedProfile = getCookie(profileStorageKey);
|
|
1288
1434
|
if (storedProfile) {
|
|
1289
1435
|
try {
|
|
1290
1436
|
setUserProfile(JSON.parse(storedProfile));
|
|
@@ -1296,22 +1442,22 @@ function CAMSProviderCore(props) {
|
|
|
1296
1442
|
React.useEffect(function () {
|
|
1297
1443
|
if (typeof window !== "undefined") {
|
|
1298
1444
|
if (userProfile) {
|
|
1299
|
-
setCookie
|
|
1445
|
+
setCookie(profileStorageKey, JSON.stringify(userProfile), 1);
|
|
1300
1446
|
}
|
|
1301
1447
|
else {
|
|
1302
|
-
deleteCookie
|
|
1448
|
+
deleteCookie(profileStorageKey);
|
|
1303
1449
|
}
|
|
1304
1450
|
}
|
|
1305
1451
|
}, [userProfile, profileStorageKey]);
|
|
1306
|
-
var enhancedLogout = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
1307
|
-
return __generator(this, function (_a) {
|
|
1452
|
+
var enhancedLogout = function () { return __awaiter$1(_this, void 0, void 0, function () {
|
|
1453
|
+
return __generator$1(this, function (_a) {
|
|
1308
1454
|
switch (_a.label) {
|
|
1309
1455
|
case 0: return [4 /*yield*/, auth.logout()];
|
|
1310
1456
|
case 1:
|
|
1311
1457
|
_a.sent();
|
|
1312
1458
|
setUserProfile(null);
|
|
1313
1459
|
if (typeof window !== "undefined") {
|
|
1314
|
-
deleteCookie
|
|
1460
|
+
deleteCookie(profileStorageKey);
|
|
1315
1461
|
}
|
|
1316
1462
|
return [2 /*return*/];
|
|
1317
1463
|
}
|
|
@@ -1347,7 +1493,8 @@ function CAMSProviderCore(props) {
|
|
|
1347
1493
|
userProfile,
|
|
1348
1494
|
]);
|
|
1349
1495
|
var value = React.useMemo(function () {
|
|
1350
|
-
|
|
1496
|
+
auth.logout; var authRest = __rest(auth, ["logout"]);
|
|
1497
|
+
return __assign(__assign({}, authRest), { logout: enhancedLogout, userProfile: userProfile, setUserProfile: setUserProfile, authMode: mode });
|
|
1351
1498
|
}, [auth, userProfile, mode]);
|
|
1352
1499
|
return jsxRuntimeExports.jsx(CAMSContext.Provider, { value: value, children: children });
|
|
1353
1500
|
}
|
|
@@ -1355,7 +1502,7 @@ function UnifiedCAMSProvider(props) {
|
|
|
1355
1502
|
// Validate appCode is a valid GUID
|
|
1356
1503
|
var appCodeValidation = GuidSchema.safeParse(props.appCode);
|
|
1357
1504
|
if (!appCodeValidation.success) {
|
|
1358
|
-
throw new Error("Invalid
|
|
1505
|
+
throw new Error("Invalid CAS APP CODE: ".concat(appCodeValidation.error.issues[0].message));
|
|
1359
1506
|
}
|
|
1360
1507
|
if (props.mode === "MSAL") {
|
|
1361
1508
|
var msalConfig = props.msalConfig, msalInstance = props.msalInstance;
|
|
@@ -1723,7 +1870,7 @@ styleInject(css_248z);
|
|
|
1723
1870
|
|
|
1724
1871
|
var LoadingSpinner = function (_a) {
|
|
1725
1872
|
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..." }))] }));
|
|
1873
|
+
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
1874
|
};
|
|
1728
1875
|
|
|
1729
1876
|
var AuthSuccessAnimation = function (_a) {
|
|
@@ -1775,15 +1922,36 @@ var APIHeaders = {
|
|
|
1775
1922
|
"X-API-VERSION": "1.0",
|
|
1776
1923
|
};
|
|
1777
1924
|
|
|
1925
|
+
// Creates an Axios instance with a base URL determined by the environment (production or development).
|
|
1926
|
+
var axiosInstance = axios.create({
|
|
1927
|
+
httpsAgent: new https.Agent({ rejectUnauthorized: false }),
|
|
1928
|
+
headers: __assign({ "Content-Type": "application/json" }, APIHeaders),
|
|
1929
|
+
});
|
|
1930
|
+
// Intercepts outgoing requests to add authorization token, version header, and timeout settings.
|
|
1931
|
+
axiosInstance.interceptors.request.use(function (config) {
|
|
1932
|
+
var _a;
|
|
1933
|
+
config.timeout = Number((_a = process.env.NEXT_PUBLIC_API_TIMEOUT) !== null && _a !== void 0 ? _a : 605000);
|
|
1934
|
+
config.timeoutErrorMessage = "Operation Timed Out"; // Custom error message for timeouts.
|
|
1935
|
+
return config; // Returns the modified request configuration.
|
|
1936
|
+
}, function (axiosError) {
|
|
1937
|
+
var _a, _b;
|
|
1938
|
+
// Handles request errors.
|
|
1939
|
+
return {
|
|
1940
|
+
status: (_a = axiosError.response) === null || _a === void 0 ? void 0 : _a.status, // Extracts HTTP status from the error response.
|
|
1941
|
+
message: axiosError.message, // Extracts the error message.
|
|
1942
|
+
data: (_b = axiosError.response) === null || _b === void 0 ? void 0 : _b.data, // Extracts response data from the error.
|
|
1943
|
+
};
|
|
1944
|
+
});
|
|
1945
|
+
|
|
1778
1946
|
var MAX_ATTEMPTS = 3;
|
|
1779
1947
|
var useOTPHandler = function (_a) {
|
|
1780
1948
|
var provider = _a.provider, accessToken = _a.accessToken, idToken = _a.idToken, appCode = _a.appCode, authenticationType = _a.authenticationType, MFAEndpoint = _a.MFAEndpoint, onAuthComplete = _a.onAuthComplete;
|
|
1781
1949
|
var _b = React.useState(false), loading = _b[0], setLoading = _b[1];
|
|
1782
1950
|
var _c = React.useState(0), attemptCount = _c[0], setAttemptCount = _c[1];
|
|
1783
1951
|
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 () {
|
|
1952
|
+
var handleSubmitOTP = React.useMemo(function () { return function (authenticationValue) { return __awaiter$1(void 0, void 0, void 0, function () {
|
|
1785
1953
|
var currentAttempt, response, error_1, currentAttempt;
|
|
1786
|
-
return __generator(this, function (_a) {
|
|
1954
|
+
return __generator$1(this, function (_a) {
|
|
1787
1955
|
switch (_a.label) {
|
|
1788
1956
|
case 0:
|
|
1789
1957
|
if (isMaxAttemptsReached) {
|
|
@@ -1800,16 +1968,13 @@ var useOTPHandler = function (_a) {
|
|
|
1800
1968
|
setAttemptCount(currentAttempt);
|
|
1801
1969
|
if (authenticationType === null)
|
|
1802
1970
|
return [2 /*return*/, false];
|
|
1803
|
-
return [4 /*yield*/,
|
|
1971
|
+
return [4 /*yield*/, axiosInstance.post(MFAEndpoint || "/api/auth/verify-mfa", {
|
|
1804
1972
|
provider: provider,
|
|
1805
1973
|
accessToken: accessToken,
|
|
1806
1974
|
idToken: idToken,
|
|
1807
1975
|
authenticationType: authenticationType,
|
|
1808
1976
|
MFACode: authenticationValue,
|
|
1809
1977
|
appCode: appCode,
|
|
1810
|
-
}, {
|
|
1811
|
-
headers: APIHeaders,
|
|
1812
|
-
timeout: 605000,
|
|
1813
1978
|
})];
|
|
1814
1979
|
case 2:
|
|
1815
1980
|
response = (_a.sent()).data;
|
|
@@ -1876,23 +2041,20 @@ var useCredentialsHandler = function (onAuthComplete) {
|
|
|
1876
2041
|
var _b = React.useState(0), attemptCount = _b[0], setAttemptCount = _b[1];
|
|
1877
2042
|
var _c = React.useState(false), isMaxAttemptsReached = _c[0], setIsMaxAttemptsReached = _c[1];
|
|
1878
2043
|
var handleSubmitCredentials = React.useMemo(function () {
|
|
1879
|
-
return function (CredAuthEndpoint, credentials, appCode) { return __awaiter(void 0, void 0, void 0, function () {
|
|
2044
|
+
return function (CredAuthEndpoint, credentials, appCode) { return __awaiter$1(void 0, void 0, void 0, function () {
|
|
1880
2045
|
var currentAttempt, response, error_2, currentAttempt;
|
|
1881
|
-
return __generator(this, function (_a) {
|
|
2046
|
+
return __generator$1(this, function (_a) {
|
|
1882
2047
|
switch (_a.label) {
|
|
1883
2048
|
case 0:
|
|
1884
2049
|
_a.trys.push([0, 2, 3, 4]);
|
|
1885
2050
|
setLoading(true);
|
|
1886
2051
|
currentAttempt = attemptCount + 1;
|
|
1887
2052
|
setAttemptCount(currentAttempt);
|
|
1888
|
-
return [4 /*yield*/,
|
|
2053
|
+
return [4 /*yield*/, axiosInstance.post(CredAuthEndpoint, {
|
|
1889
2054
|
username: credentials.username,
|
|
1890
2055
|
password: credentials.password,
|
|
1891
2056
|
MFACode: credentials.MFACode,
|
|
1892
2057
|
appCode: appCode,
|
|
1893
|
-
}, {
|
|
1894
|
-
headers: APIHeaders,
|
|
1895
|
-
timeout: 605000,
|
|
1896
2058
|
})];
|
|
1897
2059
|
case 1:
|
|
1898
2060
|
response = (_a.sent()).data;
|
|
@@ -1953,23 +2115,21 @@ var MFAOptions = function (_a) {
|
|
|
1953
2115
|
var context = useCAMSContext();
|
|
1954
2116
|
var _f = context.authMode === "MSAL" && "sendEmailOTP" in context
|
|
1955
2117
|
? context
|
|
1956
|
-
: { sendEmailOTP: null, completeMFA: null, logout: function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
2118
|
+
: { sendEmailOTP: null, completeMFA: null, logout: function () { return __awaiter$1(void 0, void 0, void 0, function () { return __generator$1(this, function (_a) {
|
|
1957
2119
|
return [2 /*return*/];
|
|
1958
2120
|
}); }); } }, sendEmailOTP = _f.sendEmailOTP, completeMFA = _f.completeMFA, logout = _f.logout;
|
|
1959
2121
|
var accessToken = context.authMode === "MSAL" ? context.accessToken : "";
|
|
1960
2122
|
var idToken = context.authMode === "MSAL" ? context.idToken : "";
|
|
1961
2123
|
var authenticate = useWebAuthn().authenticate;
|
|
1962
|
-
var handleFIDOLogin = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
2124
|
+
var handleFIDOLogin = function () { return __awaiter$1(void 0, void 0, void 0, function () {
|
|
1963
2125
|
var options, assertionResponse, error_1;
|
|
1964
|
-
return __generator(this, function (_a) {
|
|
2126
|
+
return __generator$1(this, function (_a) {
|
|
1965
2127
|
switch (_a.label) {
|
|
1966
2128
|
case 0:
|
|
1967
2129
|
_a.trys.push([0, 4, , 5]);
|
|
1968
2130
|
// 1. Fetch authentication challenge from your server
|
|
1969
2131
|
console.log("Requesting authentication challenge from server...");
|
|
1970
|
-
return [4 /*yield*/,
|
|
1971
|
-
headers: APIHeaders,
|
|
1972
|
-
})];
|
|
2132
|
+
return [4 /*yield*/, axiosInstance.post(MFAEndpoints.RetrieveAuthChallenge, {})];
|
|
1973
2133
|
case 1:
|
|
1974
2134
|
options = (_a.sent()).data;
|
|
1975
2135
|
console.log("Received challenge:", options);
|
|
@@ -1981,10 +2141,7 @@ var MFAOptions = function (_a) {
|
|
|
1981
2141
|
console.log("Authentication assertion received from client:", assertionResponse);
|
|
1982
2142
|
// 3. Send the assertion back to the server for verification
|
|
1983
2143
|
console.log("Sending assertion to server for verification...");
|
|
1984
|
-
return [4 /*yield*/,
|
|
1985
|
-
headers: APIHeaders,
|
|
1986
|
-
withCredentials: true, // credentials: 'include'
|
|
1987
|
-
})];
|
|
2144
|
+
return [4 /*yield*/, axiosInstance.post(MFAEndpoints.AuthChallengeVerify, assertionResponse)];
|
|
1988
2145
|
case 3:
|
|
1989
2146
|
_a.sent();
|
|
1990
2147
|
sonner.toast.success("🔑 Sign-in successful!");
|
|
@@ -2046,12 +2203,12 @@ var MFAOptions = function (_a) {
|
|
|
2046
2203
|
}
|
|
2047
2204
|
var content = jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, {});
|
|
2048
2205
|
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 () {
|
|
2206
|
+
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
2207
|
var success;
|
|
2051
|
-
return __generator(this, function (_a) {
|
|
2208
|
+
return __generator$1(this, function (_a) {
|
|
2052
2209
|
switch (_a.label) {
|
|
2053
2210
|
case 0:
|
|
2054
|
-
resetAttempts();
|
|
2211
|
+
// resetAttempts();
|
|
2055
2212
|
setAuthType("EmailOTP");
|
|
2056
2213
|
setOtpVisible(true);
|
|
2057
2214
|
if (!sendEmailOTP) return [3 /*break*/, 2];
|
|
@@ -2068,7 +2225,6 @@ var MFAOptions = function (_a) {
|
|
|
2068
2225
|
}
|
|
2069
2226
|
});
|
|
2070
2227
|
}); }, 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
2228
|
setAuthType("AuthenticatorCode");
|
|
2073
2229
|
setOtpVisible(true);
|
|
2074
2230
|
}, 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 +2233,7 @@ var MFAOptions = function (_a) {
|
|
|
2077
2233
|
// setAuthType("AuthenticatorCode");
|
|
2078
2234
|
// setOtpVisible(true);
|
|
2079
2235
|
// }}
|
|
2080
|
-
onClick: handleFIDOLogin, disabled: context.isLoading, children: [jsxRuntimeExports.jsx(
|
|
2236
|
+
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
2237
|
}
|
|
2082
2238
|
else if (authType === "EmailOTP") {
|
|
2083
2239
|
content = (jsxRuntimeExports.jsx(Dialog, { open: otpVisible, onOpenChange: function () {
|
|
@@ -2120,16 +2276,16 @@ var ADLoginModal = function (_a) {
|
|
|
2120
2276
|
resolver: a$1(credentialsSchema),
|
|
2121
2277
|
defaultValues: { username: "", password: "" },
|
|
2122
2278
|
});
|
|
2123
|
-
var handleCredentialsSubmit = function (values) { return __awaiter(void 0, void 0, void 0, function () {
|
|
2124
|
-
return __generator(this, function (_a) {
|
|
2279
|
+
var handleCredentialsSubmit = function (values) { return __awaiter$1(void 0, void 0, void 0, function () {
|
|
2280
|
+
return __generator$1(this, function (_a) {
|
|
2125
2281
|
setCredentials(values);
|
|
2126
2282
|
setStep("mfa");
|
|
2127
2283
|
return [2 /*return*/];
|
|
2128
2284
|
});
|
|
2129
2285
|
}); };
|
|
2130
|
-
var handleMFASubmit = function (code) { return __awaiter(void 0, void 0, void 0, function () {
|
|
2286
|
+
var handleMFASubmit = function (code) { return __awaiter$1(void 0, void 0, void 0, function () {
|
|
2131
2287
|
var error_1;
|
|
2132
|
-
return __generator(this, function (_a) {
|
|
2288
|
+
return __generator$1(this, function (_a) {
|
|
2133
2289
|
switch (_a.label) {
|
|
2134
2290
|
case 0:
|
|
2135
2291
|
setIsLoading(true);
|
|
@@ -2190,8 +2346,8 @@ var DefaultLoginPage = function (_a) {
|
|
|
2190
2346
|
var login = context.login, isLoading = context.isLoading, authMode = context.authMode;
|
|
2191
2347
|
var _b = React.useState(false), showADModal = _b[0], setShowADModal = _b[1];
|
|
2192
2348
|
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) {
|
|
2349
|
+
var _c = useCredentialsHandler(function (state, data) { return __awaiter$1(void 0, void 0, void 0, function () {
|
|
2350
|
+
return __generator$1(this, function (_a) {
|
|
2195
2351
|
console.log(data);
|
|
2196
2352
|
if (state && data) {
|
|
2197
2353
|
context.isAuthenticated = true;
|
|
@@ -2205,6 +2361,10 @@ var DefaultLoginPage = function (_a) {
|
|
|
2205
2361
|
});
|
|
2206
2362
|
}); }), handleSubmitCredentials = _c.handleSubmitCredentials, isCredAuthLoading = _c.loading, setIsCredAuthLoading = _c.setLoading;
|
|
2207
2363
|
var handleMSALLogin = function () {
|
|
2364
|
+
if (typeof window !== "undefined" && !window.crypto) {
|
|
2365
|
+
sonner.toast.error("Crypto API not available. Please use a modern browser.");
|
|
2366
|
+
return;
|
|
2367
|
+
}
|
|
2208
2368
|
if (authMode === "MSAL") {
|
|
2209
2369
|
login();
|
|
2210
2370
|
}
|
|
@@ -2213,17 +2373,15 @@ var DefaultLoginPage = function (_a) {
|
|
|
2213
2373
|
console.warn("Regular CAMS login requires configuration");
|
|
2214
2374
|
}
|
|
2215
2375
|
};
|
|
2216
|
-
var handleRegister = function (data) { return __awaiter(void 0, void 0, void 0, function () {
|
|
2376
|
+
var handleRegister = function (data) { return __awaiter$1(void 0, void 0, void 0, function () {
|
|
2217
2377
|
var options, attestationResponse, error_1;
|
|
2218
|
-
return __generator(this, function (_a) {
|
|
2378
|
+
return __generator$1(this, function (_a) {
|
|
2219
2379
|
switch (_a.label) {
|
|
2220
2380
|
case 0:
|
|
2221
2381
|
_a.trys.push([0, 4, , 5]);
|
|
2222
2382
|
// 1. Fetch challenge from your server
|
|
2223
2383
|
console.log("Requesting registration challenge from server...");
|
|
2224
|
-
return [4 /*yield*/,
|
|
2225
|
-
headers: APIHeaders,
|
|
2226
|
-
})];
|
|
2384
|
+
return [4 /*yield*/, axiosInstance.post(MFAEndpoints.RegisterNewChallenge, __assign({}, data))];
|
|
2227
2385
|
case 1:
|
|
2228
2386
|
options = (_a.sent()).data;
|
|
2229
2387
|
console.log("Received challenge:", options);
|
|
@@ -2235,10 +2393,7 @@ var DefaultLoginPage = function (_a) {
|
|
|
2235
2393
|
console.log("Passkey created on client:", attestationResponse);
|
|
2236
2394
|
// 3. Send the response back to the server for verification
|
|
2237
2395
|
console.log("Sending attestation to server for verification...");
|
|
2238
|
-
return [4 /*yield*/,
|
|
2239
|
-
headers: APIHeaders,
|
|
2240
|
-
withCredentials: true, // credentials: 'include'
|
|
2241
|
-
})];
|
|
2396
|
+
return [4 /*yield*/, axiosInstance.post(MFAEndpoints.RegisterVerify + "?username=".concat(data.username), attestationResponse)];
|
|
2242
2397
|
case 3:
|
|
2243
2398
|
_a.sent();
|
|
2244
2399
|
sonner.toast.success("✅ Registration successful! Passkey created.");
|
|
@@ -2252,15 +2407,15 @@ var DefaultLoginPage = function (_a) {
|
|
|
2252
2407
|
}
|
|
2253
2408
|
});
|
|
2254
2409
|
}); };
|
|
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-
|
|
2410
|
+
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
2411
|
// variant="outline"
|
|
2257
2412
|
, {
|
|
2258
2413
|
// variant="outline"
|
|
2259
2414
|
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
2415
|
? "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) {
|
|
2416
|
+
: "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
2417
|
var username = _b.username, password = _b.password, MFACode = _b.MFACode;
|
|
2263
|
-
return __generator(this, function (_c) {
|
|
2418
|
+
return __generator$1(this, function (_c) {
|
|
2264
2419
|
// Implement your AD login logic here
|
|
2265
2420
|
console.log("AD Login:", { username: username, password: password, MFACode: MFACode });
|
|
2266
2421
|
// Example: await adLoginService(username, password, mfaCode);
|
|
@@ -2301,8 +2456,8 @@ var MFAGate = function (_a) {
|
|
|
2301
2456
|
if (!success)
|
|
2302
2457
|
camsSdk.Logger.error("MFA authentication failed");
|
|
2303
2458
|
}, []);
|
|
2304
|
-
var handleAuthFailed = React.useCallback(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
2305
|
-
return __generator(this, function (_a) {
|
|
2459
|
+
var handleAuthFailed = React.useCallback(function () { return __awaiter$1(void 0, void 0, void 0, function () {
|
|
2460
|
+
return __generator$1(this, function (_a) {
|
|
2306
2461
|
switch (_a.label) {
|
|
2307
2462
|
case 0: return [4 /*yield*/, context.logout()];
|
|
2308
2463
|
case 1:
|
|
@@ -2311,7 +2466,6 @@ var MFAGate = function (_a) {
|
|
|
2311
2466
|
}
|
|
2312
2467
|
});
|
|
2313
2468
|
}); }, [context.logout]);
|
|
2314
|
-
camsSdk.Logger.debug("MFA Endpoint >>>", { MFAEndpoints: MFAEndpoints });
|
|
2315
2469
|
if (useADLogin && !CredentialsAuthEndpoint)
|
|
2316
2470
|
return jsxRuntimeExports.jsx(ErrorFallback, { message: "Invalid AD Login Configuration." });
|
|
2317
2471
|
if (!validatedMFAEndpoints)
|