@nibssplc/cams-sdk-react 0.0.1-beta.105 → 0.0.1-beta.107
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,
|
|
@@ -1948,10 +1947,7 @@ var MFAOptions = function (_a) {
|
|
|
1948
1947
|
// 1. Fetch authentication challenge from your server
|
|
1949
1948
|
console.log("Requesting authentication challenge from server...");
|
|
1950
1949
|
return [4 /*yield*/, axios.post(MFAEndpoints.RetrieveAuthChallenge, {}, {
|
|
1951
|
-
headers:
|
|
1952
|
-
"X-DEVICE-ID": GenerateDeviceId(),
|
|
1953
|
-
"X-API-VERSION": "1.0",
|
|
1954
|
-
},
|
|
1950
|
+
headers: APIHeaders,
|
|
1955
1951
|
})];
|
|
1956
1952
|
case 1:
|
|
1957
1953
|
options = (_a.sent()).data;
|
|
@@ -1965,10 +1961,7 @@ var MFAOptions = function (_a) {
|
|
|
1965
1961
|
// 3. Send the assertion back to the server for verification
|
|
1966
1962
|
console.log("Sending assertion to server for verification...");
|
|
1967
1963
|
return [4 /*yield*/, axios.post(MFAEndpoints.AuthChallengeVerify, assertionResponse, {
|
|
1968
|
-
headers:
|
|
1969
|
-
"X-DEVICE-ID": GenerateDeviceId(),
|
|
1970
|
-
"X-API-VERSION": "1.0",
|
|
1971
|
-
},
|
|
1964
|
+
headers: APIHeaders,
|
|
1972
1965
|
withCredentials: true, // credentials: 'include'
|
|
1973
1966
|
})];
|
|
1974
1967
|
case 3:
|
|
@@ -2095,14 +2088,13 @@ var credentialsSchema = z.object({
|
|
|
2095
2088
|
password: z.string().min(1, "Password is required"),
|
|
2096
2089
|
});
|
|
2097
2090
|
var ADLoginModal = function (_a) {
|
|
2098
|
-
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;
|
|
2099
2092
|
var _b = useState("credentials"), step = _b[0], setStep = _b[1];
|
|
2100
2093
|
var _c = useState({
|
|
2101
2094
|
username: "",
|
|
2102
2095
|
password: "",
|
|
2103
2096
|
}), credentials = _c[0], setCredentials = _c[1];
|
|
2104
2097
|
var _d = useState(""), mfaCode = _d[0], setMfaCode = _d[1];
|
|
2105
|
-
var _e = useState(false), isLoading = _e[0], setIsLoading = _e[1];
|
|
2106
2098
|
var form = useForm({
|
|
2107
2099
|
resolver: a$1(credentialsSchema),
|
|
2108
2100
|
defaultValues: { username: "", password: "" },
|
|
@@ -2152,7 +2144,7 @@ var ADLoginModal = function (_a) {
|
|
|
2152
2144
|
form.reset();
|
|
2153
2145
|
setMfaCode("");
|
|
2154
2146
|
};
|
|
2155
|
-
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) {
|
|
2156
2148
|
var field = _a.field;
|
|
2157
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, {})] }));
|
|
2158
2150
|
} }), jsxRuntimeExports.jsx(FormField, { control: form.control, name: "password", render: function (_a) {
|
|
@@ -2177,6 +2169,20 @@ var DefaultLoginPage = function (_a) {
|
|
|
2177
2169
|
var login = context.login, isLoading = context.isLoading, authMode = context.authMode;
|
|
2178
2170
|
var _b = useState(false), showADModal = _b[0], setShowADModal = _b[1];
|
|
2179
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;
|
|
2180
2186
|
var handleMSALLogin = function () {
|
|
2181
2187
|
if (authMode === "MSAL") {
|
|
2182
2188
|
login();
|
|
@@ -2195,10 +2201,7 @@ var DefaultLoginPage = function (_a) {
|
|
|
2195
2201
|
// 1. Fetch challenge from your server
|
|
2196
2202
|
console.log("Requesting registration challenge from server...");
|
|
2197
2203
|
return [4 /*yield*/, axios.post(MFAEndpoints.RegisterNewChallenge, __assign({}, data), {
|
|
2198
|
-
headers:
|
|
2199
|
-
"X-DEVICE-ID": GenerateDeviceId(),
|
|
2200
|
-
"X-API-VERSION": "1.0",
|
|
2201
|
-
},
|
|
2204
|
+
headers: APIHeaders,
|
|
2202
2205
|
})];
|
|
2203
2206
|
case 1:
|
|
2204
2207
|
options = (_a.sent()).data;
|
|
@@ -2212,10 +2215,7 @@ var DefaultLoginPage = function (_a) {
|
|
|
2212
2215
|
// 3. Send the response back to the server for verification
|
|
2213
2216
|
console.log("Sending attestation to server for verification...");
|
|
2214
2217
|
return [4 /*yield*/, axios.post(MFAEndpoints.RegisterVerify, attestationResponse, {
|
|
2215
|
-
headers:
|
|
2216
|
-
"X-DEVICE-ID": GenerateDeviceId(),
|
|
2217
|
-
"X-API-VERSION": "1.0",
|
|
2218
|
-
},
|
|
2218
|
+
headers: APIHeaders,
|
|
2219
2219
|
withCredentials: true, // credentials: 'include'
|
|
2220
2220
|
})];
|
|
2221
2221
|
case 3:
|
|
@@ -2235,28 +2235,15 @@ var DefaultLoginPage = function (_a) {
|
|
|
2235
2235
|
// variant="outline"
|
|
2236
2236
|
, {
|
|
2237
2237
|
// variant="outline"
|
|
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: "
|
|
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
|
|
2239
2239
|
? "Logging in..."
|
|
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: "
|
|
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) {
|
|
2241
2241
|
var username = _b.username, password = _b.password, MFACode = _b.MFACode;
|
|
2242
2242
|
return __generator(this, function (_c) {
|
|
2243
2243
|
// Implement your AD login logic here
|
|
2244
2244
|
console.log("AD Login:", { username: username, password: password, MFACode: MFACode });
|
|
2245
2245
|
// Example: await adLoginService(username, password, mfaCode);
|
|
2246
|
-
|
|
2247
|
-
return __generator(this, function (_a) {
|
|
2248
|
-
console.log(data);
|
|
2249
|
-
if (state && data) {
|
|
2250
|
-
context.isAuthenticated = true;
|
|
2251
|
-
context.requiresMFA = false;
|
|
2252
|
-
context.setUserProfile({
|
|
2253
|
-
type: "AUTH_SUCCESS",
|
|
2254
|
-
userProfile: __assign({}, data),
|
|
2255
|
-
});
|
|
2256
|
-
}
|
|
2257
|
-
return [2 /*return*/];
|
|
2258
|
-
});
|
|
2259
|
-
}); });
|
|
2246
|
+
handleSubmitCredentials(CredentialsAuthEndpoint !== null && CredentialsAuthEndpoint !== void 0 ? CredentialsAuthEndpoint : "/api/auth/validate", { username: username, password: password, MFACode: MFACode }, context.appCode);
|
|
2260
2247
|
return [2 /*return*/];
|
|
2261
2248
|
});
|
|
2262
2249
|
}); } })] }));
|