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