@nibssplc/cams-sdk-react 1.0.0-rc.21 → 1.0.0-rc.23
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/hooks/useCAMSMSALAuth.d.ts +0 -2
- package/dist/index.cjs.js +23 -48
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +23 -48
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
|
@@ -11,7 +11,6 @@ export interface UseCAMSMSALAuthOptions {
|
|
|
11
11
|
appCode: string;
|
|
12
12
|
allowedOrigins?: string[];
|
|
13
13
|
MFAEndpoint?: string;
|
|
14
|
-
activeCookiePeriod?: number;
|
|
15
14
|
}
|
|
16
15
|
export interface UseCAMSMSALAuthReturn {
|
|
17
16
|
login: () => Promise<void>;
|
|
@@ -28,6 +27,5 @@ export interface UseCAMSMSALAuthReturn {
|
|
|
28
27
|
completeMFA: (data: UserValidatedResponse) => Promise<MFAResponse>;
|
|
29
28
|
setRequiresMFA: React.Dispatch<React.SetStateAction<boolean>>;
|
|
30
29
|
sendEmailOTP: () => Promise<boolean>;
|
|
31
|
-
activeCookiePeriod: number;
|
|
32
30
|
}
|
|
33
31
|
export declare function useCAMSMSALAuth(options: UseCAMSMSALAuthOptions): UseCAMSMSALAuthReturn;
|
package/dist/index.cjs.js
CHANGED
|
@@ -382,12 +382,12 @@ function useCAMSAuth(options) {
|
|
|
382
382
|
};
|
|
383
383
|
}
|
|
384
384
|
|
|
385
|
-
var setCookie
|
|
386
|
-
if (days === void 0) { days = 1; }
|
|
385
|
+
var setCookie = function (name, value, days) {
|
|
387
386
|
var expires = new Date(Date.now() + days * 24 * 60 * 60 * 1000).toUTCString();
|
|
387
|
+
console.log("Auth Cookie Expires >>>", { name: name, value: value, expires: expires });
|
|
388
388
|
document.cookie = "".concat(name, "=").concat(encodeURIComponent(value), "; expires=").concat(expires, "; path=/; samesite=Lax");
|
|
389
389
|
};
|
|
390
|
-
var getCookie
|
|
390
|
+
var getCookie = function (name) {
|
|
391
391
|
var _a;
|
|
392
392
|
return ((_a = document.cookie
|
|
393
393
|
.split("; ")
|
|
@@ -398,21 +398,21 @@ var getCookie$1 = function (name) {
|
|
|
398
398
|
.split("=")[1])
|
|
399
399
|
: null;
|
|
400
400
|
};
|
|
401
|
-
var deleteCookie
|
|
401
|
+
var deleteCookie = function (name) {
|
|
402
402
|
document.cookie = name + "=; Max-Age=-99999999; path=/";
|
|
403
403
|
};
|
|
404
404
|
|
|
405
405
|
function useCAMSMSALAuth(options) {
|
|
406
406
|
var _this = this;
|
|
407
|
-
var optStorageKey = options.storageKey, optScopes = options.scopes, prompt = options.prompt, appCode = options.appCode, MFAEndpoint = options.MFAEndpoint, onAuthSuccess = options.onAuthSuccess, onAuthError = options.onAuthError
|
|
407
|
+
var optStorageKey = options.storageKey, optScopes = options.scopes, prompt = options.prompt, appCode = options.appCode, MFAEndpoint = options.MFAEndpoint, onAuthSuccess = options.onAuthSuccess, onAuthError = options.onAuthError;
|
|
408
408
|
var storageKey = optStorageKey || "CAMS-MSAL-AUTH-SDK";
|
|
409
|
-
var
|
|
409
|
+
var _a = msalReact.useMsal(), instance = _a.instance, inProgress = _a.inProgress, accounts = _a.accounts;
|
|
410
410
|
var account = msalReact.useAccount(accounts[0] || {});
|
|
411
|
-
var
|
|
412
|
-
var
|
|
413
|
-
var
|
|
414
|
-
var
|
|
415
|
-
var
|
|
411
|
+
var _b = React.useState(null), error = _b[0], setError = _b[1];
|
|
412
|
+
var _c = React.useState(""), idToken = _c[0], setIdToken = _c[1];
|
|
413
|
+
var _d = React.useState(""), accessToken = _d[0], setAccessToken = _d[1];
|
|
414
|
+
var _e = React.useState(null), mfaAuthenticator = _e[0], setMfaAuthenticator = _e[1];
|
|
415
|
+
var _f = React.useState(false), requiresMFA = _f[0], setRequiresMFA = _f[1];
|
|
416
416
|
var isLoading = inProgress !== msalBrowser.InteractionStatus.None;
|
|
417
417
|
var isAuthenticated = !!account && !!accessToken && !requiresMFA;
|
|
418
418
|
var scopes = optScopes || ["openid", "profile", "email"];
|
|
@@ -579,7 +579,7 @@ function useCAMSMSALAuth(options) {
|
|
|
579
579
|
accessToken: accessToken,
|
|
580
580
|
idToken: idToken,
|
|
581
581
|
}));
|
|
582
|
-
setCookie
|
|
582
|
+
setCookie("CAMS-MSAL-AUTH-SDK-PROFILE", JSON.stringify({ type: "AUTH_SUCCESS", userProfile: __assign({}, data) }), 1);
|
|
583
583
|
setRequiresMFA(false);
|
|
584
584
|
// Set requiresMFA to false after storage update
|
|
585
585
|
camsSdk.Logger.debug("MFA completed successfully, storage updated", {
|
|
@@ -598,7 +598,7 @@ function useCAMSMSALAuth(options) {
|
|
|
598
598
|
}
|
|
599
599
|
return [2 /*return*/];
|
|
600
600
|
});
|
|
601
|
-
}); }, [mfaAuthenticator, accessToken, idToken, storageKey
|
|
601
|
+
}); }, [mfaAuthenticator, accessToken, idToken, storageKey]);
|
|
602
602
|
var sendEmailOTP = React.useCallback(function () { return __awaiter$1(_this, void 0, void 0, function () {
|
|
603
603
|
return __generator$1(this, function (_a) {
|
|
604
604
|
switch (_a.label) {
|
|
@@ -654,8 +654,7 @@ function useCAMSMSALAuth(options) {
|
|
|
654
654
|
requiresMFA: requiresMFA,
|
|
655
655
|
completeMFA: completeMFA,
|
|
656
656
|
sendEmailOTP: sendEmailOTP,
|
|
657
|
-
setRequiresMFA: setRequiresMFA
|
|
658
|
-
activeCookiePeriod: activeCookiePeriod,
|
|
657
|
+
setRequiresMFA: setRequiresMFA
|
|
659
658
|
};
|
|
660
659
|
}
|
|
661
660
|
|
|
@@ -1248,26 +1247,6 @@ function ProtectedRoute(_a) {
|
|
|
1248
1247
|
}
|
|
1249
1248
|
|
|
1250
1249
|
var CAMSMSALContext = React.createContext(null);
|
|
1251
|
-
var setCookie = function (name, value, days) {
|
|
1252
|
-
if (days === void 0) { days = 1; }
|
|
1253
|
-
var expires = new Date(Date.now() + days * 864e5).toUTCString();
|
|
1254
|
-
camsSdk.Logger.debug("Auth Cookie Expires >>>", { name: name, value: value, expires: expires });
|
|
1255
|
-
document.cookie = "".concat(name, "=").concat(encodeURIComponent(value), "; expires=").concat(expires, "; path=/; samesite=Lax");
|
|
1256
|
-
};
|
|
1257
|
-
var getCookie = function (name) {
|
|
1258
|
-
var _a;
|
|
1259
|
-
return ((_a = document.cookie
|
|
1260
|
-
.split("; ")
|
|
1261
|
-
.find(function (row) { return row.startsWith(name + "="); })) === null || _a === void 0 ? void 0 : _a.split("=")[1])
|
|
1262
|
-
? decodeURIComponent(document.cookie
|
|
1263
|
-
.split("; ")
|
|
1264
|
-
.find(function (row) { return row.startsWith(name + "="); })
|
|
1265
|
-
.split("=")[1])
|
|
1266
|
-
: null;
|
|
1267
|
-
};
|
|
1268
|
-
var deleteCookie = function (name) {
|
|
1269
|
-
document.cookie = name + "=; Max-Age=-99999999; path=/";
|
|
1270
|
-
};
|
|
1271
1250
|
var isTokenValid = function (token) {
|
|
1272
1251
|
try {
|
|
1273
1252
|
var payload = JSON.parse(atob(token.split(".")[1]));
|
|
@@ -1324,7 +1303,7 @@ function CAMSMSALProviderInner(_a) {
|
|
|
1324
1303
|
React.useEffect(function () {
|
|
1325
1304
|
if (typeof window !== "undefined") {
|
|
1326
1305
|
if (userProfile) {
|
|
1327
|
-
setCookie(profileStorageKey, JSON.stringify(userProfile),
|
|
1306
|
+
setCookie(profileStorageKey, JSON.stringify(userProfile), 1); // Store for 1 day
|
|
1328
1307
|
}
|
|
1329
1308
|
else {
|
|
1330
1309
|
deleteCookie(profileStorageKey);
|
|
@@ -1351,9 +1330,7 @@ function CAMSMSALProviderInner(_a) {
|
|
|
1351
1330
|
}
|
|
1352
1331
|
function CAMSMSALProvider(props) {
|
|
1353
1332
|
var msalConfig = props.msalConfig, msalInstance = props.msalInstance;
|
|
1354
|
-
var instance =
|
|
1355
|
-
? msalInstance || new msalBrowser.PublicClientApplication(msalConfig)
|
|
1356
|
-
: null;
|
|
1333
|
+
var instance = msalInstance || new msalBrowser.PublicClientApplication(msalConfig);
|
|
1357
1334
|
return (jsxRuntimeExports.jsx(msalReact.MsalProvider, { instance: instance, children: jsxRuntimeExports.jsx(CAMSMSALProviderInner, __assign({}, props)) }));
|
|
1358
1335
|
}
|
|
1359
1336
|
function useCAMSMSALContext() {
|
|
@@ -1402,7 +1379,7 @@ function CAMSProviderCore(props) {
|
|
|
1402
1379
|
if (typeof window === "undefined")
|
|
1403
1380
|
return null;
|
|
1404
1381
|
try {
|
|
1405
|
-
var storedProfile = getCookie
|
|
1382
|
+
var storedProfile = getCookie(profileStorageKey);
|
|
1406
1383
|
return storedProfile ? JSON.parse(storedProfile) : null;
|
|
1407
1384
|
}
|
|
1408
1385
|
catch (_a) {
|
|
@@ -1412,7 +1389,7 @@ function CAMSProviderCore(props) {
|
|
|
1412
1389
|
var _a = React.useState(getInitialProfile), userProfile = _a[0], setUserProfile = _a[1];
|
|
1413
1390
|
React.useEffect(function () {
|
|
1414
1391
|
if (typeof window !== "undefined") {
|
|
1415
|
-
var storedProfile = getCookie
|
|
1392
|
+
var storedProfile = getCookie(profileStorageKey);
|
|
1416
1393
|
if (storedProfile) {
|
|
1417
1394
|
try {
|
|
1418
1395
|
setUserProfile(JSON.parse(storedProfile));
|
|
@@ -1424,10 +1401,10 @@ function CAMSProviderCore(props) {
|
|
|
1424
1401
|
React.useEffect(function () {
|
|
1425
1402
|
if (typeof window !== "undefined") {
|
|
1426
1403
|
if (userProfile) {
|
|
1427
|
-
setCookie
|
|
1404
|
+
setCookie(profileStorageKey, JSON.stringify(userProfile), 1);
|
|
1428
1405
|
}
|
|
1429
1406
|
else {
|
|
1430
|
-
deleteCookie
|
|
1407
|
+
deleteCookie(profileStorageKey);
|
|
1431
1408
|
}
|
|
1432
1409
|
}
|
|
1433
1410
|
}, [userProfile, profileStorageKey]);
|
|
@@ -1439,7 +1416,7 @@ function CAMSProviderCore(props) {
|
|
|
1439
1416
|
_a.sent();
|
|
1440
1417
|
setUserProfile(null);
|
|
1441
1418
|
if (typeof window !== "undefined") {
|
|
1442
|
-
deleteCookie
|
|
1419
|
+
deleteCookie(profileStorageKey);
|
|
1443
1420
|
}
|
|
1444
1421
|
return [2 /*return*/];
|
|
1445
1422
|
}
|
|
@@ -1484,13 +1461,11 @@ function UnifiedCAMSProvider(props) {
|
|
|
1484
1461
|
// Validate appCode is a valid GUID
|
|
1485
1462
|
var appCodeValidation = GuidSchema.safeParse(props.appCode);
|
|
1486
1463
|
if (!appCodeValidation.success) {
|
|
1487
|
-
throw new Error("Invalid
|
|
1464
|
+
throw new Error("Invalid CAS APP CODE: ".concat(appCodeValidation.error.issues[0].message));
|
|
1488
1465
|
}
|
|
1489
1466
|
if (props.mode === "MSAL") {
|
|
1490
1467
|
var msalConfig = props.msalConfig, msalInstance = props.msalInstance;
|
|
1491
|
-
var instance =
|
|
1492
|
-
? msalInstance || new msalBrowser.PublicClientApplication(msalConfig)
|
|
1493
|
-
: null;
|
|
1468
|
+
var instance = msalInstance || new msalBrowser.PublicClientApplication(msalConfig);
|
|
1494
1469
|
return (jsxRuntimeExports.jsx(msalReact.MsalProvider, { instance: instance, children: jsxRuntimeExports.jsx(CAMSProviderCore, __assign({}, props)) }));
|
|
1495
1470
|
}
|
|
1496
1471
|
return (jsxRuntimeExports.jsx(ClientOnly, { fallback: jsxRuntimeExports.jsx("div", { children: "Loading..." }), children: jsxRuntimeExports.jsx(CAMSProviderCore, __assign({}, props)) }));
|