@nibssplc/cams-sdk-react 1.0.0-rc.47 → 1.0.0-rc.49
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/MFAGate.d.ts +7 -1
- package/dist/components/UnifiedCAMSProvider.d.ts +5 -0
- package/dist/context/CAMSContext.d.ts +5 -0
- package/dist/hooks/useCAMSMSALAuth.d.ts +0 -5
- package/dist/index.cjs.js +29 -20
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +29 -20
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -413,7 +413,7 @@ var deleteCookie = function (name) {
|
|
|
413
413
|
|
|
414
414
|
function useCAMSMSALAuth(options) {
|
|
415
415
|
var _this = this;
|
|
416
|
-
var optStorageKey = options.storageKey, optScopes = options.scopes, prompt = options.prompt, appCode = options.appCode, MFAEndpoint = options.MFAEndpoint,
|
|
416
|
+
var optStorageKey = options.storageKey, optScopes = options.scopes, prompt = options.prompt, appCode = options.appCode, MFAEndpoint = options.MFAEndpoint, _a = options.activeCookiePeriod, activeCookiePeriod = _a === void 0 ? 1 : _a;
|
|
417
417
|
var storageKey = optStorageKey || "CAMS-MSAL-AUTH-SDK";
|
|
418
418
|
var _b = useMsal(), instance = _b.instance, inProgress = _b.inProgress, accounts = _b.accounts;
|
|
419
419
|
var account = useAccount(accounts[0] || {});
|
|
@@ -542,10 +542,6 @@ function useCAMSMSALAuth(options) {
|
|
|
542
542
|
idToken: response.idToken,
|
|
543
543
|
}));
|
|
544
544
|
}
|
|
545
|
-
onAuthSuccess === null || onAuthSuccess === void 0 ? void 0 : onAuthSuccess({
|
|
546
|
-
accessToken: response.accessToken,
|
|
547
|
-
idToken: response.idToken,
|
|
548
|
-
});
|
|
549
545
|
return [3 /*break*/, 4];
|
|
550
546
|
case 3:
|
|
551
547
|
err_1 = _b.sent();
|
|
@@ -565,12 +561,10 @@ function useCAMSMSALAuth(options) {
|
|
|
565
561
|
((_a = err_1.message) === null || _a === void 0 ? void 0 : _a.includes("popup"))) {
|
|
566
562
|
camsError_1 = new CAMSError(CAMSErrorType.POPUP_BLOCKED, "Popup blocked by browser. Please allow popups and try again.");
|
|
567
563
|
setError(camsError_1);
|
|
568
|
-
onAuthError === null || onAuthError === void 0 ? void 0 : onAuthError(camsError_1);
|
|
569
564
|
return [2 /*return*/];
|
|
570
565
|
}
|
|
571
566
|
camsError = new CAMSError(CAMSErrorType.API_VALIDATION_ERROR, "Login failed: " + err_1.message || err_1);
|
|
572
567
|
setError(camsError);
|
|
573
|
-
onAuthError === null || onAuthError === void 0 ? void 0 : onAuthError(camsError);
|
|
574
568
|
return [3 /*break*/, 4];
|
|
575
569
|
case 4: return [2 /*return*/];
|
|
576
570
|
}
|
|
@@ -581,8 +575,6 @@ function useCAMSMSALAuth(options) {
|
|
|
581
575
|
prompt,
|
|
582
576
|
appCode,
|
|
583
577
|
MFAEndpoint,
|
|
584
|
-
onAuthSuccess,
|
|
585
|
-
onAuthError,
|
|
586
578
|
storageKey,
|
|
587
579
|
inProgress,
|
|
588
580
|
]);
|
|
@@ -1475,8 +1467,8 @@ function CAMSProviderCore(props) {
|
|
|
1475
1467
|
]);
|
|
1476
1468
|
var value = useMemo(function () {
|
|
1477
1469
|
auth.logout; var authRest = __rest(auth, ["logout"]);
|
|
1478
|
-
return __assign(__assign({}, authRest), { logout: enhancedLogout, userProfile: userProfile, setUserProfile: setUserProfile, authMode: mode });
|
|
1479
|
-
}, [auth, userProfile, mode]);
|
|
1470
|
+
return __assign(__assign({}, authRest), { logout: enhancedLogout, userProfile: userProfile, setUserProfile: setUserProfile, authMode: mode, onAuthSuccess: mode === "MSAL" ? props.onAuthSuccess : undefined, onAuthError: mode === "MSAL" ? props.onAuthError : undefined });
|
|
1471
|
+
}, [auth, userProfile, mode, props]);
|
|
1480
1472
|
return jsxRuntimeExports.jsx(CAMSContext.Provider, { value: value, children: children });
|
|
1481
1473
|
}
|
|
1482
1474
|
function UnifiedCAMSProvider(props) {
|
|
@@ -2397,7 +2389,7 @@ var MFAGate = function (_a) {
|
|
|
2397
2389
|
// loginComponent: LoginComponent = DefaultLoginPage,
|
|
2398
2390
|
_c = _a.usePassKey,
|
|
2399
2391
|
// loginComponent: LoginComponent = DefaultLoginPage,
|
|
2400
|
-
usePassKey = _c === void 0 ? false : _c, _d = _a.useADLogin, useADLogin = _d === void 0 ? false : _d, CredentialsAuthEndpoint = _a.CredentialsAuthEndpoint, PassKeysRegisterProps = _a.PassKeysRegisterProps, MFAEndpoints = _a.MFAEndpoints;
|
|
2392
|
+
usePassKey = _c === void 0 ? false : _c, _d = _a.useADLogin, useADLogin = _d === void 0 ? false : _d, CredentialsAuthEndpoint = _a.CredentialsAuthEndpoint, PassKeysRegisterProps = _a.PassKeysRegisterProps, MFAEndpoints = _a.MFAEndpoints, requiresMFA = _a.requiresMFA, onAuthSuccess = _a.onAuthSuccess, onAuthError = _a.onAuthError;
|
|
2401
2393
|
var context = useCAMSContext();
|
|
2402
2394
|
var validatedMFAEndpoints = useMemo(function () {
|
|
2403
2395
|
var parsed = MFAEndpointsSchema.safeParse(MFAEndpoints);
|
|
@@ -2408,19 +2400,35 @@ var MFAGate = function (_a) {
|
|
|
2408
2400
|
return parsed.data;
|
|
2409
2401
|
}, [MFAEndpoints]);
|
|
2410
2402
|
var handleComplete = useCallback(function (success) {
|
|
2411
|
-
|
|
2403
|
+
var _a;
|
|
2404
|
+
if (success && context.authMode === "MSAL") {
|
|
2405
|
+
var tokens = {
|
|
2406
|
+
accessToken: context.accessToken,
|
|
2407
|
+
idToken: context.idToken,
|
|
2408
|
+
};
|
|
2409
|
+
onAuthSuccess === null || onAuthSuccess === void 0 ? void 0 : onAuthSuccess(tokens);
|
|
2410
|
+
(_a = context.onAuthSuccess) === null || _a === void 0 ? void 0 : _a.call(context, tokens);
|
|
2411
|
+
}
|
|
2412
|
+
else if (!success) {
|
|
2412
2413
|
Logger.error("MFA authentication failed");
|
|
2413
|
-
|
|
2414
|
+
}
|
|
2415
|
+
}, [context, onAuthSuccess]);
|
|
2414
2416
|
var handleAuthFailed = useCallback(function () { return __awaiter$1(void 0, void 0, void 0, function () {
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2417
|
+
var _a;
|
|
2418
|
+
return __generator$1(this, function (_b) {
|
|
2419
|
+
switch (_b.label) {
|
|
2420
|
+
case 0:
|
|
2421
|
+
if (context.authMode === "MSAL" && context.error) {
|
|
2422
|
+
onAuthError === null || onAuthError === void 0 ? void 0 : onAuthError(context.error);
|
|
2423
|
+
(_a = context.onAuthError) === null || _a === void 0 ? void 0 : _a.call(context, context.error);
|
|
2424
|
+
}
|
|
2425
|
+
return [4 /*yield*/, context.logout()];
|
|
2418
2426
|
case 1:
|
|
2419
|
-
|
|
2427
|
+
_b.sent();
|
|
2420
2428
|
return [2 /*return*/];
|
|
2421
2429
|
}
|
|
2422
2430
|
});
|
|
2423
|
-
}); }, [context
|
|
2431
|
+
}); }, [context, onAuthError]);
|
|
2424
2432
|
if (useADLogin && !CredentialsAuthEndpoint)
|
|
2425
2433
|
return jsxRuntimeExports.jsx(ErrorFallback, { message: "Invalid AD Login Configuration." });
|
|
2426
2434
|
if (!validatedMFAEndpoints)
|
|
@@ -2429,7 +2437,8 @@ var MFAGate = function (_a) {
|
|
|
2429
2437
|
return jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: children });
|
|
2430
2438
|
if (context.isLoading)
|
|
2431
2439
|
return fallback;
|
|
2432
|
-
|
|
2440
|
+
var shouldRequireMFA = requiresMFA !== null && requiresMFA !== void 0 ? requiresMFA : context.requiresMFA;
|
|
2441
|
+
if (shouldRequireMFA) {
|
|
2433
2442
|
return (jsxRuntimeExports.jsx(MFAOptions, { MFAEndpoints: validatedMFAEndpoints, usePassKey: usePassKey, onComplete: handleComplete, onAuthFailed: handleAuthFailed }));
|
|
2434
2443
|
}
|
|
2435
2444
|
if (!context.isAuthenticated) {
|