@nibssplc/cams-sdk-react 0.0.1-beta.104 → 0.0.1-beta.106
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/index.esm.js
CHANGED
|
@@ -1719,7 +1719,7 @@ var GenerateDeviceId = function () {
|
|
|
1719
1719
|
var userAgent = window.navigator.userAgent;
|
|
1720
1720
|
var deviceId = "";
|
|
1721
1721
|
// Parse browser, version, OS, and device type
|
|
1722
|
-
var browserMatch = Array.from(userAgent.matchAll(/(Chrome|Firefox|Safari|Edge|Opera)\/([\d.]+)/
|
|
1722
|
+
var browserMatch = Array.from(userAgent.matchAll(/(Chrome|Firefox|Safari|Edge|Opera)\/([\d.]+)/gi));
|
|
1723
1723
|
var osMatch = Array.from(userAgent.matchAll(/\(([^)]+)\)/g));
|
|
1724
1724
|
var isMobile = /Mobile|Android|iPhone|iPad/i.test(userAgent);
|
|
1725
1725
|
// Browser info
|
|
@@ -1749,6 +1749,10 @@ var GenerateDeviceId = function () {
|
|
|
1749
1749
|
deviceId += "_".concat(hash);
|
|
1750
1750
|
return (_a = deviceId.replace(/[^a-zA-Z0-9-_]/g, "_")) !== null && _a !== void 0 ? _a : "unknown-device";
|
|
1751
1751
|
};
|
|
1752
|
+
var APIHeaders = {
|
|
1753
|
+
"X-DEVICE-ID": GenerateDeviceId(),
|
|
1754
|
+
"X-API-VERSION": "1.0",
|
|
1755
|
+
};
|
|
1752
1756
|
|
|
1753
1757
|
var MAX_ATTEMPTS = 3;
|
|
1754
1758
|
var useOTPHandler = function (_a) {
|
|
@@ -1783,9 +1787,7 @@ var useOTPHandler = function (_a) {
|
|
|
1783
1787
|
MFACode: authenticationValue,
|
|
1784
1788
|
appCode: appCode,
|
|
1785
1789
|
}, {
|
|
1786
|
-
headers:
|
|
1787
|
-
"X-Device-ID": GenerateDeviceId(),
|
|
1788
|
-
},
|
|
1790
|
+
headers: APIHeaders,
|
|
1789
1791
|
timeout: 605000,
|
|
1790
1792
|
})];
|
|
1791
1793
|
case 2:
|
|
@@ -1848,34 +1850,31 @@ var useOTPHandler = function (_a) {
|
|
|
1848
1850
|
remainingAttempts: MAX_ATTEMPTS - attemptCount,
|
|
1849
1851
|
};
|
|
1850
1852
|
};
|
|
1851
|
-
var
|
|
1853
|
+
var useCredentialsHandler = function (onAuthComplete) {
|
|
1852
1854
|
var _a = useState(false), loading = _a[0], setLoading = _a[1];
|
|
1853
1855
|
var _b = useState(0), attemptCount = _b[0], setAttemptCount = _b[1];
|
|
1854
1856
|
var _c = useState(false), isMaxAttemptsReached = _c[0], setIsMaxAttemptsReached = _c[1];
|
|
1855
1857
|
var handleSubmitCredentials = useMemo(function () {
|
|
1856
|
-
return function (
|
|
1858
|
+
return function (CredAuthEndpoint, credentials, appCode) { return __awaiter(void 0, void 0, void 0, function () {
|
|
1857
1859
|
var currentAttempt, response, error_2, currentAttempt;
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
switch (_c.label) {
|
|
1860
|
+
return __generator(this, function (_a) {
|
|
1861
|
+
switch (_a.label) {
|
|
1861
1862
|
case 0:
|
|
1862
|
-
|
|
1863
|
+
_a.trys.push([0, 2, 3, 4]);
|
|
1863
1864
|
setLoading(true);
|
|
1864
1865
|
currentAttempt = attemptCount + 1;
|
|
1865
1866
|
setAttemptCount(currentAttempt);
|
|
1866
1867
|
return [4 /*yield*/, axios.post(CredAuthEndpoint, {
|
|
1867
|
-
username: username,
|
|
1868
|
-
password: password,
|
|
1869
|
-
MFACode: MFACode,
|
|
1868
|
+
username: credentials.username,
|
|
1869
|
+
password: credentials.password,
|
|
1870
|
+
MFACode: credentials.MFACode,
|
|
1870
1871
|
appCode: appCode,
|
|
1871
1872
|
}, {
|
|
1872
|
-
headers:
|
|
1873
|
-
"X-Device-ID": GenerateDeviceId(),
|
|
1874
|
-
},
|
|
1873
|
+
headers: APIHeaders,
|
|
1875
1874
|
timeout: 605000,
|
|
1876
1875
|
})];
|
|
1877
1876
|
case 1:
|
|
1878
|
-
response = (
|
|
1877
|
+
response = (_a.sent()).data;
|
|
1879
1878
|
if (response) {
|
|
1880
1879
|
onAuthComplete(true, response);
|
|
1881
1880
|
return [2 /*return*/, true];
|
|
@@ -1893,7 +1892,7 @@ var CredentialsHandler = function (credentials, appCode, CredAuthEndpoint, onAut
|
|
|
1893
1892
|
return [2 /*return*/, false];
|
|
1894
1893
|
}
|
|
1895
1894
|
case 2:
|
|
1896
|
-
error_2 =
|
|
1895
|
+
error_2 = _a.sent();
|
|
1897
1896
|
console.error(error_2);
|
|
1898
1897
|
currentAttempt = attemptCount + 1;
|
|
1899
1898
|
if (currentAttempt >= MAX_ATTEMPTS) {
|
|
@@ -1912,7 +1911,7 @@ var CredentialsHandler = function (credentials, appCode, CredAuthEndpoint, onAut
|
|
|
1912
1911
|
}
|
|
1913
1912
|
});
|
|
1914
1913
|
}); };
|
|
1915
|
-
}, [
|
|
1914
|
+
}, []);
|
|
1916
1915
|
return {
|
|
1917
1916
|
handleSubmitCredentials: handleSubmitCredentials,
|
|
1918
1917
|
loading: loading,
|
|
@@ -1941,46 +1940,36 @@ var MFAOptions = function (_a) {
|
|
|
1941
1940
|
var authenticate = useWebAuthn().authenticate;
|
|
1942
1941
|
var handleFIDOLogin = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
1943
1942
|
var options, assertionResponse, error_1;
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
switch (_g.label) {
|
|
1943
|
+
return __generator(this, function (_a) {
|
|
1944
|
+
switch (_a.label) {
|
|
1947
1945
|
case 0:
|
|
1948
|
-
|
|
1946
|
+
_a.trys.push([0, 4, , 5]);
|
|
1949
1947
|
// 1. Fetch authentication challenge from your server
|
|
1950
1948
|
console.log("Requesting authentication challenge from server...");
|
|
1951
1949
|
return [4 /*yield*/, axios.post(MFAEndpoints.RetrieveAuthChallenge, {}, {
|
|
1952
|
-
headers:
|
|
1953
|
-
"X-DEVICE-ID": GenerateDeviceId(),
|
|
1954
|
-
"X-API-VERSION": "1.0",
|
|
1955
|
-
},
|
|
1950
|
+
headers: APIHeaders,
|
|
1956
1951
|
})];
|
|
1957
1952
|
case 1:
|
|
1958
|
-
options = (
|
|
1953
|
+
options = (_a.sent()).data;
|
|
1959
1954
|
console.log("Received challenge:", options);
|
|
1960
1955
|
// 2. Call the SDK to trigger the browser's passkey authentication UI
|
|
1961
1956
|
console.log("Calling SDK authenticate function...");
|
|
1962
|
-
return [4 /*yield*/, authenticate(__assign(__assign({}, options), {
|
|
1963
|
-
type: "public-key",
|
|
1964
|
-
alg: param.alg
|
|
1965
|
-
}); }), 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()) || "discouraged", userVerification: ((_f = (_e = options.authenticatorSelection) === null || _e === void 0 ? void 0 : _e.userVerification) === null || _f === void 0 ? void 0 : _f.toLowerCase()) || "preferred" }) }))];
|
|
1957
|
+
return [4 /*yield*/, authenticate(__assign(__assign({}, options), { userVerification: "discouraged" }))];
|
|
1966
1958
|
case 2:
|
|
1967
|
-
assertionResponse =
|
|
1959
|
+
assertionResponse = _a.sent();
|
|
1968
1960
|
console.log("Authentication assertion received from client:", assertionResponse);
|
|
1969
1961
|
// 3. Send the assertion back to the server for verification
|
|
1970
1962
|
console.log("Sending assertion to server for verification...");
|
|
1971
1963
|
return [4 /*yield*/, axios.post(MFAEndpoints.AuthChallengeVerify, assertionResponse, {
|
|
1972
|
-
headers:
|
|
1973
|
-
"X-DEVICE-ID": GenerateDeviceId(),
|
|
1974
|
-
"X-API-VERSION": "1.0",
|
|
1975
|
-
},
|
|
1964
|
+
headers: APIHeaders,
|
|
1976
1965
|
withCredentials: true, // credentials: 'include'
|
|
1977
1966
|
})];
|
|
1978
1967
|
case 3:
|
|
1979
|
-
|
|
1968
|
+
_a.sent();
|
|
1980
1969
|
toast.success("🔑 Sign-in successful!");
|
|
1981
1970
|
return [3 /*break*/, 5];
|
|
1982
1971
|
case 4:
|
|
1983
|
-
error_1 =
|
|
1972
|
+
error_1 = _a.sent();
|
|
1984
1973
|
console.error("Authentication failed:", error_1);
|
|
1985
1974
|
toast.error("❌ Could not sign in.");
|
|
1986
1975
|
return [3 /*break*/, 5];
|
|
@@ -2099,14 +2088,13 @@ var credentialsSchema = z.object({
|
|
|
2099
2088
|
password: z.string().min(1, "Password is required"),
|
|
2100
2089
|
});
|
|
2101
2090
|
var ADLoginModal = function (_a) {
|
|
2102
|
-
var open = _a.open, onOpenChange = _a.onOpenChange, onLogin = _a.onLogin;
|
|
2091
|
+
var open = _a.open, isLoading = _a.isLoading, setIsLoading = _a.setIsLoading, onOpenChange = _a.onOpenChange, onLogin = _a.onLogin;
|
|
2103
2092
|
var _b = useState("credentials"), step = _b[0], setStep = _b[1];
|
|
2104
2093
|
var _c = useState({
|
|
2105
2094
|
username: "",
|
|
2106
2095
|
password: "",
|
|
2107
2096
|
}), credentials = _c[0], setCredentials = _c[1];
|
|
2108
2097
|
var _d = useState(""), mfaCode = _d[0], setMfaCode = _d[1];
|
|
2109
|
-
var _e = useState(false), isLoading = _e[0], setIsLoading = _e[1];
|
|
2110
2098
|
var form = useForm({
|
|
2111
2099
|
resolver: a$1(credentialsSchema),
|
|
2112
2100
|
defaultValues: { username: "", password: "" },
|
|
@@ -2156,7 +2144,7 @@ var ADLoginModal = function (_a) {
|
|
|
2156
2144
|
form.reset();
|
|
2157
2145
|
setMfaCode("");
|
|
2158
2146
|
};
|
|
2159
|
-
return (jsxRuntimeExports.jsx(Dialog, { open: open, onOpenChange: handleClose, children: jsxRuntimeExports.jsxs(DialogContent, { className: "
|
|
2147
|
+
return (jsxRuntimeExports.jsx(Dialog, { open: open, onOpenChange: handleClose, children: jsxRuntimeExports.jsxs(DialogContent, { className: "w-[70vw] min-w-[250px] max-w-[350px]", 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) {
|
|
2160
2148
|
var field = _a.field;
|
|
2161
2149
|
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, {})] }));
|
|
2162
2150
|
} }), jsxRuntimeExports.jsx(FormField, { control: form.control, name: "password", render: function (_a) {
|
|
@@ -2181,6 +2169,20 @@ var DefaultLoginPage = function (_a) {
|
|
|
2181
2169
|
var login = context.login, isLoading = context.isLoading, authMode = context.authMode;
|
|
2182
2170
|
var _b = useState(false), showADModal = _b[0], setShowADModal = _b[1];
|
|
2183
2171
|
var register = useWebAuthn().register;
|
|
2172
|
+
var _c = useCredentialsHandler(function (state, data) { return __awaiter(void 0, void 0, void 0, function () {
|
|
2173
|
+
return __generator(this, function (_a) {
|
|
2174
|
+
console.log(data);
|
|
2175
|
+
if (state && data) {
|
|
2176
|
+
context.isAuthenticated = true;
|
|
2177
|
+
context.requiresMFA = false;
|
|
2178
|
+
context.setUserProfile({
|
|
2179
|
+
type: "AUTH_SUCCESS",
|
|
2180
|
+
userProfile: __assign({}, data),
|
|
2181
|
+
});
|
|
2182
|
+
}
|
|
2183
|
+
return [2 /*return*/];
|
|
2184
|
+
});
|
|
2185
|
+
}); }), handleSubmitCredentials = _c.handleSubmitCredentials, isCredAuthLoading = _c.loading, setIsCredAuthLoading = _c.setLoading;
|
|
2184
2186
|
var handleMSALLogin = function () {
|
|
2185
2187
|
if (authMode === "MSAL") {
|
|
2186
2188
|
login();
|
|
@@ -2199,10 +2201,7 @@ var DefaultLoginPage = function (_a) {
|
|
|
2199
2201
|
// 1. Fetch challenge from your server
|
|
2200
2202
|
console.log("Requesting registration challenge from server...");
|
|
2201
2203
|
return [4 /*yield*/, axios.post(MFAEndpoints.RegisterNewChallenge, __assign({}, data), {
|
|
2202
|
-
headers:
|
|
2203
|
-
"X-DEVICE-ID": GenerateDeviceId(),
|
|
2204
|
-
"X-API-VERSION": "1.0",
|
|
2205
|
-
},
|
|
2204
|
+
headers: APIHeaders,
|
|
2206
2205
|
})];
|
|
2207
2206
|
case 1:
|
|
2208
2207
|
options = (_a.sent()).data;
|
|
@@ -2216,10 +2215,7 @@ var DefaultLoginPage = function (_a) {
|
|
|
2216
2215
|
// 3. Send the response back to the server for verification
|
|
2217
2216
|
console.log("Sending attestation to server for verification...");
|
|
2218
2217
|
return [4 /*yield*/, axios.post(MFAEndpoints.RegisterVerify, attestationResponse, {
|
|
2219
|
-
headers:
|
|
2220
|
-
"X-DEVICE-ID": GenerateDeviceId(),
|
|
2221
|
-
"X-API-VERSION": "1.0",
|
|
2222
|
-
},
|
|
2218
|
+
headers: APIHeaders,
|
|
2223
2219
|
withCredentials: true, // credentials: 'include'
|
|
2224
2220
|
})];
|
|
2225
2221
|
case 3:
|
|
@@ -2239,28 +2235,15 @@ var DefaultLoginPage = function (_a) {
|
|
|
2239
2235
|
// variant="outline"
|
|
2240
2236
|
, {
|
|
2241
2237
|
// variant="outline"
|
|
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: "
|
|
2238
|
+
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: "text-[#506f4a]", size: 64 }), jsxRuntimeExports.jsx("span", { children: isLoading
|
|
2243
2239
|
? "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: "
|
|
2240
|
+
: "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: "text-[#506f4a]", size: 64 }), 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, isLoading: isCredAuthLoading, setIsLoading: setIsCredAuthLoading, onLogin: function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
|
|
2245
2241
|
var username = _b.username, password = _b.password, MFACode = _b.MFACode;
|
|
2246
2242
|
return __generator(this, function (_c) {
|
|
2247
2243
|
// Implement your AD login logic here
|
|
2248
2244
|
console.log("AD Login:", { username: username, password: password, MFACode: MFACode });
|
|
2249
2245
|
// Example: await adLoginService(username, password, mfaCode);
|
|
2250
|
-
|
|
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
|
-
}); });
|
|
2246
|
+
handleSubmitCredentials(CredentialsAuthEndpoint !== null && CredentialsAuthEndpoint !== void 0 ? CredentialsAuthEndpoint : "/api/auth/validate", { username: username, password: password, MFACode: MFACode }, context.appCode);
|
|
2264
2247
|
return [2 /*return*/];
|
|
2265
2248
|
});
|
|
2266
2249
|
}); } })] }));
|
|
@@ -2308,8 +2291,10 @@ var MFAGate = function (_a) {
|
|
|
2308
2291
|
});
|
|
2309
2292
|
}); }, [context.logout]);
|
|
2310
2293
|
Logger.debug("MFA Endpoint >>>", { MFAEndpoints: MFAEndpoints });
|
|
2294
|
+
if (useADLogin && !CredentialsAuthEndpoint)
|
|
2295
|
+
return jsxRuntimeExports.jsx(ErrorFallback, { message: "Invalid AD Login Configuration." });
|
|
2311
2296
|
if (!validatedMFAEndpoints)
|
|
2312
|
-
return jsxRuntimeExports.jsx(ErrorFallback, { message: "Invalid MFA
|
|
2297
|
+
return jsxRuntimeExports.jsx(ErrorFallback, { message: "Invalid MFA Configuration." });
|
|
2313
2298
|
if (context.authMode !== "MSAL")
|
|
2314
2299
|
return jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: children });
|
|
2315
2300
|
if (context.isLoading)
|