@nibssplc/cams-sdk-react 0.0.1-beta.60 → 0.0.1-beta.61
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/UnifiedCAMSProvider.d.ts +0 -1
- package/dist/context/CAMSContext.d.ts +0 -1
- package/dist/hooks/useCAMSMSALAuth.d.ts +1 -2
- package/dist/index.cjs.js +23 -19
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +23 -19
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
|
@@ -14,7 +14,6 @@ interface MSALProviderProps extends BaseProviderProps, UseCAMSMSALAuthOptions {
|
|
|
14
14
|
mode: "MSAL";
|
|
15
15
|
msalConfig: Configuration;
|
|
16
16
|
msalInstance?: PublicClientApplication;
|
|
17
|
-
validateTokenUrl?: string;
|
|
18
17
|
}
|
|
19
18
|
type UnifiedCAMSProviderProps = RegularProviderProps | MSALProviderProps;
|
|
20
19
|
export declare function UnifiedCAMSProvider(props: UnifiedCAMSProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -6,7 +6,6 @@ interface BaseCAMSContextValue {
|
|
|
6
6
|
userProfile: Profile | null;
|
|
7
7
|
setUserProfile: (profile: Profile | null) => void;
|
|
8
8
|
authMode: AuthMode;
|
|
9
|
-
validateTokenUrl?: string;
|
|
10
9
|
}
|
|
11
10
|
interface RegularCAMSContextValue extends BaseCAMSContextValue, UseCAMSAuthReturn {
|
|
12
11
|
authMode: "REGULAR";
|
|
@@ -5,12 +5,11 @@ export interface UseCAMSMSALAuthOptions {
|
|
|
5
5
|
onTokenExpired?: () => void;
|
|
6
6
|
scopes?: string[];
|
|
7
7
|
storageKey?: string;
|
|
8
|
-
mfaUrl?: string;
|
|
9
8
|
prompt?: string;
|
|
10
9
|
messageOrigin?: string;
|
|
11
10
|
appCode: string;
|
|
12
11
|
allowedOrigins?: string[];
|
|
13
|
-
|
|
12
|
+
MFAEndpoint: string;
|
|
14
13
|
}
|
|
15
14
|
export interface UseCAMSMSALAuthReturn {
|
|
16
15
|
login: () => Promise<void>;
|
package/dist/index.cjs.js
CHANGED
|
@@ -260,7 +260,7 @@ function useCAMSMSALAuth(options) {
|
|
|
260
260
|
var _this = this;
|
|
261
261
|
if (options === void 0) { options = {
|
|
262
262
|
appCode: "",
|
|
263
|
-
|
|
263
|
+
MFAEndpoint: "/auth/multi-factor",
|
|
264
264
|
storageKey: "CAMS-MSAL-AUTH-SDK",
|
|
265
265
|
}; }
|
|
266
266
|
var _a = msalReact.useMsal(), instance = _a.instance, inProgress = _a.inProgress, accounts = _a.accounts;
|
|
@@ -356,7 +356,7 @@ function useCAMSMSALAuth(options) {
|
|
|
356
356
|
idToken: response.idToken,
|
|
357
357
|
appCode: options.appCode,
|
|
358
358
|
provider: "MSAL",
|
|
359
|
-
apiEndpoint: options.
|
|
359
|
+
apiEndpoint: options.MFAEndpoint,
|
|
360
360
|
};
|
|
361
361
|
authenticator = new camsSdk.CAMSMFAAuthenticator(mfaConfig);
|
|
362
362
|
setMfaAuthenticator(authenticator);
|
|
@@ -1138,14 +1138,14 @@ var deleteCookie = function (name) {
|
|
|
1138
1138
|
};
|
|
1139
1139
|
function CAMSProviderCore(props) {
|
|
1140
1140
|
var _this = this;
|
|
1141
|
-
var
|
|
1141
|
+
var children = props.children, mode = props.mode, appCode = props.appCode;
|
|
1142
1142
|
// Always call both hooks to satisfy Rules of Hooks
|
|
1143
1143
|
var regularAuth = useCAMSAuth(mode === "REGULAR"
|
|
1144
1144
|
? __assign(__assign({}, props), { appCode: appCode })
|
|
1145
1145
|
: { appCode: "" });
|
|
1146
1146
|
var msalAuth = useCAMSMSALAuth(mode === "MSAL"
|
|
1147
1147
|
? __assign(__assign({}, props), { appCode: appCode })
|
|
1148
|
-
: { appCode: "" });
|
|
1148
|
+
: { appCode: "", MFAEndpoint: "/auth/multi-factor" });
|
|
1149
1149
|
var auth = mode === "REGULAR" ? regularAuth : msalAuth;
|
|
1150
1150
|
var profileStorageKey = "".concat(auth.storageKey, "-PROFILE");
|
|
1151
1151
|
var getInitialProfile = function () {
|
|
@@ -1159,7 +1159,7 @@ function CAMSProviderCore(props) {
|
|
|
1159
1159
|
return null;
|
|
1160
1160
|
}
|
|
1161
1161
|
};
|
|
1162
|
-
var
|
|
1162
|
+
var _a = React.useState(getInitialProfile), userProfile = _a[0], setUserProfile = _a[1];
|
|
1163
1163
|
React.useEffect(function () {
|
|
1164
1164
|
if (typeof window !== "undefined") {
|
|
1165
1165
|
var storedProfile = getCookie(profileStorageKey);
|
|
@@ -1197,7 +1197,11 @@ function CAMSProviderCore(props) {
|
|
|
1197
1197
|
}); };
|
|
1198
1198
|
// Handle MFA completion for MSAL mode
|
|
1199
1199
|
React.useEffect(function () {
|
|
1200
|
-
if (mode === "MSAL" &&
|
|
1200
|
+
if (mode === "MSAL" &&
|
|
1201
|
+
"requiresMFA" in auth &&
|
|
1202
|
+
!auth.requiresMFA &&
|
|
1203
|
+
auth.isAuthenticated &&
|
|
1204
|
+
!userProfile) {
|
|
1201
1205
|
// MFA completed, extract profile from stored data
|
|
1202
1206
|
var storedData = getCookie(auth.storageKey);
|
|
1203
1207
|
if (storedData) {
|
|
@@ -1212,8 +1216,8 @@ function CAMSProviderCore(props) {
|
|
|
1212
1216
|
}
|
|
1213
1217
|
}, [mode, auth, userProfile]);
|
|
1214
1218
|
var value = React.useMemo(function () {
|
|
1215
|
-
return (__assign(__assign({}, auth), { logout: enhancedLogout, userProfile: userProfile, setUserProfile: setUserProfile, authMode: mode
|
|
1216
|
-
}, [auth, userProfile, mode
|
|
1219
|
+
return (__assign(__assign({}, auth), { logout: enhancedLogout, userProfile: userProfile, setUserProfile: setUserProfile, authMode: mode }));
|
|
1220
|
+
}, [auth, userProfile, mode]);
|
|
1217
1221
|
return jsxRuntimeExports.jsx(CAMSContext.Provider, { value: value, children: children });
|
|
1218
1222
|
}
|
|
1219
1223
|
function UnifiedCAMSProvider(props) {
|
|
@@ -1222,11 +1226,11 @@ function UnifiedCAMSProvider(props) {
|
|
|
1222
1226
|
if (!appCodeValidation.success) {
|
|
1223
1227
|
throw new Error("Invalid appCode: ".concat(appCodeValidation.error.issues[0].message));
|
|
1224
1228
|
}
|
|
1225
|
-
// Validate
|
|
1226
|
-
if (props.mode === "MSAL" && props.
|
|
1227
|
-
var urlValidation = UrlSchema.safeParse(props.
|
|
1229
|
+
// Validate apiEndpoint if provided
|
|
1230
|
+
if (props.mode === "MSAL" && props.MFAEndpoint) {
|
|
1231
|
+
var urlValidation = UrlSchema.safeParse(props.MFAEndpoint);
|
|
1228
1232
|
if (!urlValidation.success) {
|
|
1229
|
-
throw new Error("Invalid
|
|
1233
|
+
throw new Error("Invalid apiEndpoint: ".concat(urlValidation.error.issues[0].message));
|
|
1230
1234
|
}
|
|
1231
1235
|
}
|
|
1232
1236
|
if (props.mode === "MSAL") {
|
|
@@ -1680,18 +1684,18 @@ var MFAOptions = function (_a) {
|
|
|
1680
1684
|
var _f = React.useState(null), authType = _f[0], setAuthType = _f[1];
|
|
1681
1685
|
var context = useCAMSContext();
|
|
1682
1686
|
var isSDKMode = context.authMode === "MSAL" && "completeMFA" in context;
|
|
1683
|
-
var
|
|
1687
|
+
var sendEmailOTP = (isSDKMode
|
|
1684
1688
|
? context
|
|
1685
|
-
: {
|
|
1689
|
+
: { sendEmailOTP: null }).sendEmailOTP;
|
|
1686
1690
|
var accessToken = context.authMode === "MSAL" ? context.accessToken : "";
|
|
1687
1691
|
var idToken = context.authMode === "MSAL" ? context.idToken : "";
|
|
1688
|
-
var
|
|
1692
|
+
var _g = useOTPHandler({
|
|
1689
1693
|
provider: "azure",
|
|
1690
1694
|
accessToken: accessToken || "",
|
|
1691
1695
|
idToken: idToken || "",
|
|
1692
1696
|
appCode: context.appCode || "",
|
|
1693
1697
|
authenticationType: authType,
|
|
1694
|
-
validateTokenUrl: context.
|
|
1698
|
+
validateTokenUrl: ((context.authMode === "MSAL" && "MFAEndpoint" in context) ? (context.MFAEndpoint || "/api/auth/verify-mfa") : "/api/validate-token"),
|
|
1695
1699
|
onAuthComplete: function (success, data) {
|
|
1696
1700
|
if (success) {
|
|
1697
1701
|
setShowSuccessAnimation(true);
|
|
@@ -1705,7 +1709,7 @@ var MFAOptions = function (_a) {
|
|
|
1705
1709
|
}
|
|
1706
1710
|
}
|
|
1707
1711
|
},
|
|
1708
|
-
}), handleSubmitOTP =
|
|
1712
|
+
}), handleSubmitOTP = _g.handleSubmitOTP, loading = _g.loading, attemptCount = _g.attemptCount, isMaxAttemptsReached = _g.isMaxAttemptsReached, remainingAttempts = _g.remainingAttempts, resetAttempts = _g.resetAttempts;
|
|
1709
1713
|
var handleGoBack = function () {
|
|
1710
1714
|
setAuthType(null);
|
|
1711
1715
|
setOtpVisible(false);
|
|
@@ -1743,7 +1747,7 @@ var MFAOptions = function (_a) {
|
|
|
1743
1747
|
resetAttempts();
|
|
1744
1748
|
setAuthType("AuthenticatorCode");
|
|
1745
1749
|
setOtpVisible(true);
|
|
1746
|
-
}, children: [jsxRuntimeExports.jsx("img", { src: "/microsoftauthenticator.svg", alt: "Authenticator", className: "rounded-full", width: 24, height: 24 }), 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" })] })] })] })] }));
|
|
1750
|
+
}, children: [jsxRuntimeExports.jsx("img", { src: "/images/microsoftauthenticator.svg", alt: "Authenticator", className: "rounded-full", width: 24, height: 24 }), 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" })] })] })] })] }));
|
|
1747
1751
|
}
|
|
1748
1752
|
else if (authType === "EmailOTP") {
|
|
1749
1753
|
content = (jsxRuntimeExports.jsxs(Dialog, { open: otpVisible, onOpenChange: function () {
|
|
@@ -1755,7 +1759,7 @@ var MFAOptions = function (_a) {
|
|
|
1755
1759
|
else if (authType === "AuthenticatorCode") {
|
|
1756
1760
|
content = (jsxRuntimeExports.jsxs(Dialog, { open: otpVisible, onOpenChange: handleGoBack, children: [jsxRuntimeExports.jsx(DialogHeader, { children: jsxRuntimeExports.jsx(DialogTitle, { children: "Authenticator App" }) }), jsxRuntimeExports.jsx(DialogContent, { className: "sm:max-w-[425px]", children: loading ? (jsxRuntimeExports.jsx("div", { className: "p-3 flex justify-center items-center", children: jsxRuntimeExports.jsx(LoadingSpinner, {}) })) : (jsxRuntimeExports.jsxs("div", { className: "space-y-4", children: [jsxRuntimeExports.jsx("p", { className: "text-sm text-gray-600 text-center", children: "Enter the 6-digit Code from your Authenticator app" }), jsxRuntimeExports.jsx(GenericOTPVerifier, { value: value, setValue: setValue, isDisabled: loading || isMaxAttemptsReached, onChangeOTP: handleSubmitOTP, fieldName: "AuthenticatorCode", attemptCount: attemptCount, remainingAttempts: remainingAttempts, isMaxAttemptsReached: isMaxAttemptsReached })] })) })] }));
|
|
1757
1761
|
}
|
|
1758
|
-
return (jsxRuntimeExports.jsxs(Card, { className: "mx-auto space-y-6 p-6 bg-white rounded-lg shadow-md", children: [jsxRuntimeExports.jsxs(CardHeader, { children: [jsxRuntimeExports.jsx("img", { src: "/
|
|
1762
|
+
return (jsxRuntimeExports.jsx("div", { className: "flex justify-center items-center", children: jsxRuntimeExports.jsxs(Card, { className: "mx-auto space-y-6 p-6 bg-white rounded-lg shadow-md", children: [jsxRuntimeExports.jsxs(CardHeader, { children: [jsxRuntimeExports.jsx("img", { src: "/images/OTPAuthentication.svg", alt: "NIBSS Logo", width: 365, height: 365 }), jsxRuntimeExports.jsx(CardTitle, { className: "text-3xl font-bold mb-6 text-center", children: "Two-Factor Authentication" }), jsxRuntimeExports.jsx(CardTitle, { className: "text-gray-300 text-sm -tracking-wide text-center", children: "Your Microsoft account has been validated. Please complete two-factor authentication to continue." })] }), jsxRuntimeExports.jsx(CardContent, { children: content }), 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" })] })] }) }));
|
|
1759
1763
|
};
|
|
1760
1764
|
|
|
1761
1765
|
var LoginButton = function () {
|