@nibssplc/cams-sdk-react 1.0.0-rc.67 → 1.0.0-rc.69
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/MFAGate.d.ts +2 -1
- package/dist/components/UnifiedCAMSProvider.d.ts +2 -2
- package/dist/hooks/useCAMSMSALAuth.d.ts +2 -2
- package/dist/index.cjs.js +29 -16
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +29 -16
- package/dist/index.esm.js.map +1 -1
- package/package.json +2 -2
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { PublicClientApplication, Configuration } from "@azure/msal-browser";
|
|
3
3
|
import { UseCAMSAuthOptions } from "../hooks/useCAMSAuth";
|
|
4
|
-
import { UseCAMSMSALAuthOptions } from "../hooks/useCAMSMSALAuth";
|
|
5
4
|
import { useCAMSContext } from "../context/CAMSContext";
|
|
6
5
|
interface BaseProviderProps {
|
|
7
6
|
children: React.ReactNode;
|
|
@@ -10,8 +9,9 @@ interface BaseProviderProps {
|
|
|
10
9
|
interface RegularProviderProps extends BaseProviderProps, Omit<UseCAMSAuthOptions, "appCode"> {
|
|
11
10
|
mode: "REGULAR";
|
|
12
11
|
}
|
|
13
|
-
interface MSALProviderProps extends BaseProviderProps
|
|
12
|
+
interface MSALProviderProps extends BaseProviderProps {
|
|
14
13
|
mode: "MSAL";
|
|
14
|
+
ValidateUserEndpoint: string;
|
|
15
15
|
msalConfig: Configuration;
|
|
16
16
|
msalInstance?: PublicClientApplication;
|
|
17
17
|
onAuthSuccess?: (tokens: {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import "../utils/crypto-polyfill";
|
|
2
|
-
import { CAMSError, MFAAuthenticatedResponse } from "@nibssplc/cams-sdk";
|
|
2
|
+
import { CAMSError, type MFAAuthenticatedResponse } from "@nibssplc/cams-sdk";
|
|
3
3
|
export interface UseCAMSMSALAuthOptions {
|
|
4
4
|
onTokenExpired?: () => void;
|
|
5
5
|
scopes?: string[];
|
|
@@ -8,7 +8,7 @@ export interface UseCAMSMSALAuthOptions {
|
|
|
8
8
|
messageOrigin?: string;
|
|
9
9
|
appCode: string;
|
|
10
10
|
allowedOrigins?: string[];
|
|
11
|
-
|
|
11
|
+
ValidateUserEndpoint: string;
|
|
12
12
|
activeCookiePeriod?: number;
|
|
13
13
|
}
|
|
14
14
|
export interface UseCAMSMSALAuthReturn {
|
package/dist/index.cjs.js
CHANGED
|
@@ -433,7 +433,7 @@ var deleteCookie = function (name) {
|
|
|
433
433
|
|
|
434
434
|
function useCAMSMSALAuth(options) {
|
|
435
435
|
var _this = this;
|
|
436
|
-
var optStorageKey = options.storageKey, optScopes = options.scopes, prompt = options.prompt, appCode = options.appCode,
|
|
436
|
+
var optStorageKey = options.storageKey, optScopes = options.scopes, prompt = options.prompt, appCode = options.appCode, ValidateUserEndpoint = options.ValidateUserEndpoint, _a = options.activeCookiePeriod, activeCookiePeriod = _a === void 0 ? 1 : _a;
|
|
437
437
|
var storageKey = optStorageKey || "CAMS-MSAL-AUTH-SDK";
|
|
438
438
|
var _b = msalReact.useMsal(), instance = _b.instance, inProgress = _b.inProgress, accounts = _b.accounts;
|
|
439
439
|
var account = msalReact.useAccount(accounts[0] || {});
|
|
@@ -515,7 +515,7 @@ function useCAMSMSALAuth(options) {
|
|
|
515
515
|
accessToken: response.accessToken,
|
|
516
516
|
idToken: response.idToken,
|
|
517
517
|
provider: "MSAL",
|
|
518
|
-
APIAuthEndpoint:
|
|
518
|
+
APIAuthEndpoint: ValidateUserEndpoint,
|
|
519
519
|
};
|
|
520
520
|
authenticator = new camsSdk.CAMSMFAAuthenticator();
|
|
521
521
|
return [4 /*yield*/, authenticator.GetUserMFAConfig(mfaConfig)];
|
|
@@ -523,9 +523,9 @@ function useCAMSMSALAuth(options) {
|
|
|
523
523
|
userConfig = _b.sent();
|
|
524
524
|
camsSdk.Logger.debug("MFA Authenticator initialized:", userConfig);
|
|
525
525
|
console.log("MFA Authenticator initialized:", userConfig);
|
|
526
|
-
setRequiresMFA(userConfig.userInfo.isMFAEnabled);
|
|
527
526
|
// Don't persist as authenticated until MFA is complete
|
|
528
|
-
if (typeof window !== "undefined") {
|
|
527
|
+
if (typeof window !== "undefined" && userConfig.isValid) {
|
|
528
|
+
setRequiresMFA(userConfig.userInfo.isMFAEnabled);
|
|
529
529
|
localStorage.setItem(storageKey, JSON.stringify({
|
|
530
530
|
isAuthenticated: false,
|
|
531
531
|
requiresMFA: userConfig.userInfo.isMFAEnabled,
|
|
@@ -560,7 +560,15 @@ function useCAMSMSALAuth(options) {
|
|
|
560
560
|
case 5: return [2 /*return*/];
|
|
561
561
|
}
|
|
562
562
|
});
|
|
563
|
-
}); }, [
|
|
563
|
+
}); }, [
|
|
564
|
+
instance,
|
|
565
|
+
scopes,
|
|
566
|
+
prompt,
|
|
567
|
+
appCode,
|
|
568
|
+
ValidateUserEndpoint,
|
|
569
|
+
storageKey,
|
|
570
|
+
inProgress,
|
|
571
|
+
]);
|
|
564
572
|
var completeMFA = React.useCallback(function (data) { return __awaiter$1(_this, void 0, void 0, function () {
|
|
565
573
|
return __generator$1(this, function (_a) {
|
|
566
574
|
camsSdk.Logger.info("Completed MFA.. Setting State");
|
|
@@ -573,7 +581,11 @@ function useCAMSMSALAuth(options) {
|
|
|
573
581
|
accessToken: accessToken,
|
|
574
582
|
idToken: idToken,
|
|
575
583
|
}));
|
|
576
|
-
setCookie("CAMS-MSAL-AUTH-SDK-PROFILE", JSON.stringify({
|
|
584
|
+
setCookie("CAMS-MSAL-AUTH-SDK-PROFILE", JSON.stringify({
|
|
585
|
+
state: "AUTH_SUCCESS",
|
|
586
|
+
role: data.userInfo.role,
|
|
587
|
+
profile: __assign({}, data),
|
|
588
|
+
}), activeCookiePeriod);
|
|
577
589
|
setRequiresMFA(false);
|
|
578
590
|
// Set requiresMFA to false after storage update
|
|
579
591
|
camsSdk.Logger.debug("MFA completed successfully, storage updated", {
|
|
@@ -949,8 +961,8 @@ function CAMSProviderCore(props) {
|
|
|
949
961
|
? __assign(__assign({}, props), { appCode: appCode })
|
|
950
962
|
: { appCode: "" });
|
|
951
963
|
var msalAuth = useCAMSMSALAuth(mode === "MSAL"
|
|
952
|
-
? __assign(__assign({}, props), { appCode: appCode })
|
|
953
|
-
: { appCode: "" });
|
|
964
|
+
? __assign(__assign({}, props), { appCode: appCode, ValidateUserEndpoint: props.ValidateUserEndpoint })
|
|
965
|
+
: { appCode: "", ValidateUserEndpoint: "" });
|
|
954
966
|
var auth = mode === "REGULAR" ? regularAuth : msalAuth;
|
|
955
967
|
var profileStorageKey = "".concat(auth.storageKey, "-PROFILE");
|
|
956
968
|
var getInitialProfile = function () {
|
|
@@ -1580,7 +1592,7 @@ var MFAOptions = function (_a) {
|
|
|
1580
1592
|
var _j = useOTPHandler({
|
|
1581
1593
|
email: ((_c = (_b = context.user) === null || _b === void 0 ? void 0 : _b.profile) === null || _c === void 0 ? void 0 : _c.email) || "",
|
|
1582
1594
|
appCode: context.appCode || "",
|
|
1583
|
-
MFAEndpoint: MFAEndpoints.
|
|
1595
|
+
MFAEndpoint: MFAEndpoints.ValidateUserMFA,
|
|
1584
1596
|
onAuthComplete: function (state, data) {
|
|
1585
1597
|
console.log("Completed Auth. Handling MFA", state);
|
|
1586
1598
|
if (state) {
|
|
@@ -1756,13 +1768,13 @@ var DefaultLoginPage = function (_a) {
|
|
|
1756
1768
|
context.requiresMFA = false;
|
|
1757
1769
|
context.setUserProfile({
|
|
1758
1770
|
state: "AUTH_SUCCESS",
|
|
1759
|
-
|
|
1771
|
+
message: data.message,
|
|
1772
|
+
role: data.userInfo.role,
|
|
1760
1773
|
profile: {
|
|
1761
|
-
id: data.
|
|
1762
|
-
name: data.
|
|
1763
|
-
email: data.
|
|
1764
|
-
isMFAEnabled: data.
|
|
1765
|
-
message: data.message,
|
|
1774
|
+
id: data.userInfo.id,
|
|
1775
|
+
name: data.userInfo.name,
|
|
1776
|
+
email: data.userInfo.email,
|
|
1777
|
+
isMFAEnabled: data.userInfo.isMFAEnabled,
|
|
1766
1778
|
tokens: data.tokens,
|
|
1767
1779
|
},
|
|
1768
1780
|
});
|
|
@@ -1812,7 +1824,8 @@ var ErrorFallback = function (_a) {
|
|
|
1812
1824
|
};
|
|
1813
1825
|
|
|
1814
1826
|
var MFAEndpointsSchema = z.object({
|
|
1815
|
-
|
|
1827
|
+
ValidateUser: z.url("ValidateUser Endpoint must be a valid URL"),
|
|
1828
|
+
ValidateUserMFA: z.url("ValidateUser MFA Endpoint must be a valid URL"),
|
|
1816
1829
|
RegisterNewChallenge: z.url("MFA RegisterNewChallenge must be a valid URL"),
|
|
1817
1830
|
RegisterVerify: z.url("MFA RegisterVerify must be a valid URL"),
|
|
1818
1831
|
RetrieveAuthChallenge: z.url("MFA RetrieveAuthChallenge must be a valid URL"),
|