@nibssplc/cams-sdk-react 1.0.0-rc.47 → 1.0.0-rc.48
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 +2 -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 +26 -20
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +26 -20
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
|
@@ -15,6 +15,7 @@ interface MFAGateProps {
|
|
|
15
15
|
CredentialsAuthEndpoint?: string;
|
|
16
16
|
PassKeysRegisterProps?: Record<string, unknown>;
|
|
17
17
|
MFAEndpoints?: MFAEndpoints;
|
|
18
|
+
requiresMFA?: boolean;
|
|
18
19
|
}
|
|
19
|
-
declare const MFAGate: ({ children, fallback, usePassKey, useADLogin, CredentialsAuthEndpoint, PassKeysRegisterProps, MFAEndpoints, }: MFAGateProps) => string | number | bigint | boolean | Iterable<import("react").ReactNode> | Promise<string | number | bigint | boolean | import("react").ReactPortal | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<import("react").ReactNode> | null | undefined> | import("react/jsx-runtime").JSX.Element | null;
|
|
20
|
+
declare const MFAGate: ({ children, fallback, usePassKey, useADLogin, CredentialsAuthEndpoint, PassKeysRegisterProps, MFAEndpoints, requiresMFA, }: MFAGateProps) => string | number | bigint | boolean | Iterable<import("react").ReactNode> | Promise<string | number | bigint | boolean | import("react").ReactPortal | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<import("react").ReactNode> | null | undefined> | import("react/jsx-runtime").JSX.Element | null;
|
|
20
21
|
export default MFAGate;
|
|
@@ -14,6 +14,11 @@ interface MSALProviderProps extends BaseProviderProps, Omit<UseCAMSMSALAuthOptio
|
|
|
14
14
|
mode: "MSAL";
|
|
15
15
|
msalConfig: Configuration;
|
|
16
16
|
msalInstance?: PublicClientApplication;
|
|
17
|
+
onAuthSuccess?: (tokens: {
|
|
18
|
+
accessToken: string;
|
|
19
|
+
idToken: string;
|
|
20
|
+
}) => void;
|
|
21
|
+
onAuthError?: (error: any) => void;
|
|
17
22
|
}
|
|
18
23
|
type UnifiedCAMSProviderProps = RegularProviderProps | MSALProviderProps;
|
|
19
24
|
export declare function UnifiedCAMSProvider(props: UnifiedCAMSProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -12,6 +12,11 @@ interface RegularCAMSContextValue extends BaseCAMSContextValue, UseCAMSAuthRetur
|
|
|
12
12
|
}
|
|
13
13
|
interface MSALCAMSContextValue extends BaseCAMSContextValue, UseCAMSMSALAuthReturn {
|
|
14
14
|
authMode: "MSAL";
|
|
15
|
+
onAuthSuccess?: (tokens: {
|
|
16
|
+
accessToken: string;
|
|
17
|
+
idToken: string;
|
|
18
|
+
}) => void;
|
|
19
|
+
onAuthError?: (error: any) => void;
|
|
15
20
|
}
|
|
16
21
|
export type CAMSContextValue = RegularCAMSContextValue | MSALCAMSContextValue;
|
|
17
22
|
export declare const CAMSContext: import("react").Context<CAMSContextValue | null>;
|
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
import "../utils/crypto-polyfill";
|
|
2
2
|
import { CAMSError, CAMSMFAAuthenticator, MFAResponse } from "@nibssplc/cams-sdk";
|
|
3
3
|
export interface UseCAMSMSALAuthOptions {
|
|
4
|
-
onAuthSuccess?: (tokens: {
|
|
5
|
-
accessToken: string;
|
|
6
|
-
idToken: string;
|
|
7
|
-
}) => void;
|
|
8
|
-
onAuthError?: (error: CAMSError) => void;
|
|
9
4
|
onTokenExpired?: () => void;
|
|
10
5
|
scopes?: string[];
|
|
11
6
|
storageKey?: string;
|
package/dist/index.cjs.js
CHANGED
|
@@ -434,7 +434,7 @@ var deleteCookie = function (name) {
|
|
|
434
434
|
|
|
435
435
|
function useCAMSMSALAuth(options) {
|
|
436
436
|
var _this = this;
|
|
437
|
-
var optStorageKey = options.storageKey, optScopes = options.scopes, prompt = options.prompt, appCode = options.appCode, MFAEndpoint = options.MFAEndpoint,
|
|
437
|
+
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;
|
|
438
438
|
var storageKey = optStorageKey || "CAMS-MSAL-AUTH-SDK";
|
|
439
439
|
var _b = msalReact.useMsal(), instance = _b.instance, inProgress = _b.inProgress, accounts = _b.accounts;
|
|
440
440
|
var account = msalReact.useAccount(accounts[0] || {});
|
|
@@ -563,10 +563,6 @@ function useCAMSMSALAuth(options) {
|
|
|
563
563
|
idToken: response.idToken,
|
|
564
564
|
}));
|
|
565
565
|
}
|
|
566
|
-
onAuthSuccess === null || onAuthSuccess === void 0 ? void 0 : onAuthSuccess({
|
|
567
|
-
accessToken: response.accessToken,
|
|
568
|
-
idToken: response.idToken,
|
|
569
|
-
});
|
|
570
566
|
return [3 /*break*/, 4];
|
|
571
567
|
case 3:
|
|
572
568
|
err_1 = _b.sent();
|
|
@@ -586,12 +582,10 @@ function useCAMSMSALAuth(options) {
|
|
|
586
582
|
((_a = err_1.message) === null || _a === void 0 ? void 0 : _a.includes("popup"))) {
|
|
587
583
|
camsError_1 = new camsSdk.CAMSError(camsSdk.CAMSErrorType.POPUP_BLOCKED, "Popup blocked by browser. Please allow popups and try again.");
|
|
588
584
|
setError(camsError_1);
|
|
589
|
-
onAuthError === null || onAuthError === void 0 ? void 0 : onAuthError(camsError_1);
|
|
590
585
|
return [2 /*return*/];
|
|
591
586
|
}
|
|
592
587
|
camsError = new camsSdk.CAMSError(camsSdk.CAMSErrorType.API_VALIDATION_ERROR, "Login failed: " + err_1.message || err_1);
|
|
593
588
|
setError(camsError);
|
|
594
|
-
onAuthError === null || onAuthError === void 0 ? void 0 : onAuthError(camsError);
|
|
595
589
|
return [3 /*break*/, 4];
|
|
596
590
|
case 4: return [2 /*return*/];
|
|
597
591
|
}
|
|
@@ -602,8 +596,6 @@ function useCAMSMSALAuth(options) {
|
|
|
602
596
|
prompt,
|
|
603
597
|
appCode,
|
|
604
598
|
MFAEndpoint,
|
|
605
|
-
onAuthSuccess,
|
|
606
|
-
onAuthError,
|
|
607
599
|
storageKey,
|
|
608
600
|
inProgress,
|
|
609
601
|
]);
|
|
@@ -1496,8 +1488,8 @@ function CAMSProviderCore(props) {
|
|
|
1496
1488
|
]);
|
|
1497
1489
|
var value = React.useMemo(function () {
|
|
1498
1490
|
auth.logout; var authRest = __rest(auth, ["logout"]);
|
|
1499
|
-
return __assign(__assign({}, authRest), { logout: enhancedLogout, userProfile: userProfile, setUserProfile: setUserProfile, authMode: mode });
|
|
1500
|
-
}, [auth, userProfile, mode]);
|
|
1491
|
+
return __assign(__assign({}, authRest), { logout: enhancedLogout, userProfile: userProfile, setUserProfile: setUserProfile, authMode: mode, onAuthSuccess: mode === "MSAL" ? props.onAuthSuccess : undefined, onAuthError: mode === "MSAL" ? props.onAuthError : undefined });
|
|
1492
|
+
}, [auth, userProfile, mode, props]);
|
|
1501
1493
|
return jsxRuntimeExports.jsx(CAMSContext.Provider, { value: value, children: children });
|
|
1502
1494
|
}
|
|
1503
1495
|
function UnifiedCAMSProvider(props) {
|
|
@@ -2418,7 +2410,7 @@ var MFAGate = function (_a) {
|
|
|
2418
2410
|
// loginComponent: LoginComponent = DefaultLoginPage,
|
|
2419
2411
|
_c = _a.usePassKey,
|
|
2420
2412
|
// loginComponent: LoginComponent = DefaultLoginPage,
|
|
2421
|
-
usePassKey = _c === void 0 ? false : _c, _d = _a.useADLogin, useADLogin = _d === void 0 ? false : _d, CredentialsAuthEndpoint = _a.CredentialsAuthEndpoint, PassKeysRegisterProps = _a.PassKeysRegisterProps, MFAEndpoints = _a.MFAEndpoints;
|
|
2413
|
+
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;
|
|
2422
2414
|
var context = useCAMSContext();
|
|
2423
2415
|
var validatedMFAEndpoints = React.useMemo(function () {
|
|
2424
2416
|
var parsed = MFAEndpointsSchema.safeParse(MFAEndpoints);
|
|
@@ -2429,19 +2421,32 @@ var MFAGate = function (_a) {
|
|
|
2429
2421
|
return parsed.data;
|
|
2430
2422
|
}, [MFAEndpoints]);
|
|
2431
2423
|
var handleComplete = React.useCallback(function (success) {
|
|
2432
|
-
|
|
2424
|
+
var _a;
|
|
2425
|
+
if (success && context.authMode === "MSAL") {
|
|
2426
|
+
(_a = context.onAuthSuccess) === null || _a === void 0 ? void 0 : _a.call(context, {
|
|
2427
|
+
accessToken: context.accessToken,
|
|
2428
|
+
idToken: context.idToken,
|
|
2429
|
+
});
|
|
2430
|
+
}
|
|
2431
|
+
else if (!success) {
|
|
2433
2432
|
camsSdk.Logger.error("MFA authentication failed");
|
|
2434
|
-
|
|
2433
|
+
}
|
|
2434
|
+
}, [context]);
|
|
2435
2435
|
var handleAuthFailed = React.useCallback(function () { return __awaiter$1(void 0, void 0, void 0, function () {
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2436
|
+
var _a;
|
|
2437
|
+
return __generator$1(this, function (_b) {
|
|
2438
|
+
switch (_b.label) {
|
|
2439
|
+
case 0:
|
|
2440
|
+
if (context.authMode === "MSAL" && context.error) {
|
|
2441
|
+
(_a = context.onAuthError) === null || _a === void 0 ? void 0 : _a.call(context, context.error);
|
|
2442
|
+
}
|
|
2443
|
+
return [4 /*yield*/, context.logout()];
|
|
2439
2444
|
case 1:
|
|
2440
|
-
|
|
2445
|
+
_b.sent();
|
|
2441
2446
|
return [2 /*return*/];
|
|
2442
2447
|
}
|
|
2443
2448
|
});
|
|
2444
|
-
}); }, [context
|
|
2449
|
+
}); }, [context]);
|
|
2445
2450
|
if (useADLogin && !CredentialsAuthEndpoint)
|
|
2446
2451
|
return jsxRuntimeExports.jsx(ErrorFallback, { message: "Invalid AD Login Configuration." });
|
|
2447
2452
|
if (!validatedMFAEndpoints)
|
|
@@ -2450,7 +2455,8 @@ var MFAGate = function (_a) {
|
|
|
2450
2455
|
return jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: children });
|
|
2451
2456
|
if (context.isLoading)
|
|
2452
2457
|
return fallback;
|
|
2453
|
-
|
|
2458
|
+
var shouldRequireMFA = requiresMFA !== null && requiresMFA !== void 0 ? requiresMFA : context.requiresMFA;
|
|
2459
|
+
if (shouldRequireMFA) {
|
|
2454
2460
|
return (jsxRuntimeExports.jsx(MFAOptions, { MFAEndpoints: validatedMFAEndpoints, usePassKey: usePassKey, onComplete: handleComplete, onAuthFailed: handleAuthFailed }));
|
|
2455
2461
|
}
|
|
2456
2462
|
if (!context.isAuthenticated) {
|