@nibssplc/cams-sdk-react 0.0.1-beta.32 → 0.0.1-beta.33
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 +0 -1
- package/dist/index.cjs.js +38 -61
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +38 -61
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -16699,86 +16699,66 @@ function useCAMSMSALAuth(options) {
|
|
|
16699
16699
|
var _c = useState(null), token = _c[0], setToken = _c[1];
|
|
16700
16700
|
var _d = useState(null), idToken = _d[0], setIdToken = _d[1];
|
|
16701
16701
|
var _e = useState(null), accessToken = _e[0], setAccessToken = _e[1];
|
|
16702
|
-
var _f = useState(false), isMFAPending = _f[0], setIsMFAPending = _f[1];
|
|
16703
|
-
var _g = useState(false), hasRedirected = _g[0], setHasRedirected = _g[1];
|
|
16704
16702
|
var isLoading = inProgress !== InteractionStatus.None;
|
|
16705
|
-
var isAuthenticated = !!account && !!token
|
|
16703
|
+
var isAuthenticated = !!account && !!token;
|
|
16706
16704
|
var scopes = options.scopes || ["openid", "profile", "email"];
|
|
16707
|
-
useEffect(function () {
|
|
16708
|
-
if (account && !isMFAPending && !hasRedirected) {
|
|
16709
|
-
// Get token in foreground popup
|
|
16710
|
-
instance
|
|
16711
|
-
.acquireTokenPopup({
|
|
16712
|
-
scopes: scopes,
|
|
16713
|
-
account: account,
|
|
16714
|
-
prompt: options.prompt || "login",
|
|
16715
|
-
})
|
|
16716
|
-
.then(function (response) {
|
|
16717
|
-
var _a;
|
|
16718
|
-
setToken(response.accessToken);
|
|
16719
|
-
setAccessToken(response.accessToken);
|
|
16720
|
-
setIdToken(response.idToken);
|
|
16721
|
-
setIsMFAPending(true);
|
|
16722
|
-
setHasRedirected(true);
|
|
16723
|
-
// Small delay to ensure popup closes before redirect
|
|
16724
|
-
setTimeout(function () {
|
|
16725
|
-
if (typeof window !== "undefined" && process.env.NODE_ENV !== 'test') {
|
|
16726
|
-
window.location.href = options.mfaUrl;
|
|
16727
|
-
}
|
|
16728
|
-
}, 100);
|
|
16729
|
-
(_a = options.onAuthSuccess) === null || _a === void 0 ? void 0 : _a.call(options, response.accessToken);
|
|
16730
|
-
})
|
|
16731
|
-
.catch(function (err) {
|
|
16732
|
-
var _a;
|
|
16733
|
-
var camsError = new CAMSError(CAMSErrorType.API_VALIDATION_ERROR, "Failed to acquire token: " + err);
|
|
16734
|
-
setError(camsError);
|
|
16735
|
-
(_a = options.onAuthError) === null || _a === void 0 ? void 0 : _a.call(options, camsError);
|
|
16736
|
-
});
|
|
16737
|
-
}
|
|
16738
|
-
}, [account, instance, isMFAPending, hasRedirected]);
|
|
16739
16705
|
var login = useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
16740
|
-
var err_1, redirectErr_1, camsError_1, camsError;
|
|
16741
|
-
var _a, _b, _c;
|
|
16742
|
-
return __generator(this, function (
|
|
16743
|
-
switch (
|
|
16706
|
+
var loginResponse, tokenResponse, err_1, redirectErr_1, camsError_1, camsError;
|
|
16707
|
+
var _a, _b, _c, _d;
|
|
16708
|
+
return __generator(this, function (_e) {
|
|
16709
|
+
switch (_e.label) {
|
|
16744
16710
|
case 0:
|
|
16745
16711
|
setError(null);
|
|
16746
|
-
|
|
16712
|
+
_e.label = 1;
|
|
16747
16713
|
case 1:
|
|
16748
|
-
|
|
16749
|
-
return [4 /*yield*/, instance.
|
|
16714
|
+
_e.trys.push([1, 4, , 9]);
|
|
16715
|
+
return [4 /*yield*/, instance.loginPopup({
|
|
16750
16716
|
scopes: scopes,
|
|
16751
16717
|
prompt: options.prompt || "login",
|
|
16752
16718
|
})];
|
|
16753
16719
|
case 2:
|
|
16754
|
-
|
|
16755
|
-
return [
|
|
16720
|
+
loginResponse = _e.sent();
|
|
16721
|
+
return [4 /*yield*/, instance.acquireTokenPopup({
|
|
16722
|
+
scopes: scopes,
|
|
16723
|
+
account: loginResponse.account,
|
|
16724
|
+
prompt: options.prompt || "login",
|
|
16725
|
+
})];
|
|
16756
16726
|
case 3:
|
|
16757
|
-
|
|
16758
|
-
|
|
16759
|
-
|
|
16760
|
-
|
|
16727
|
+
tokenResponse = _e.sent();
|
|
16728
|
+
setToken(tokenResponse.accessToken);
|
|
16729
|
+
setAccessToken(tokenResponse.accessToken);
|
|
16730
|
+
setIdToken(tokenResponse.idToken);
|
|
16731
|
+
if (typeof window !== "undefined" && process.env.NODE_ENV !== 'test') {
|
|
16732
|
+
window.location.href = options.mfaUrl;
|
|
16733
|
+
}
|
|
16734
|
+
(_a = options.onAuthSuccess) === null || _a === void 0 ? void 0 : _a.call(options, tokenResponse.accessToken);
|
|
16735
|
+
return [3 /*break*/, 9];
|
|
16761
16736
|
case 4:
|
|
16762
|
-
|
|
16737
|
+
err_1 = _e.sent();
|
|
16738
|
+
if (!(err_1.errorCode === "popup_window_error" ||
|
|
16739
|
+
((_b = err_1.message) === null || _b === void 0 ? void 0 : _b.includes("popup")))) return [3 /*break*/, 8];
|
|
16740
|
+
_e.label = 5;
|
|
16741
|
+
case 5:
|
|
16742
|
+
_e.trys.push([5, 7, , 8]);
|
|
16763
16743
|
return [4 /*yield*/, instance.loginRedirect({
|
|
16764
16744
|
scopes: scopes,
|
|
16765
16745
|
prompt: options.prompt || "login",
|
|
16766
16746
|
})];
|
|
16767
|
-
case 5:
|
|
16768
|
-
_d.sent();
|
|
16769
|
-
return [2 /*return*/];
|
|
16770
16747
|
case 6:
|
|
16771
|
-
|
|
16748
|
+
_e.sent();
|
|
16749
|
+
return [2 /*return*/];
|
|
16750
|
+
case 7:
|
|
16751
|
+
redirectErr_1 = _e.sent();
|
|
16772
16752
|
camsError_1 = new CAMSError(CAMSErrorType.POPUP_BLOCKED, "Both popup and redirect failed: " + redirectErr_1);
|
|
16773
16753
|
setError(camsError_1);
|
|
16774
|
-
(
|
|
16754
|
+
(_c = options.onAuthError) === null || _c === void 0 ? void 0 : _c.call(options, camsError_1);
|
|
16775
16755
|
return [2 /*return*/];
|
|
16776
|
-
case
|
|
16756
|
+
case 8:
|
|
16777
16757
|
camsError = new CAMSError(CAMSErrorType.API_VALIDATION_ERROR, "Login failed: " + err_1);
|
|
16778
16758
|
setError(camsError);
|
|
16779
|
-
(
|
|
16780
|
-
return [3 /*break*/,
|
|
16781
|
-
case
|
|
16759
|
+
(_d = options.onAuthError) === null || _d === void 0 ? void 0 : _d.call(options, camsError);
|
|
16760
|
+
return [3 /*break*/, 9];
|
|
16761
|
+
case 9: return [2 /*return*/];
|
|
16782
16762
|
}
|
|
16783
16763
|
});
|
|
16784
16764
|
}); }, [instance, scopes, options]);
|
|
@@ -16793,8 +16773,6 @@ function useCAMSMSALAuth(options) {
|
|
|
16793
16773
|
_a.sent();
|
|
16794
16774
|
setToken(null);
|
|
16795
16775
|
setError(null);
|
|
16796
|
-
setIsMFAPending(false);
|
|
16797
|
-
setHasRedirected(false);
|
|
16798
16776
|
return [3 /*break*/, 3];
|
|
16799
16777
|
case 2:
|
|
16800
16778
|
err_2 = _a.sent();
|
|
@@ -16810,7 +16788,6 @@ function useCAMSMSALAuth(options) {
|
|
|
16810
16788
|
logout: logout,
|
|
16811
16789
|
isAuthenticated: isAuthenticated,
|
|
16812
16790
|
isLoading: isLoading,
|
|
16813
|
-
isMFAPending: isMFAPending,
|
|
16814
16791
|
error: error,
|
|
16815
16792
|
token: token,
|
|
16816
16793
|
idToken: idToken,
|