@nibssplc/cams-sdk-react 0.0.1-beta.63 → 0.0.1-beta.64
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/hooks/useOTPHandler.d.ts +2 -2
- package/dist/index.cjs.js +50 -5
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +50 -5
- package/dist/index.esm.js.map +1 -1
- package/dist/utils/DeviceID.d.ts +1 -0
- package/package.json +1 -1
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
export declare const useOTPHandler: ({ provider, accessToken, idToken, appCode, authenticationType,
|
|
1
|
+
export declare const useOTPHandler: ({ provider, accessToken, idToken, appCode, authenticationType, MFAEndpoint, onAuthComplete, }: {
|
|
2
2
|
provider: string;
|
|
3
3
|
accessToken: string;
|
|
4
4
|
idToken: string;
|
|
5
5
|
appCode: string;
|
|
6
6
|
authenticationType: "AuthenticatorCode" | "EmailOTP" | null;
|
|
7
|
-
|
|
7
|
+
MFAEndpoint?: string;
|
|
8
8
|
onAuthComplete: (state: boolean, data: UserValidatedResponse | null) => void;
|
|
9
9
|
}) => {
|
|
10
10
|
handleSubmitOTP: (authenticationValue: string) => Promise<boolean>;
|
package/dist/index.cjs.js
CHANGED
|
@@ -1592,8 +1592,48 @@ var AuthSuccessAnimation = function (_a) {
|
|
|
1592
1592
|
return (jsxRuntimeExports.jsxs(framerMotion.motion.div, { initial: { opacity: 0, scale: 0.8 }, animate: { opacity: 1, scale: 1 }, transition: { duration: 0.5, ease: "easeOut" }, className: "flex flex-col items-center justify-center space-y-6 p-8", onAnimationComplete: onComplete, children: [jsxRuntimeExports.jsx(framerMotion.motion.div, { initial: { scale: 0 }, animate: { scale: 1 }, transition: { delay: 0.2, duration: 0.6, type: "spring", stiffness: 200 }, children: jsxRuntimeExports.jsx(lucideReact.CheckCircle, { className: "w-20 h-20 text-green-500" }) }), jsxRuntimeExports.jsxs(framerMotion.motion.div, { initial: { y: 20, opacity: 0 }, animate: { y: 0, opacity: 1 }, transition: { delay: 0.4, duration: 0.5 }, className: "text-center space-y-2", children: [jsxRuntimeExports.jsx("h2", { className: "text-2xl font-bold text-green-600", children: "Authentication Successful!" }), jsxRuntimeExports.jsx("p", { className: "text-gray-600", children: "Redirecting you to the application..." })] }), jsxRuntimeExports.jsx(framerMotion.motion.div, { initial: { width: 0 }, animate: { width: "100%" }, transition: { delay: 0.8, duration: 2 }, className: "h-1 bg-green-500 rounded-full max-w-xs" })] }));
|
|
1593
1593
|
};
|
|
1594
1594
|
|
|
1595
|
+
// Function to parse userAgent and generate a device ID
|
|
1596
|
+
var GenerateDeviceId = function () {
|
|
1597
|
+
var _a;
|
|
1598
|
+
if (typeof window === "undefined" || !window.navigator) {
|
|
1599
|
+
return "unknown-device";
|
|
1600
|
+
}
|
|
1601
|
+
var userAgent = window.navigator.userAgent;
|
|
1602
|
+
var deviceId = "";
|
|
1603
|
+
// Parse browser, version, OS, and device type
|
|
1604
|
+
var browserMatch = Array.from(userAgent.matchAll(/(Chrome|Firefox|Safari|Edge|Opera)\/([\d.]+)/ig));
|
|
1605
|
+
var osMatch = Array.from(userAgent.matchAll(/\(([^)]+)\)/g));
|
|
1606
|
+
var isMobile = /Mobile|Android|iPhone|iPad/i.test(userAgent);
|
|
1607
|
+
// Browser info
|
|
1608
|
+
if (browserMatch.length > 0) {
|
|
1609
|
+
var _b = browserMatch[0], browserName = _b[1], browserVersion = _b[2];
|
|
1610
|
+
var majorVersion = browserVersion.split(".")[0];
|
|
1611
|
+
deviceId += "".concat(browserName, "-").concat(majorVersion);
|
|
1612
|
+
}
|
|
1613
|
+
else {
|
|
1614
|
+
deviceId += "UnknownBrowser";
|
|
1615
|
+
}
|
|
1616
|
+
// OS info
|
|
1617
|
+
if (osMatch.length > 0) {
|
|
1618
|
+
var osInfo = osMatch[0][1]
|
|
1619
|
+
.split(";")[0]
|
|
1620
|
+
.trim()
|
|
1621
|
+
.replace(/[\s/()]/g, "_");
|
|
1622
|
+
deviceId += "_".concat(osInfo);
|
|
1623
|
+
}
|
|
1624
|
+
else {
|
|
1625
|
+
deviceId += "_UnknownOS";
|
|
1626
|
+
}
|
|
1627
|
+
// Device type
|
|
1628
|
+
deviceId += isMobile ? "_Mobile" : "_Desktop";
|
|
1629
|
+
// Add a simple hash of userAgent for uniqueness
|
|
1630
|
+
var hash = btoa(userAgent).slice(0, 8);
|
|
1631
|
+
deviceId += "_".concat(hash);
|
|
1632
|
+
return (_a = deviceId.replace(/[^a-zA-Z0-9-_]/g, "_")) !== null && _a !== void 0 ? _a : "unknown-device";
|
|
1633
|
+
};
|
|
1634
|
+
|
|
1595
1635
|
var useOTPHandler = function (_a) {
|
|
1596
|
-
var provider = _a.provider, accessToken = _a.accessToken, idToken = _a.idToken, appCode = _a.appCode, authenticationType = _a.authenticationType,
|
|
1636
|
+
var provider = _a.provider, accessToken = _a.accessToken, idToken = _a.idToken, appCode = _a.appCode, authenticationType = _a.authenticationType, MFAEndpoint = _a.MFAEndpoint, onAuthComplete = _a.onAuthComplete;
|
|
1597
1637
|
var _b = React.useState(false), loading = _b[0], setLoading = _b[1];
|
|
1598
1638
|
var _c = React.useState(0), attemptCount = _c[0], setAttemptCount = _c[1];
|
|
1599
1639
|
var _d = React.useState(false), isMaxAttemptsReached = _d[0], setIsMaxAttemptsReached = _d[1];
|
|
@@ -1617,13 +1657,18 @@ var useOTPHandler = function (_a) {
|
|
|
1617
1657
|
setAttemptCount(currentAttempt);
|
|
1618
1658
|
if (authenticationType === null)
|
|
1619
1659
|
return [2 /*return*/, false];
|
|
1620
|
-
return [4 /*yield*/, axios.post(
|
|
1660
|
+
return [4 /*yield*/, axios.post(MFAEndpoint || "/api/auth/verify-mfa", {
|
|
1621
1661
|
provider: provider,
|
|
1622
1662
|
accessToken: accessToken,
|
|
1623
1663
|
idToken: idToken,
|
|
1624
1664
|
authenticationType: authenticationType,
|
|
1625
1665
|
MFACode: authenticationValue,
|
|
1626
1666
|
appCode: appCode,
|
|
1667
|
+
}, {
|
|
1668
|
+
headers: {
|
|
1669
|
+
"X-Device-ID": GenerateDeviceId(),
|
|
1670
|
+
},
|
|
1671
|
+
timeout: 605000,
|
|
1627
1672
|
})];
|
|
1628
1673
|
case 2:
|
|
1629
1674
|
response = (_a.sent()).data;
|
|
@@ -1667,7 +1712,7 @@ var useOTPHandler = function (_a) {
|
|
|
1667
1712
|
idToken,
|
|
1668
1713
|
authenticationType,
|
|
1669
1714
|
onAuthComplete,
|
|
1670
|
-
|
|
1715
|
+
MFAEndpoint,
|
|
1671
1716
|
attemptCount,
|
|
1672
1717
|
isMaxAttemptsReached,
|
|
1673
1718
|
]);
|
|
@@ -1704,7 +1749,7 @@ var MFAOptions = function (_a) {
|
|
|
1704
1749
|
provider: "MSAL",
|
|
1705
1750
|
appCode: context.appCode || "",
|
|
1706
1751
|
authenticationType: authType,
|
|
1707
|
-
|
|
1752
|
+
MFAEndpoint: MFAEndpoint,
|
|
1708
1753
|
onAuthComplete: function (state, data) {
|
|
1709
1754
|
if (state) {
|
|
1710
1755
|
setShowSuccessAnimation(true);
|
|
@@ -1770,7 +1815,7 @@ var MFAOptions = function (_a) {
|
|
|
1770
1815
|
else if (authType === "AuthenticatorCode") {
|
|
1771
1816
|
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 })] })) })] }));
|
|
1772
1817
|
}
|
|
1773
|
-
return (jsxRuntimeExports.jsx("div", { className: "flex justify-center items-center h-dvh", 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("div", { className: "flex justify-center items", children: jsxRuntimeExports.jsx("img", { src: OTPAuthenticationImg, 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-base -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" })] })] }) }));
|
|
1818
|
+
return (jsxRuntimeExports.jsx("div", { className: "flex justify-center items-center h-dvh", 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("div", { className: "flex justify-center items", children: jsxRuntimeExports.jsx("img", { src: OTPAuthenticationImg, 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-base -tracking-wide text-center", children: "Your Microsoft account has been validated. Please complete two-factor authentication to continue." })] }), jsxRuntimeExports.jsx(CardContent, { className: "max-w-[80%]", 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" })] })] }) }));
|
|
1774
1819
|
};
|
|
1775
1820
|
|
|
1776
1821
|
var LoginButton = function () {
|