@nibssplc/cams-sdk-react 0.0.1-beta.102 → 0.0.1-beta.104
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/DefaultLoginPage.d.ts +3 -1
- package/dist/components/MFAGate.d.ts +3 -1
- package/dist/hooks/useOTPHandler.d.ts +1 -1
- package/dist/index.cjs.js +110 -18
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +110 -18
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { MFAEndpoints } from "./MFAGate";
|
|
2
2
|
interface LoginPageProps {
|
|
3
3
|
usePassKey?: boolean;
|
|
4
|
+
CredentialsAuthEndpoint?: string;
|
|
5
|
+
useADLogin?: boolean;
|
|
4
6
|
MFAEndpoints: MFAEndpoints;
|
|
5
7
|
PassKeysRegisterProps?: Record<string, unknown>;
|
|
6
8
|
}
|
|
7
|
-
declare const DefaultLoginPage: ({ usePassKey, MFAEndpoints, PassKeysRegisterProps, }: LoginPageProps) => import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
declare const DefaultLoginPage: ({ usePassKey, useADLogin, MFAEndpoints, CredentialsAuthEndpoint, PassKeysRegisterProps, }: LoginPageProps) => import("react/jsx-runtime").JSX.Element;
|
|
8
10
|
export default DefaultLoginPage;
|
|
@@ -11,8 +11,10 @@ interface MFAGateProps {
|
|
|
11
11
|
children: React.ReactNode;
|
|
12
12
|
fallback?: React.ReactNode;
|
|
13
13
|
usePassKey?: boolean;
|
|
14
|
+
useADLogin?: boolean;
|
|
15
|
+
CredentialsAuthEndpoint?: string;
|
|
14
16
|
PassKeysRegisterProps?: Record<string, unknown>;
|
|
15
17
|
MFAEndpoints?: MFAEndpoints;
|
|
16
18
|
}
|
|
17
|
-
declare const MFAGate: ({ children, fallback, usePassKey, 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;
|
|
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;
|
|
18
20
|
export default MFAGate;
|
|
@@ -15,7 +15,7 @@ export declare const useOTPHandler: ({ provider, accessToken, idToken, appCode,
|
|
|
15
15
|
resetAttempts: () => void;
|
|
16
16
|
remainingAttempts: number;
|
|
17
17
|
};
|
|
18
|
-
export declare const
|
|
18
|
+
export declare const CredentialsHandler: (credentials: Credentials, appCode: string, CredAuthEndpoint: string, onAuthComplete: (state: boolean, data: UserValidatedResponse | null) => void) => {
|
|
19
19
|
handleSubmitCredentials: ({ username, password, MFACode, appCode, }: {
|
|
20
20
|
username: string;
|
|
21
21
|
password: string;
|
package/dist/index.cjs.js
CHANGED
|
@@ -588,7 +588,7 @@ function register(options) {
|
|
|
588
588
|
alg: param.alg,
|
|
589
589
|
}); }), attestation: (((_b = options.attestation) === null || _b === void 0 ? void 0 : _b.toLowerCase()) || "none"), authenticatorSelection: __assign(__assign({}, options.authenticatorSelection), { residentKey: (((_d = (_c = options.authenticatorSelection) === null || _c === void 0 ? void 0 : _c.residentKey) === null || _d === void 0 ? void 0 : _d.toLowerCase()) ||
|
|
590
590
|
"discouraged"), userVerification: (((_f = (_e = options.authenticatorSelection) === null || _e === void 0 ? void 0 : _e.userVerification) === null || _f === void 0 ? void 0 : _f.toLowerCase()) ||
|
|
591
|
-
"
|
|
591
|
+
"discouraged") }) }),
|
|
592
592
|
})];
|
|
593
593
|
case 1:
|
|
594
594
|
credential = _k.sent();
|
|
@@ -1869,6 +1869,81 @@ var useOTPHandler = function (_a) {
|
|
|
1869
1869
|
remainingAttempts: MAX_ATTEMPTS - attemptCount,
|
|
1870
1870
|
};
|
|
1871
1871
|
};
|
|
1872
|
+
var CredentialsHandler = function (credentials, appCode, CredAuthEndpoint, onAuthComplete) {
|
|
1873
|
+
var _a = React.useState(false), loading = _a[0], setLoading = _a[1];
|
|
1874
|
+
var _b = React.useState(0), attemptCount = _b[0], setAttemptCount = _b[1];
|
|
1875
|
+
var _c = React.useState(false), isMaxAttemptsReached = _c[0], setIsMaxAttemptsReached = _c[1];
|
|
1876
|
+
var handleSubmitCredentials = React.useMemo(function () {
|
|
1877
|
+
return function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
|
|
1878
|
+
var currentAttempt, response, error_2, currentAttempt;
|
|
1879
|
+
var username = _b.username, password = _b.password, MFACode = _b.MFACode, appCode = _b.appCode;
|
|
1880
|
+
return __generator(this, function (_c) {
|
|
1881
|
+
switch (_c.label) {
|
|
1882
|
+
case 0:
|
|
1883
|
+
_c.trys.push([0, 2, 3, 4]);
|
|
1884
|
+
setLoading(true);
|
|
1885
|
+
currentAttempt = attemptCount + 1;
|
|
1886
|
+
setAttemptCount(currentAttempt);
|
|
1887
|
+
return [4 /*yield*/, axios.post(CredAuthEndpoint, {
|
|
1888
|
+
username: username,
|
|
1889
|
+
password: password,
|
|
1890
|
+
MFACode: MFACode,
|
|
1891
|
+
appCode: appCode,
|
|
1892
|
+
}, {
|
|
1893
|
+
headers: {
|
|
1894
|
+
"X-Device-ID": GenerateDeviceId(),
|
|
1895
|
+
},
|
|
1896
|
+
timeout: 605000,
|
|
1897
|
+
})];
|
|
1898
|
+
case 1:
|
|
1899
|
+
response = (_c.sent()).data;
|
|
1900
|
+
if (response) {
|
|
1901
|
+
onAuthComplete(true, response);
|
|
1902
|
+
return [2 /*return*/, true];
|
|
1903
|
+
}
|
|
1904
|
+
else {
|
|
1905
|
+
if (currentAttempt >= MAX_ATTEMPTS) {
|
|
1906
|
+
setIsMaxAttemptsReached(true);
|
|
1907
|
+
onAuthComplete(false, {
|
|
1908
|
+
message: "Maximum attempts reached",
|
|
1909
|
+
});
|
|
1910
|
+
}
|
|
1911
|
+
else {
|
|
1912
|
+
onAuthComplete(false, response.response.data);
|
|
1913
|
+
}
|
|
1914
|
+
return [2 /*return*/, false];
|
|
1915
|
+
}
|
|
1916
|
+
case 2:
|
|
1917
|
+
error_2 = _c.sent();
|
|
1918
|
+
console.error(error_2);
|
|
1919
|
+
currentAttempt = attemptCount + 1;
|
|
1920
|
+
if (currentAttempt >= MAX_ATTEMPTS) {
|
|
1921
|
+
setIsMaxAttemptsReached(true);
|
|
1922
|
+
onAuthComplete(false, error_2.response.data);
|
|
1923
|
+
}
|
|
1924
|
+
else {
|
|
1925
|
+
onAuthComplete(false, error_2.response.data);
|
|
1926
|
+
}
|
|
1927
|
+
onAuthComplete(false, error_2.response.data);
|
|
1928
|
+
return [2 /*return*/, false];
|
|
1929
|
+
case 3:
|
|
1930
|
+
setLoading(false);
|
|
1931
|
+
return [7 /*endfinally*/];
|
|
1932
|
+
case 4: return [2 /*return*/];
|
|
1933
|
+
}
|
|
1934
|
+
});
|
|
1935
|
+
}); };
|
|
1936
|
+
}, [credentials.username, credentials.password, credentials.MFACode]);
|
|
1937
|
+
return {
|
|
1938
|
+
handleSubmitCredentials: handleSubmitCredentials,
|
|
1939
|
+
loading: loading,
|
|
1940
|
+
setLoading: setLoading,
|
|
1941
|
+
attemptCount: attemptCount,
|
|
1942
|
+
isMaxAttemptsReached: isMaxAttemptsReached,
|
|
1943
|
+
// resetAttempts,
|
|
1944
|
+
remainingAttempts: MAX_ATTEMPTS - attemptCount,
|
|
1945
|
+
};
|
|
1946
|
+
};
|
|
1872
1947
|
|
|
1873
1948
|
var MFAOptions = function (_a) {
|
|
1874
1949
|
var onComplete = _a.onComplete, onAuthFailed = _a.onAuthFailed, MFAEndpoints = _a.MFAEndpoints, usePassKey = _a.usePassKey;
|
|
@@ -2102,17 +2177,27 @@ var ADLoginModal = function (_a) {
|
|
|
2102
2177
|
form.reset();
|
|
2103
2178
|
setMfaCode("");
|
|
2104
2179
|
};
|
|
2105
|
-
return (jsxRuntimeExports.jsx(Dialog, { open: open, onOpenChange: handleClose, children: jsxRuntimeExports.jsxs(DialogContent, { className: "sm:max-w-[
|
|
2180
|
+
return (jsxRuntimeExports.jsx(Dialog, { open: open, onOpenChange: handleClose, children: jsxRuntimeExports.jsxs(DialogContent, { className: "sm:max-w-[75%] max-w-[400px]", children: [jsxRuntimeExports.jsx(DialogHeader, { children: jsxRuntimeExports.jsxs("div", { className: "flex items-center gap-2", children: [jsxRuntimeExports.jsx(lucideReact.KeyIcon, { className: "w-8 h-8 text-[#506f4a]" }), jsxRuntimeExports.jsx(DialogTitle, { className: "text-2xl", children: "Sign in with AD" })] }) }), step === "credentials" ? (jsxRuntimeExports.jsx(Form, __assign({}, form, { children: jsxRuntimeExports.jsxs("form", { onSubmit: form.handleSubmit(handleCredentialsSubmit), className: "space-y-4", children: [jsxRuntimeExports.jsx(FormField, { control: form.control, name: "username", render: function (_a) {
|
|
2106
2181
|
var field = _a.field;
|
|
2107
|
-
return (jsxRuntimeExports.jsxs(FormItem, { children: [jsxRuntimeExports.jsx(FormLabel, { children: "Username" }), jsxRuntimeExports.jsx(FormControl, { children: jsxRuntimeExports.jsx(Input, __assign({ placeholder: "Enter your username" }, field)) }), jsxRuntimeExports.jsx(FormMessage, {})] }));
|
|
2182
|
+
return (jsxRuntimeExports.jsxs(FormItem, { children: [jsxRuntimeExports.jsx(FormLabel, { children: "Username" }), jsxRuntimeExports.jsx(FormControl, { children: jsxRuntimeExports.jsx(Input, __assign({ className: "h-12", placeholder: "Enter your username" }, field)) }), jsxRuntimeExports.jsx(FormMessage, {})] }));
|
|
2108
2183
|
} }), jsxRuntimeExports.jsx(FormField, { control: form.control, name: "password", render: function (_a) {
|
|
2109
2184
|
var field = _a.field;
|
|
2110
|
-
return (jsxRuntimeExports.jsxs(FormItem, { children: [jsxRuntimeExports.jsx(FormLabel, { children: "Password" }), jsxRuntimeExports.jsx(FormControl, { children: jsxRuntimeExports.jsx(Input, __assign({ type: "password", placeholder: "Enter your password" }, field)) }), jsxRuntimeExports.jsx(FormMessage, {})] }));
|
|
2185
|
+
return (jsxRuntimeExports.jsxs(FormItem, { children: [jsxRuntimeExports.jsx(FormLabel, { children: "Password" }), jsxRuntimeExports.jsx(FormControl, { children: jsxRuntimeExports.jsx(Input, __assign({ className: "h-12", type: "password", placeholder: "Enter your password" }, field)) }), jsxRuntimeExports.jsx(FormMessage, {})] }));
|
|
2111
2186
|
} }), jsxRuntimeExports.jsx(Button, { type: "submit", className: "w-full bg-[#506f4a] hover:bg-[#506f4a]/90", children: "Continue" })] }) }))) : (jsxRuntimeExports.jsxs("div", { className: "space-y-4", children: [jsxRuntimeExports.jsx(GenericOTPVerifier, { value: mfaCode, setValue: setMfaCode, setLoading: setIsLoading, isDisabled: isLoading, onChangeOTP: handleMFASubmit, fieldName: "AuthenticatorCode" }), isLoading && (jsxRuntimeExports.jsxs("div", { className: "flex items-center justify-center gap-2 text-sm text-muted-foreground", children: [jsxRuntimeExports.jsx(lucideReact.Loader2, { className: "w-4 h-4 animate-spin" }), jsxRuntimeExports.jsx("span", { children: "Verifying..." })] }))] }))] }) }));
|
|
2112
2187
|
};
|
|
2113
2188
|
|
|
2114
2189
|
var DefaultLoginPage = function (_a) {
|
|
2115
|
-
var usePassKey = _a.usePassKey, MFAEndpoints = _a.MFAEndpoints, PassKeysRegisterProps = _a.PassKeysRegisterProps;
|
|
2190
|
+
var usePassKey = _a.usePassKey, useADLogin = _a.useADLogin, MFAEndpoints = _a.MFAEndpoints, CredentialsAuthEndpoint = _a.CredentialsAuthEndpoint, PassKeysRegisterProps = _a.PassKeysRegisterProps;
|
|
2191
|
+
var cardVariants = {
|
|
2192
|
+
hidden: { opacity: 0, scale: 0.8, y: 50 },
|
|
2193
|
+
visible: {
|
|
2194
|
+
opacity: 1,
|
|
2195
|
+
scale: 1,
|
|
2196
|
+
y: 0,
|
|
2197
|
+
transition: { type: "spring", duration: 0.6 },
|
|
2198
|
+
},
|
|
2199
|
+
exit: { opacity: 0, scale: 0.8, y: -50, transition: { duration: 0.3 } },
|
|
2200
|
+
};
|
|
2116
2201
|
var context = useCAMSContext();
|
|
2117
2202
|
var login = context.login, isLoading = context.isLoading, authMode = context.authMode;
|
|
2118
2203
|
var _b = React.useState(false), showADModal = _b[0], setShowADModal = _b[1];
|
|
@@ -2126,16 +2211,6 @@ var DefaultLoginPage = function (_a) {
|
|
|
2126
2211
|
console.warn("Regular CAMS login requires configuration");
|
|
2127
2212
|
}
|
|
2128
2213
|
};
|
|
2129
|
-
var cardVariants = {
|
|
2130
|
-
hidden: { opacity: 0, scale: 0.8, y: 50 },
|
|
2131
|
-
visible: {
|
|
2132
|
-
opacity: 1,
|
|
2133
|
-
scale: 1,
|
|
2134
|
-
y: 0,
|
|
2135
|
-
transition: { type: "spring", duration: 0.6 },
|
|
2136
|
-
},
|
|
2137
|
-
exit: { opacity: 0, scale: 0.8, y: -50, transition: { duration: 0.3 } },
|
|
2138
|
-
};
|
|
2139
2214
|
var handleRegister = function (data) { return __awaiter(void 0, void 0, void 0, function () {
|
|
2140
2215
|
var options, attestationResponse, error_1;
|
|
2141
2216
|
return __generator(this, function (_a) {
|
|
@@ -2185,11 +2260,28 @@ var DefaultLoginPage = function (_a) {
|
|
|
2185
2260
|
// variant="outline"
|
|
2186
2261
|
, {
|
|
2187
2262
|
// variant="outline"
|
|
2188
|
-
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" })] }),
|
|
2263
|
+
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: "w-24 h-24 text-[#506f4a]" }), jsxRuntimeExports.jsx("span", { children: isLoading
|
|
2264
|
+
? "Logging in..."
|
|
2265
|
+
: "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: "w-12 h-12 text-[#506f4a]" }), 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, onLogin: function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
|
|
2189
2266
|
var username = _b.username, password = _b.password, MFACode = _b.MFACode;
|
|
2190
2267
|
return __generator(this, function (_c) {
|
|
2191
2268
|
// Implement your AD login logic here
|
|
2192
2269
|
console.log("AD Login:", { username: username, password: password, MFACode: MFACode });
|
|
2270
|
+
// Example: await adLoginService(username, password, mfaCode);
|
|
2271
|
+
CredentialsHandler({ username: username, password: password, MFACode: MFACode }, context.appCode, CredentialsAuthEndpoint !== null && CredentialsAuthEndpoint !== void 0 ? CredentialsAuthEndpoint : "/api/auth/validate", function (state, data) { return __awaiter(void 0, void 0, void 0, function () {
|
|
2272
|
+
return __generator(this, function (_a) {
|
|
2273
|
+
console.log(data);
|
|
2274
|
+
if (state && data) {
|
|
2275
|
+
context.isAuthenticated = true;
|
|
2276
|
+
context.requiresMFA = false;
|
|
2277
|
+
context.setUserProfile({
|
|
2278
|
+
type: "AUTH_SUCCESS",
|
|
2279
|
+
userProfile: __assign({}, data),
|
|
2280
|
+
});
|
|
2281
|
+
}
|
|
2282
|
+
return [2 /*return*/];
|
|
2283
|
+
});
|
|
2284
|
+
}); });
|
|
2193
2285
|
return [2 /*return*/];
|
|
2194
2286
|
});
|
|
2195
2287
|
}); } })] }));
|
|
@@ -2212,7 +2304,7 @@ var MFAGate = function (_a) {
|
|
|
2212
2304
|
// loginComponent: LoginComponent = DefaultLoginPage,
|
|
2213
2305
|
_c = _a.usePassKey,
|
|
2214
2306
|
// loginComponent: LoginComponent = DefaultLoginPage,
|
|
2215
|
-
usePassKey = _c === void 0 ? false : _c, PassKeysRegisterProps = _a.PassKeysRegisterProps, MFAEndpoints = _a.MFAEndpoints;
|
|
2307
|
+
usePassKey = _c === void 0 ? false : _c, _d = _a.useADLogin, useADLogin = _d === void 0 ? false : _d, CredentialsAuthEndpoint = _a.CredentialsAuthEndpoint, PassKeysRegisterProps = _a.PassKeysRegisterProps, MFAEndpoints = _a.MFAEndpoints;
|
|
2216
2308
|
var context = useCAMSContext();
|
|
2217
2309
|
var validatedMFAEndpoints = React.useMemo(function () {
|
|
2218
2310
|
var parsed = MFAEndpointsSchema.safeParse(MFAEndpoints);
|
|
@@ -2247,7 +2339,7 @@ var MFAGate = function (_a) {
|
|
|
2247
2339
|
return (jsxRuntimeExports.jsx(MFAOptions, { MFAEndpoints: validatedMFAEndpoints, usePassKey: usePassKey, onComplete: handleComplete, onAuthFailed: handleAuthFailed }));
|
|
2248
2340
|
}
|
|
2249
2341
|
if (!context.isAuthenticated) {
|
|
2250
|
-
return (jsxRuntimeExports.jsx(DefaultLoginPage, { usePassKey: usePassKey, MFAEndpoints: MFAEndpoints, PassKeysRegisterProps: PassKeysRegisterProps }));
|
|
2342
|
+
return (jsxRuntimeExports.jsx(DefaultLoginPage, { usePassKey: usePassKey, useADLogin: useADLogin, MFAEndpoints: MFAEndpoints, PassKeysRegisterProps: PassKeysRegisterProps, CredentialsAuthEndpoint: CredentialsAuthEndpoint }));
|
|
2251
2343
|
}
|
|
2252
2344
|
return jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: children });
|
|
2253
2345
|
};
|