@nibssplc/cams-sdk-react 0.0.1-beta.82 → 0.0.1-beta.84
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/ADLoginModal.d.ts +2 -2
- package/dist/components/MFAGate.d.ts +1 -2
- package/dist/hooks/useOTPHandler.d.ts +13 -0
- package/dist/index.cjs.js +19 -60
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.esm.js +21 -61
- package/dist/index.esm.js.map +1 -1
- package/package.json +2 -2
- package/dist/hooks/useCAMSPopupAuth.d.ts +0 -17
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
export * from './hooks/useCAMSAuth';
|
|
2
2
|
export * from './hooks/useCAMSMSALAuth';
|
|
3
|
-
export * from './hooks/useCAMSPopupAuth';
|
|
4
3
|
export * from './components/ProtectedRoute';
|
|
5
4
|
export { CAMSMSALProvider, useCAMSMSALContext } from './components/CAMSMSALProvider';
|
|
6
5
|
export * from './components/ClientOnly';
|
package/dist/index.esm.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import React__default, { useState, useRef, useEffect, useCallback, createContext, useContext, useMemo } from 'react';
|
|
3
|
-
import { CAMSSessionManager, isPopupWindow, CAMSMFAAuthenticator, Logger, CAMSError, CAMSErrorType
|
|
3
|
+
import { CAMSSessionManager, isPopupWindow, CAMSMFAAuthenticator, Logger, CAMSError, CAMSErrorType } from '@nibssplc/cams-sdk';
|
|
4
4
|
export * from '@nibssplc/cams-sdk';
|
|
5
5
|
import { useMsal, useAccount, MsalProvider } from '@azure/msal-react';
|
|
6
6
|
import { InteractionStatus, PublicClientApplication } from '@azure/msal-browser';
|
|
@@ -513,56 +513,6 @@ function useCAMSMSALAuth(options) {
|
|
|
513
513
|
};
|
|
514
514
|
}
|
|
515
515
|
|
|
516
|
-
/**
|
|
517
|
-
* Hook for handling authentication in popup windows
|
|
518
|
-
* This should be used by the popup app to complete authentication
|
|
519
|
-
*/
|
|
520
|
-
function useCAMSPopupAuth(options) {
|
|
521
|
-
if (options === void 0) { options = {}; }
|
|
522
|
-
var _a = options.storageKey, storageKey = _a === void 0 ? "CAMS-SDK" : _a, targetOrigin = options.targetOrigin, onAuthComplete = options.onAuthComplete, onAuthError = options.onAuthError;
|
|
523
|
-
useEffect(function () {
|
|
524
|
-
if (typeof window === "undefined" || !isPopupWindow())
|
|
525
|
-
return;
|
|
526
|
-
// Initialize popup auth handler
|
|
527
|
-
initializePopupAuth(targetOrigin);
|
|
528
|
-
// Set up global handlers for the popup app
|
|
529
|
-
var globalHandlers = window.__CAMS_POPUP_AUTH__;
|
|
530
|
-
if (globalHandlers) {
|
|
531
|
-
var originalCompleteAuth_1 = globalHandlers.completeAuth;
|
|
532
|
-
var originalErrorAuth_1 = globalHandlers.errorAuth;
|
|
533
|
-
globalHandlers.completeAuth = function (profile) {
|
|
534
|
-
onAuthComplete === null || onAuthComplete === void 0 ? void 0 : onAuthComplete(profile);
|
|
535
|
-
originalCompleteAuth_1(profile);
|
|
536
|
-
};
|
|
537
|
-
globalHandlers.errorAuth = function (error) {
|
|
538
|
-
onAuthError === null || onAuthError === void 0 ? void 0 : onAuthError(error);
|
|
539
|
-
originalErrorAuth_1(error);
|
|
540
|
-
};
|
|
541
|
-
}
|
|
542
|
-
}, [targetOrigin, onAuthComplete, onAuthError]);
|
|
543
|
-
var completeAuth = useCallback(function (profile) {
|
|
544
|
-
if (!isPopupWindow()) {
|
|
545
|
-
console.warn("completeAuth called outside of popup window");
|
|
546
|
-
return;
|
|
547
|
-
}
|
|
548
|
-
var sessionManager = new CAMSSessionManager(localStorage, storageKey);
|
|
549
|
-
sessionManager.completePopupAuth(profile, targetOrigin);
|
|
550
|
-
}, [storageKey, targetOrigin]);
|
|
551
|
-
var errorAuth = useCallback(function (error) {
|
|
552
|
-
if (!isPopupWindow()) {
|
|
553
|
-
console.warn("errorAuth called outside of popup window");
|
|
554
|
-
return;
|
|
555
|
-
}
|
|
556
|
-
var sessionManager = new CAMSSessionManager(localStorage, storageKey);
|
|
557
|
-
sessionManager.errorPopupAuth(error, targetOrigin);
|
|
558
|
-
}, [storageKey, targetOrigin]);
|
|
559
|
-
return {
|
|
560
|
-
completeAuth: completeAuth,
|
|
561
|
-
errorAuth: errorAuth,
|
|
562
|
-
isPopup: isPopupWindow(),
|
|
563
|
-
};
|
|
564
|
-
}
|
|
565
|
-
|
|
566
516
|
var jsxRuntime = {exports: {}};
|
|
567
517
|
|
|
568
518
|
var reactJsxRuntime_production = {};
|
|
@@ -1656,12 +1606,12 @@ var GenerateDeviceId = function () {
|
|
|
1656
1606
|
return (_a = deviceId.replace(/[^a-zA-Z0-9-_]/g, "_")) !== null && _a !== void 0 ? _a : "unknown-device";
|
|
1657
1607
|
};
|
|
1658
1608
|
|
|
1609
|
+
var MAX_ATTEMPTS = 3;
|
|
1659
1610
|
var useOTPHandler = function (_a) {
|
|
1660
1611
|
var provider = _a.provider, accessToken = _a.accessToken, idToken = _a.idToken, appCode = _a.appCode, authenticationType = _a.authenticationType, MFAEndpoint = _a.MFAEndpoint, onAuthComplete = _a.onAuthComplete;
|
|
1661
1612
|
var _b = useState(false), loading = _b[0], setLoading = _b[1];
|
|
1662
1613
|
var _c = useState(0), attemptCount = _c[0], setAttemptCount = _c[1];
|
|
1663
1614
|
var _d = useState(false), isMaxAttemptsReached = _d[0], setIsMaxAttemptsReached = _d[1];
|
|
1664
|
-
var MAX_ATTEMPTS = 3;
|
|
1665
1615
|
var handleSubmitOTP = useMemo(function () { return function (authenticationValue) { return __awaiter(void 0, void 0, void 0, function () {
|
|
1666
1616
|
var currentAttempt, response, error_1, currentAttempt;
|
|
1667
1617
|
return __generator(this, function (_a) {
|
|
@@ -1876,7 +1826,10 @@ var credentialsSchema = z.object({
|
|
|
1876
1826
|
var ADLoginModal = function (_a) {
|
|
1877
1827
|
var open = _a.open, onOpenChange = _a.onOpenChange, onLogin = _a.onLogin;
|
|
1878
1828
|
var _b = useState("credentials"), step = _b[0], setStep = _b[1];
|
|
1879
|
-
var _c = useState({
|
|
1829
|
+
var _c = useState({
|
|
1830
|
+
username: "",
|
|
1831
|
+
password: "",
|
|
1832
|
+
}), credentials = _c[0], setCredentials = _c[1];
|
|
1880
1833
|
var _d = useState(""), mfaCode = _d[0], setMfaCode = _d[1];
|
|
1881
1834
|
var _e = useState(false), isLoading = _e[0], setIsLoading = _e[1];
|
|
1882
1835
|
var form = useForm({
|
|
@@ -1899,7 +1852,11 @@ var ADLoginModal = function (_a) {
|
|
|
1899
1852
|
_a.label = 1;
|
|
1900
1853
|
case 1:
|
|
1901
1854
|
_a.trys.push([1, 3, 4, 5]);
|
|
1902
|
-
return [4 /*yield*/, onLogin(
|
|
1855
|
+
return [4 /*yield*/, onLogin({
|
|
1856
|
+
username: credentials.username,
|
|
1857
|
+
password: credentials.password,
|
|
1858
|
+
MFACode: code,
|
|
1859
|
+
})];
|
|
1903
1860
|
case 2:
|
|
1904
1861
|
_a.sent();
|
|
1905
1862
|
onOpenChange(false);
|
|
@@ -1924,7 +1881,7 @@ var ADLoginModal = function (_a) {
|
|
|
1924
1881
|
form.reset();
|
|
1925
1882
|
setMfaCode("");
|
|
1926
1883
|
};
|
|
1927
|
-
return (jsxRuntimeExports.jsx(Dialog, { open: open, onOpenChange: handleClose, children: jsxRuntimeExports.jsxs(DialogContent, { className: "sm:max-w-
|
|
1884
|
+
return (jsxRuntimeExports.jsx(Dialog, { open: open, onOpenChange: handleClose, children: jsxRuntimeExports.jsxs(DialogContent, { className: "sm:max-w-[85%]", 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) {
|
|
1928
1885
|
var field = _a.field;
|
|
1929
1886
|
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, {})] }));
|
|
1930
1887
|
} }), jsxRuntimeExports.jsx(FormField, { control: form.control, name: "password", render: function (_a) {
|
|
@@ -1964,10 +1921,11 @@ var DefaultLoginPage = function () {
|
|
|
1964
1921
|
// variant="outline"
|
|
1965
1922
|
, {
|
|
1966
1923
|
// variant="outline"
|
|
1967
|
-
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, {}), jsxRuntimeExports.jsx("span", { children: isLoading ? "Logging in..." : "Sign in with
|
|
1968
|
-
|
|
1924
|
+
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-8 h-8 text-[#506f4a]" }), jsxRuntimeExports.jsx("span", { children: isLoading ? "Logging in..." : "Sign in with ActiveDirectory" })] })] }), 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) {
|
|
1925
|
+
var username = _b.username, password = _b.password, MFACode = _b.MFACode;
|
|
1926
|
+
return __generator(this, function (_c) {
|
|
1969
1927
|
// Implement your AD login logic here
|
|
1970
|
-
console.log("AD Login:", { username: username, password: password,
|
|
1928
|
+
console.log("AD Login:", { username: username, password: password, MFACode: MFACode });
|
|
1971
1929
|
return [2 /*return*/];
|
|
1972
1930
|
});
|
|
1973
1931
|
}); } })] }));
|
|
@@ -1980,7 +1938,9 @@ var ErrorFallback = function (_a) {
|
|
|
1980
1938
|
|
|
1981
1939
|
var MFAEndpointUrlSchema = z$1.url("MFAEndpoint must be a valid URL");
|
|
1982
1940
|
var MFAGate = function (_a) {
|
|
1983
|
-
var children = _a.children, _b = _a.fallback, fallback = _b === void 0 ? jsxRuntimeExports.jsx(LoadingSpinner, {}) : _b,
|
|
1941
|
+
var children = _a.children, _b = _a.fallback, fallback = _b === void 0 ? jsxRuntimeExports.jsx(LoadingSpinner, {}) : _b,
|
|
1942
|
+
// loginComponent: LoginComponent = DefaultLoginPage,
|
|
1943
|
+
MFAEndpoint = _a.MFAEndpoint;
|
|
1984
1944
|
var context = useCAMSContext();
|
|
1985
1945
|
var validatedMFAEndpoint = useMemo(function () {
|
|
1986
1946
|
var parsed = MFAEndpointUrlSchema.safeParse(MFAEndpoint);
|
|
@@ -2015,10 +1975,10 @@ var MFAGate = function (_a) {
|
|
|
2015
1975
|
return (jsxRuntimeExports.jsx(MFAOptions, { MFAEndpoint: validatedMFAEndpoint, onComplete: handleComplete, onAuthFailed: handleAuthFailed }));
|
|
2016
1976
|
}
|
|
2017
1977
|
if (!context.isAuthenticated) {
|
|
2018
|
-
return jsxRuntimeExports.jsx(
|
|
1978
|
+
return jsxRuntimeExports.jsx(DefaultLoginPage, {});
|
|
2019
1979
|
}
|
|
2020
1980
|
return jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: children });
|
|
2021
1981
|
};
|
|
2022
1982
|
|
|
2023
|
-
export { CAMSMSALProvider, CAMSProvider, ClientOnly, DefaultLoginPage as LoginButton, MFAGate, MFAOptions, ProtectedRoute, UnifiedCAMSProvider, useCAMSAuth, useCAMSContext, useCAMSMSALAuth, useCAMSMSALContext
|
|
1983
|
+
export { CAMSMSALProvider, CAMSProvider, ClientOnly, DefaultLoginPage as LoginButton, MFAGate, MFAOptions, ProtectedRoute, UnifiedCAMSProvider, useCAMSAuth, useCAMSContext, useCAMSMSALAuth, useCAMSMSALContext };
|
|
2024
1984
|
//# sourceMappingURL=index.esm.js.map
|