@nibssplc/cams-sdk-react 1.0.0-rc.23 → 1.0.0-rc.24
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/useCAMSMSALAuth.d.ts +2 -0
- package/dist/index.cjs.js +12 -10
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +12 -10
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
|
@@ -11,6 +11,7 @@ export interface UseCAMSMSALAuthOptions {
|
|
|
11
11
|
appCode: string;
|
|
12
12
|
allowedOrigins?: string[];
|
|
13
13
|
MFAEndpoint?: string;
|
|
14
|
+
activeCookiePeriod?: number;
|
|
14
15
|
}
|
|
15
16
|
export interface UseCAMSMSALAuthReturn {
|
|
16
17
|
login: () => Promise<void>;
|
|
@@ -27,5 +28,6 @@ export interface UseCAMSMSALAuthReturn {
|
|
|
27
28
|
completeMFA: (data: UserValidatedResponse) => Promise<MFAResponse>;
|
|
28
29
|
setRequiresMFA: React.Dispatch<React.SetStateAction<boolean>>;
|
|
29
30
|
sendEmailOTP: () => Promise<boolean>;
|
|
31
|
+
activeCookiePeriod: number;
|
|
30
32
|
}
|
|
31
33
|
export declare function useCAMSMSALAuth(options: UseCAMSMSALAuthOptions): UseCAMSMSALAuthReturn;
|
package/dist/index.cjs.js
CHANGED
|
@@ -383,6 +383,7 @@ function useCAMSAuth(options) {
|
|
|
383
383
|
}
|
|
384
384
|
|
|
385
385
|
var setCookie = function (name, value, days) {
|
|
386
|
+
if (days === void 0) { days = 1; }
|
|
386
387
|
var expires = new Date(Date.now() + days * 24 * 60 * 60 * 1000).toUTCString();
|
|
387
388
|
console.log("Auth Cookie Expires >>>", { name: name, value: value, expires: expires });
|
|
388
389
|
document.cookie = "".concat(name, "=").concat(encodeURIComponent(value), "; expires=").concat(expires, "; path=/; samesite=Lax");
|
|
@@ -404,15 +405,15 @@ var deleteCookie = function (name) {
|
|
|
404
405
|
|
|
405
406
|
function useCAMSMSALAuth(options) {
|
|
406
407
|
var _this = this;
|
|
407
|
-
var optStorageKey = options.storageKey, optScopes = options.scopes, prompt = options.prompt, appCode = options.appCode, MFAEndpoint = options.MFAEndpoint, onAuthSuccess = options.onAuthSuccess, onAuthError = options.onAuthError;
|
|
408
|
+
var optStorageKey = options.storageKey, optScopes = options.scopes, prompt = options.prompt, appCode = options.appCode, MFAEndpoint = options.MFAEndpoint, onAuthSuccess = options.onAuthSuccess, onAuthError = options.onAuthError, _a = options.activeCookiePeriod, activeCookiePeriod = _a === void 0 ? 1 : _a;
|
|
408
409
|
var storageKey = optStorageKey || "CAMS-MSAL-AUTH-SDK";
|
|
409
|
-
var
|
|
410
|
+
var _b = msalReact.useMsal(), instance = _b.instance, inProgress = _b.inProgress, accounts = _b.accounts;
|
|
410
411
|
var account = msalReact.useAccount(accounts[0] || {});
|
|
411
|
-
var
|
|
412
|
-
var
|
|
413
|
-
var
|
|
414
|
-
var
|
|
415
|
-
var
|
|
412
|
+
var _c = React.useState(null), error = _c[0], setError = _c[1];
|
|
413
|
+
var _d = React.useState(""), idToken = _d[0], setIdToken = _d[1];
|
|
414
|
+
var _e = React.useState(""), accessToken = _e[0], setAccessToken = _e[1];
|
|
415
|
+
var _f = React.useState(null), mfaAuthenticator = _f[0], setMfaAuthenticator = _f[1];
|
|
416
|
+
var _g = React.useState(false), requiresMFA = _g[0], setRequiresMFA = _g[1];
|
|
416
417
|
var isLoading = inProgress !== msalBrowser.InteractionStatus.None;
|
|
417
418
|
var isAuthenticated = !!account && !!accessToken && !requiresMFA;
|
|
418
419
|
var scopes = optScopes || ["openid", "profile", "email"];
|
|
@@ -579,7 +580,7 @@ function useCAMSMSALAuth(options) {
|
|
|
579
580
|
accessToken: accessToken,
|
|
580
581
|
idToken: idToken,
|
|
581
582
|
}));
|
|
582
|
-
setCookie("CAMS-MSAL-AUTH-SDK-PROFILE", JSON.stringify({ type: "AUTH_SUCCESS", userProfile: __assign({}, data) }),
|
|
583
|
+
setCookie("CAMS-MSAL-AUTH-SDK-PROFILE", JSON.stringify({ type: "AUTH_SUCCESS", userProfile: __assign({}, data) }), activeCookiePeriod);
|
|
583
584
|
setRequiresMFA(false);
|
|
584
585
|
// Set requiresMFA to false after storage update
|
|
585
586
|
camsSdk.Logger.debug("MFA completed successfully, storage updated", {
|
|
@@ -598,7 +599,7 @@ function useCAMSMSALAuth(options) {
|
|
|
598
599
|
}
|
|
599
600
|
return [2 /*return*/];
|
|
600
601
|
});
|
|
601
|
-
}); }, [mfaAuthenticator, accessToken, idToken, storageKey]);
|
|
602
|
+
}); }, [mfaAuthenticator, accessToken, idToken, storageKey, activeCookiePeriod]);
|
|
602
603
|
var sendEmailOTP = React.useCallback(function () { return __awaiter$1(_this, void 0, void 0, function () {
|
|
603
604
|
return __generator$1(this, function (_a) {
|
|
604
605
|
switch (_a.label) {
|
|
@@ -654,7 +655,8 @@ function useCAMSMSALAuth(options) {
|
|
|
654
655
|
requiresMFA: requiresMFA,
|
|
655
656
|
completeMFA: completeMFA,
|
|
656
657
|
sendEmailOTP: sendEmailOTP,
|
|
657
|
-
setRequiresMFA: setRequiresMFA
|
|
658
|
+
setRequiresMFA: setRequiresMFA,
|
|
659
|
+
activeCookiePeriod: activeCookiePeriod,
|
|
658
660
|
};
|
|
659
661
|
}
|
|
660
662
|
|