@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
package/dist/index.esm.js
CHANGED
|
@@ -567,7 +567,7 @@ function register(options) {
|
|
|
567
567
|
alg: param.alg,
|
|
568
568
|
}); }), 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()) ||
|
|
569
569
|
"discouraged"), userVerification: (((_f = (_e = options.authenticatorSelection) === null || _e === void 0 ? void 0 : _e.userVerification) === null || _f === void 0 ? void 0 : _f.toLowerCase()) ||
|
|
570
|
-
"
|
|
570
|
+
"discouraged") }) }),
|
|
571
571
|
})];
|
|
572
572
|
case 1:
|
|
573
573
|
credential = _k.sent();
|
|
@@ -1848,6 +1848,81 @@ var useOTPHandler = function (_a) {
|
|
|
1848
1848
|
remainingAttempts: MAX_ATTEMPTS - attemptCount,
|
|
1849
1849
|
};
|
|
1850
1850
|
};
|
|
1851
|
+
var CredentialsHandler = function (credentials, appCode, CredAuthEndpoint, onAuthComplete) {
|
|
1852
|
+
var _a = useState(false), loading = _a[0], setLoading = _a[1];
|
|
1853
|
+
var _b = useState(0), attemptCount = _b[0], setAttemptCount = _b[1];
|
|
1854
|
+
var _c = useState(false), isMaxAttemptsReached = _c[0], setIsMaxAttemptsReached = _c[1];
|
|
1855
|
+
var handleSubmitCredentials = useMemo(function () {
|
|
1856
|
+
return function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
|
|
1857
|
+
var currentAttempt, response, error_2, currentAttempt;
|
|
1858
|
+
var username = _b.username, password = _b.password, MFACode = _b.MFACode, appCode = _b.appCode;
|
|
1859
|
+
return __generator(this, function (_c) {
|
|
1860
|
+
switch (_c.label) {
|
|
1861
|
+
case 0:
|
|
1862
|
+
_c.trys.push([0, 2, 3, 4]);
|
|
1863
|
+
setLoading(true);
|
|
1864
|
+
currentAttempt = attemptCount + 1;
|
|
1865
|
+
setAttemptCount(currentAttempt);
|
|
1866
|
+
return [4 /*yield*/, axios.post(CredAuthEndpoint, {
|
|
1867
|
+
username: username,
|
|
1868
|
+
password: password,
|
|
1869
|
+
MFACode: MFACode,
|
|
1870
|
+
appCode: appCode,
|
|
1871
|
+
}, {
|
|
1872
|
+
headers: {
|
|
1873
|
+
"X-Device-ID": GenerateDeviceId(),
|
|
1874
|
+
},
|
|
1875
|
+
timeout: 605000,
|
|
1876
|
+
})];
|
|
1877
|
+
case 1:
|
|
1878
|
+
response = (_c.sent()).data;
|
|
1879
|
+
if (response) {
|
|
1880
|
+
onAuthComplete(true, response);
|
|
1881
|
+
return [2 /*return*/, true];
|
|
1882
|
+
}
|
|
1883
|
+
else {
|
|
1884
|
+
if (currentAttempt >= MAX_ATTEMPTS) {
|
|
1885
|
+
setIsMaxAttemptsReached(true);
|
|
1886
|
+
onAuthComplete(false, {
|
|
1887
|
+
message: "Maximum attempts reached",
|
|
1888
|
+
});
|
|
1889
|
+
}
|
|
1890
|
+
else {
|
|
1891
|
+
onAuthComplete(false, response.response.data);
|
|
1892
|
+
}
|
|
1893
|
+
return [2 /*return*/, false];
|
|
1894
|
+
}
|
|
1895
|
+
case 2:
|
|
1896
|
+
error_2 = _c.sent();
|
|
1897
|
+
console.error(error_2);
|
|
1898
|
+
currentAttempt = attemptCount + 1;
|
|
1899
|
+
if (currentAttempt >= MAX_ATTEMPTS) {
|
|
1900
|
+
setIsMaxAttemptsReached(true);
|
|
1901
|
+
onAuthComplete(false, error_2.response.data);
|
|
1902
|
+
}
|
|
1903
|
+
else {
|
|
1904
|
+
onAuthComplete(false, error_2.response.data);
|
|
1905
|
+
}
|
|
1906
|
+
onAuthComplete(false, error_2.response.data);
|
|
1907
|
+
return [2 /*return*/, false];
|
|
1908
|
+
case 3:
|
|
1909
|
+
setLoading(false);
|
|
1910
|
+
return [7 /*endfinally*/];
|
|
1911
|
+
case 4: return [2 /*return*/];
|
|
1912
|
+
}
|
|
1913
|
+
});
|
|
1914
|
+
}); };
|
|
1915
|
+
}, [credentials.username, credentials.password, credentials.MFACode]);
|
|
1916
|
+
return {
|
|
1917
|
+
handleSubmitCredentials: handleSubmitCredentials,
|
|
1918
|
+
loading: loading,
|
|
1919
|
+
setLoading: setLoading,
|
|
1920
|
+
attemptCount: attemptCount,
|
|
1921
|
+
isMaxAttemptsReached: isMaxAttemptsReached,
|
|
1922
|
+
// resetAttempts,
|
|
1923
|
+
remainingAttempts: MAX_ATTEMPTS - attemptCount,
|
|
1924
|
+
};
|
|
1925
|
+
};
|
|
1851
1926
|
|
|
1852
1927
|
var MFAOptions = function (_a) {
|
|
1853
1928
|
var onComplete = _a.onComplete, onAuthFailed = _a.onAuthFailed, MFAEndpoints = _a.MFAEndpoints, usePassKey = _a.usePassKey;
|
|
@@ -2081,17 +2156,27 @@ var ADLoginModal = function (_a) {
|
|
|
2081
2156
|
form.reset();
|
|
2082
2157
|
setMfaCode("");
|
|
2083
2158
|
};
|
|
2084
|
-
return (jsxRuntimeExports.jsx(Dialog, { open: open, onOpenChange: handleClose, children: jsxRuntimeExports.jsxs(DialogContent, { className: "sm:max-w-[
|
|
2159
|
+
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(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) {
|
|
2085
2160
|
var field = _a.field;
|
|
2086
|
-
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, {})] }));
|
|
2161
|
+
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, {})] }));
|
|
2087
2162
|
} }), jsxRuntimeExports.jsx(FormField, { control: form.control, name: "password", render: function (_a) {
|
|
2088
2163
|
var field = _a.field;
|
|
2089
|
-
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, {})] }));
|
|
2164
|
+
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, {})] }));
|
|
2090
2165
|
} }), 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(Loader2, { className: "w-4 h-4 animate-spin" }), jsxRuntimeExports.jsx("span", { children: "Verifying..." })] }))] }))] }) }));
|
|
2091
2166
|
};
|
|
2092
2167
|
|
|
2093
2168
|
var DefaultLoginPage = function (_a) {
|
|
2094
|
-
var usePassKey = _a.usePassKey, MFAEndpoints = _a.MFAEndpoints, PassKeysRegisterProps = _a.PassKeysRegisterProps;
|
|
2169
|
+
var usePassKey = _a.usePassKey, useADLogin = _a.useADLogin, MFAEndpoints = _a.MFAEndpoints, CredentialsAuthEndpoint = _a.CredentialsAuthEndpoint, PassKeysRegisterProps = _a.PassKeysRegisterProps;
|
|
2170
|
+
var cardVariants = {
|
|
2171
|
+
hidden: { opacity: 0, scale: 0.8, y: 50 },
|
|
2172
|
+
visible: {
|
|
2173
|
+
opacity: 1,
|
|
2174
|
+
scale: 1,
|
|
2175
|
+
y: 0,
|
|
2176
|
+
transition: { type: "spring", duration: 0.6 },
|
|
2177
|
+
},
|
|
2178
|
+
exit: { opacity: 0, scale: 0.8, y: -50, transition: { duration: 0.3 } },
|
|
2179
|
+
};
|
|
2095
2180
|
var context = useCAMSContext();
|
|
2096
2181
|
var login = context.login, isLoading = context.isLoading, authMode = context.authMode;
|
|
2097
2182
|
var _b = useState(false), showADModal = _b[0], setShowADModal = _b[1];
|
|
@@ -2105,16 +2190,6 @@ var DefaultLoginPage = function (_a) {
|
|
|
2105
2190
|
console.warn("Regular CAMS login requires configuration");
|
|
2106
2191
|
}
|
|
2107
2192
|
};
|
|
2108
|
-
var cardVariants = {
|
|
2109
|
-
hidden: { opacity: 0, scale: 0.8, y: 50 },
|
|
2110
|
-
visible: {
|
|
2111
|
-
opacity: 1,
|
|
2112
|
-
scale: 1,
|
|
2113
|
-
y: 0,
|
|
2114
|
-
transition: { type: "spring", duration: 0.6 },
|
|
2115
|
-
},
|
|
2116
|
-
exit: { opacity: 0, scale: 0.8, y: -50, transition: { duration: 0.3 } },
|
|
2117
|
-
};
|
|
2118
2193
|
var handleRegister = function (data) { return __awaiter(void 0, void 0, void 0, function () {
|
|
2119
2194
|
var options, attestationResponse, error_1;
|
|
2120
2195
|
return __generator(this, function (_a) {
|
|
@@ -2164,11 +2239,28 @@ var DefaultLoginPage = function (_a) {
|
|
|
2164
2239
|
// variant="outline"
|
|
2165
2240
|
, {
|
|
2166
2241
|
// variant="outline"
|
|
2167
|
-
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" })] }),
|
|
2242
|
+
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(KeyIcon, { className: "w-24 h-24 text-[#506f4a]" }), jsxRuntimeExports.jsx("span", { children: isLoading
|
|
2243
|
+
? "Logging in..."
|
|
2244
|
+
: "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(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(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) {
|
|
2168
2245
|
var username = _b.username, password = _b.password, MFACode = _b.MFACode;
|
|
2169
2246
|
return __generator(this, function (_c) {
|
|
2170
2247
|
// Implement your AD login logic here
|
|
2171
2248
|
console.log("AD Login:", { username: username, password: password, MFACode: MFACode });
|
|
2249
|
+
// Example: await adLoginService(username, password, mfaCode);
|
|
2250
|
+
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 () {
|
|
2251
|
+
return __generator(this, function (_a) {
|
|
2252
|
+
console.log(data);
|
|
2253
|
+
if (state && data) {
|
|
2254
|
+
context.isAuthenticated = true;
|
|
2255
|
+
context.requiresMFA = false;
|
|
2256
|
+
context.setUserProfile({
|
|
2257
|
+
type: "AUTH_SUCCESS",
|
|
2258
|
+
userProfile: __assign({}, data),
|
|
2259
|
+
});
|
|
2260
|
+
}
|
|
2261
|
+
return [2 /*return*/];
|
|
2262
|
+
});
|
|
2263
|
+
}); });
|
|
2172
2264
|
return [2 /*return*/];
|
|
2173
2265
|
});
|
|
2174
2266
|
}); } })] }));
|
|
@@ -2191,7 +2283,7 @@ var MFAGate = function (_a) {
|
|
|
2191
2283
|
// loginComponent: LoginComponent = DefaultLoginPage,
|
|
2192
2284
|
_c = _a.usePassKey,
|
|
2193
2285
|
// loginComponent: LoginComponent = DefaultLoginPage,
|
|
2194
|
-
usePassKey = _c === void 0 ? false : _c, PassKeysRegisterProps = _a.PassKeysRegisterProps, MFAEndpoints = _a.MFAEndpoints;
|
|
2286
|
+
usePassKey = _c === void 0 ? false : _c, _d = _a.useADLogin, useADLogin = _d === void 0 ? false : _d, CredentialsAuthEndpoint = _a.CredentialsAuthEndpoint, PassKeysRegisterProps = _a.PassKeysRegisterProps, MFAEndpoints = _a.MFAEndpoints;
|
|
2195
2287
|
var context = useCAMSContext();
|
|
2196
2288
|
var validatedMFAEndpoints = useMemo(function () {
|
|
2197
2289
|
var parsed = MFAEndpointsSchema.safeParse(MFAEndpoints);
|
|
@@ -2226,7 +2318,7 @@ var MFAGate = function (_a) {
|
|
|
2226
2318
|
return (jsxRuntimeExports.jsx(MFAOptions, { MFAEndpoints: validatedMFAEndpoints, usePassKey: usePassKey, onComplete: handleComplete, onAuthFailed: handleAuthFailed }));
|
|
2227
2319
|
}
|
|
2228
2320
|
if (!context.isAuthenticated) {
|
|
2229
|
-
return (jsxRuntimeExports.jsx(DefaultLoginPage, { usePassKey: usePassKey, MFAEndpoints: MFAEndpoints, PassKeysRegisterProps: PassKeysRegisterProps }));
|
|
2321
|
+
return (jsxRuntimeExports.jsx(DefaultLoginPage, { usePassKey: usePassKey, useADLogin: useADLogin, MFAEndpoints: MFAEndpoints, PassKeysRegisterProps: PassKeysRegisterProps, CredentialsAuthEndpoint: CredentialsAuthEndpoint }));
|
|
2230
2322
|
}
|
|
2231
2323
|
return jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: children });
|
|
2232
2324
|
};
|