@nibssplc/cams-sdk-react 1.0.0-rc.23 → 1.0.0-rc.25
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 +77 -39
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +77 -39
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -24,20 +24,38 @@ import https from 'https';
|
|
|
24
24
|
if (typeof window !== 'undefined') {
|
|
25
25
|
// Ensure crypto object exists
|
|
26
26
|
if (!window.crypto) {
|
|
27
|
-
|
|
27
|
+
try {
|
|
28
|
+
Object.defineProperty(window, 'crypto', {
|
|
29
|
+
value: {},
|
|
30
|
+
writable: true,
|
|
31
|
+
configurable: true
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
catch (e) {
|
|
35
|
+
// Ignore if crypto cannot be defined
|
|
36
|
+
}
|
|
28
37
|
}
|
|
29
38
|
// Polyfill getRandomValues
|
|
30
|
-
if (!window.crypto.getRandomValues) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
39
|
+
if (window.crypto && !window.crypto.getRandomValues) {
|
|
40
|
+
try {
|
|
41
|
+
Object.defineProperty(window.crypto, 'getRandomValues', {
|
|
42
|
+
value: function (array) {
|
|
43
|
+
var bytes = new Uint8Array(array.buffer, array.byteOffset, array.byteLength);
|
|
44
|
+
for (var i = 0; i < bytes.length; i++) {
|
|
45
|
+
bytes[i] = Math.floor(Math.random() * 256);
|
|
46
|
+
}
|
|
47
|
+
return array;
|
|
48
|
+
},
|
|
49
|
+
writable: true,
|
|
50
|
+
configurable: true
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
catch (e) {
|
|
54
|
+
// Ignore if getRandomValues cannot be defined
|
|
55
|
+
}
|
|
38
56
|
}
|
|
39
57
|
// Polyfill crypto.subtle with SHA-256 (handles both undefined and null in non-HTTPS contexts)
|
|
40
|
-
if (!window.crypto.subtle || window.location.protocol === 'http:') {
|
|
58
|
+
if (window.crypto && (!window.crypto.subtle || window.location.protocol === 'http:')) {
|
|
41
59
|
var sha256_1 = function (data) { return __awaiter(void 0, void 0, void 0, function () {
|
|
42
60
|
var bytes, hash, k, ml, msg, i, w, j, j, s0, s1, a, b, c, d, e, f, g, h, j, S1, ch, temp1, S0, maj, temp2, result, i;
|
|
43
61
|
return __generator(this, function (_a) {
|
|
@@ -107,28 +125,46 @@ if (typeof window !== 'undefined') {
|
|
|
107
125
|
return [2 /*return*/, result.buffer];
|
|
108
126
|
});
|
|
109
127
|
}); };
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
128
|
+
try {
|
|
129
|
+
Object.defineProperty(window.crypto, 'subtle', {
|
|
130
|
+
value: {
|
|
131
|
+
digest: function (algorithm, data) { return __awaiter(void 0, void 0, void 0, function () {
|
|
132
|
+
var alg;
|
|
133
|
+
return __generator(this, function (_a) {
|
|
134
|
+
alg = typeof algorithm === 'string' ? algorithm : algorithm.name;
|
|
135
|
+
if (alg === 'SHA-256')
|
|
136
|
+
return [2 /*return*/, sha256_1(data)];
|
|
137
|
+
console.error("Unsupported crypto algorithm: ".concat(alg));
|
|
138
|
+
throw new Error("Unsupported algorithm: ".concat(alg));
|
|
139
|
+
});
|
|
140
|
+
}); }
|
|
141
|
+
},
|
|
142
|
+
writable: true,
|
|
143
|
+
configurable: true
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
catch (e) {
|
|
147
|
+
// Ignore if subtle cannot be defined
|
|
148
|
+
}
|
|
122
149
|
}
|
|
123
150
|
// Polyfill randomUUID
|
|
124
|
-
if (!window.crypto.randomUUID) {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
151
|
+
if (window.crypto && !window.crypto.randomUUID) {
|
|
152
|
+
try {
|
|
153
|
+
Object.defineProperty(window.crypto, 'randomUUID', {
|
|
154
|
+
value: function () {
|
|
155
|
+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
|
156
|
+
var r = (Math.random() * 16) | 0;
|
|
157
|
+
var v = c === 'x' ? r : (r & 0x3) | 0x8;
|
|
158
|
+
return v.toString(16);
|
|
159
|
+
});
|
|
160
|
+
},
|
|
161
|
+
writable: true,
|
|
162
|
+
configurable: true
|
|
130
163
|
});
|
|
131
|
-
}
|
|
164
|
+
}
|
|
165
|
+
catch (e) {
|
|
166
|
+
// Ignore if randomUUID cannot be defined
|
|
167
|
+
}
|
|
132
168
|
}
|
|
133
169
|
}
|
|
134
170
|
|
|
@@ -362,6 +398,7 @@ function useCAMSAuth(options) {
|
|
|
362
398
|
}
|
|
363
399
|
|
|
364
400
|
var setCookie = function (name, value, days) {
|
|
401
|
+
if (days === void 0) { days = 1; }
|
|
365
402
|
var expires = new Date(Date.now() + days * 24 * 60 * 60 * 1000).toUTCString();
|
|
366
403
|
console.log("Auth Cookie Expires >>>", { name: name, value: value, expires: expires });
|
|
367
404
|
document.cookie = "".concat(name, "=").concat(encodeURIComponent(value), "; expires=").concat(expires, "; path=/; samesite=Lax");
|
|
@@ -383,15 +420,15 @@ var deleteCookie = function (name) {
|
|
|
383
420
|
|
|
384
421
|
function useCAMSMSALAuth(options) {
|
|
385
422
|
var _this = this;
|
|
386
|
-
var optStorageKey = options.storageKey, optScopes = options.scopes, prompt = options.prompt, appCode = options.appCode, MFAEndpoint = options.MFAEndpoint, onAuthSuccess = options.onAuthSuccess, onAuthError = options.onAuthError;
|
|
423
|
+
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;
|
|
387
424
|
var storageKey = optStorageKey || "CAMS-MSAL-AUTH-SDK";
|
|
388
|
-
var
|
|
425
|
+
var _b = useMsal(), instance = _b.instance, inProgress = _b.inProgress, accounts = _b.accounts;
|
|
389
426
|
var account = useAccount(accounts[0] || {});
|
|
390
|
-
var
|
|
391
|
-
var
|
|
392
|
-
var
|
|
393
|
-
var
|
|
394
|
-
var
|
|
427
|
+
var _c = useState(null), error = _c[0], setError = _c[1];
|
|
428
|
+
var _d = useState(""), idToken = _d[0], setIdToken = _d[1];
|
|
429
|
+
var _e = useState(""), accessToken = _e[0], setAccessToken = _e[1];
|
|
430
|
+
var _f = useState(null), mfaAuthenticator = _f[0], setMfaAuthenticator = _f[1];
|
|
431
|
+
var _g = useState(false), requiresMFA = _g[0], setRequiresMFA = _g[1];
|
|
395
432
|
var isLoading = inProgress !== InteractionStatus.None;
|
|
396
433
|
var isAuthenticated = !!account && !!accessToken && !requiresMFA;
|
|
397
434
|
var scopes = optScopes || ["openid", "profile", "email"];
|
|
@@ -558,7 +595,7 @@ function useCAMSMSALAuth(options) {
|
|
|
558
595
|
accessToken: accessToken,
|
|
559
596
|
idToken: idToken,
|
|
560
597
|
}));
|
|
561
|
-
setCookie("CAMS-MSAL-AUTH-SDK-PROFILE", JSON.stringify({ type: "AUTH_SUCCESS", userProfile: __assign({}, data) }),
|
|
598
|
+
setCookie("CAMS-MSAL-AUTH-SDK-PROFILE", JSON.stringify({ type: "AUTH_SUCCESS", userProfile: __assign({}, data) }), activeCookiePeriod);
|
|
562
599
|
setRequiresMFA(false);
|
|
563
600
|
// Set requiresMFA to false after storage update
|
|
564
601
|
Logger.debug("MFA completed successfully, storage updated", {
|
|
@@ -577,7 +614,7 @@ function useCAMSMSALAuth(options) {
|
|
|
577
614
|
}
|
|
578
615
|
return [2 /*return*/];
|
|
579
616
|
});
|
|
580
|
-
}); }, [mfaAuthenticator, accessToken, idToken, storageKey]);
|
|
617
|
+
}); }, [mfaAuthenticator, accessToken, idToken, storageKey, activeCookiePeriod]);
|
|
581
618
|
var sendEmailOTP = useCallback(function () { return __awaiter$1(_this, void 0, void 0, function () {
|
|
582
619
|
return __generator$1(this, function (_a) {
|
|
583
620
|
switch (_a.label) {
|
|
@@ -633,7 +670,8 @@ function useCAMSMSALAuth(options) {
|
|
|
633
670
|
requiresMFA: requiresMFA,
|
|
634
671
|
completeMFA: completeMFA,
|
|
635
672
|
sendEmailOTP: sendEmailOTP,
|
|
636
|
-
setRequiresMFA: setRequiresMFA
|
|
673
|
+
setRequiresMFA: setRequiresMFA,
|
|
674
|
+
activeCookiePeriod: activeCookiePeriod,
|
|
637
675
|
};
|
|
638
676
|
}
|
|
639
677
|
|