@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.cjs.js
CHANGED
|
@@ -16718,81 +16718,66 @@ function useCAMSMSALAuth(options) {
|
|
|
16718
16718
|
var _c = React__default.useState(null), token = _c[0], setToken = _c[1];
|
|
16719
16719
|
var _d = React__default.useState(null), idToken = _d[0], setIdToken = _d[1];
|
|
16720
16720
|
var _e = React__default.useState(null), accessToken = _e[0], setAccessToken = _e[1];
|
|
16721
|
-
var _f = React__default.useState(false), isMFAPending = _f[0], setIsMFAPending = _f[1];
|
|
16722
16721
|
var isLoading = inProgress !== InteractionStatus.None;
|
|
16723
|
-
var isAuthenticated = !!account && !!token
|
|
16722
|
+
var isAuthenticated = !!account && !!token;
|
|
16724
16723
|
var scopes = options.scopes || ["openid", "profile", "email"];
|
|
16725
|
-
React__default.useEffect(function () {
|
|
16726
|
-
if (account && !isMFAPending) {
|
|
16727
|
-
// Get token in foreground popup
|
|
16728
|
-
instance
|
|
16729
|
-
.acquireTokenPopup({
|
|
16730
|
-
scopes: scopes,
|
|
16731
|
-
account: account,
|
|
16732
|
-
prompt: options.prompt || "login",
|
|
16733
|
-
})
|
|
16734
|
-
.then(function (response) {
|
|
16735
|
-
var _a;
|
|
16736
|
-
setToken(response.accessToken);
|
|
16737
|
-
setAccessToken(response.accessToken);
|
|
16738
|
-
setIdToken(response.idToken);
|
|
16739
|
-
setIsMFAPending(true);
|
|
16740
|
-
if (typeof window !== "undefined" && process.env.NODE_ENV !== 'test') {
|
|
16741
|
-
window.location.href = options.mfaUrl;
|
|
16742
|
-
}
|
|
16743
|
-
(_a = options.onAuthSuccess) === null || _a === void 0 ? void 0 : _a.call(options, response.accessToken);
|
|
16744
|
-
})
|
|
16745
|
-
.catch(function (err) {
|
|
16746
|
-
var _a;
|
|
16747
|
-
var camsError = new camsSdk.CAMSError(camsSdk.CAMSErrorType.API_VALIDATION_ERROR, "Failed to acquire token: " + err);
|
|
16748
|
-
setError(camsError);
|
|
16749
|
-
(_a = options.onAuthError) === null || _a === void 0 ? void 0 : _a.call(options, camsError);
|
|
16750
|
-
});
|
|
16751
|
-
}
|
|
16752
|
-
}, [account, instance, isMFAPending]);
|
|
16753
16724
|
var login = React__default.useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
16754
|
-
var err_1, redirectErr_1, camsError_1, camsError;
|
|
16755
|
-
var _a, _b, _c;
|
|
16756
|
-
return __generator(this, function (
|
|
16757
|
-
switch (
|
|
16725
|
+
var loginResponse, tokenResponse, err_1, redirectErr_1, camsError_1, camsError;
|
|
16726
|
+
var _a, _b, _c, _d;
|
|
16727
|
+
return __generator(this, function (_e) {
|
|
16728
|
+
switch (_e.label) {
|
|
16758
16729
|
case 0:
|
|
16759
16730
|
setError(null);
|
|
16760
|
-
|
|
16731
|
+
_e.label = 1;
|
|
16761
16732
|
case 1:
|
|
16762
|
-
|
|
16733
|
+
_e.trys.push([1, 4, , 9]);
|
|
16763
16734
|
return [4 /*yield*/, instance.loginPopup({
|
|
16764
16735
|
scopes: scopes,
|
|
16765
16736
|
prompt: options.prompt || "login",
|
|
16766
16737
|
})];
|
|
16767
16738
|
case 2:
|
|
16768
|
-
|
|
16769
|
-
return [
|
|
16739
|
+
loginResponse = _e.sent();
|
|
16740
|
+
return [4 /*yield*/, instance.acquireTokenPopup({
|
|
16741
|
+
scopes: scopes,
|
|
16742
|
+
account: loginResponse.account,
|
|
16743
|
+
prompt: options.prompt || "login",
|
|
16744
|
+
})];
|
|
16770
16745
|
case 3:
|
|
16771
|
-
|
|
16772
|
-
|
|
16773
|
-
|
|
16774
|
-
|
|
16746
|
+
tokenResponse = _e.sent();
|
|
16747
|
+
setToken(tokenResponse.accessToken);
|
|
16748
|
+
setAccessToken(tokenResponse.accessToken);
|
|
16749
|
+
setIdToken(tokenResponse.idToken);
|
|
16750
|
+
if (typeof window !== "undefined" && process.env.NODE_ENV !== 'test') {
|
|
16751
|
+
window.location.href = options.mfaUrl;
|
|
16752
|
+
}
|
|
16753
|
+
(_a = options.onAuthSuccess) === null || _a === void 0 ? void 0 : _a.call(options, tokenResponse.accessToken);
|
|
16754
|
+
return [3 /*break*/, 9];
|
|
16775
16755
|
case 4:
|
|
16776
|
-
|
|
16756
|
+
err_1 = _e.sent();
|
|
16757
|
+
if (!(err_1.errorCode === "popup_window_error" ||
|
|
16758
|
+
((_b = err_1.message) === null || _b === void 0 ? void 0 : _b.includes("popup")))) return [3 /*break*/, 8];
|
|
16759
|
+
_e.label = 5;
|
|
16760
|
+
case 5:
|
|
16761
|
+
_e.trys.push([5, 7, , 8]);
|
|
16777
16762
|
return [4 /*yield*/, instance.loginRedirect({
|
|
16778
16763
|
scopes: scopes,
|
|
16779
16764
|
prompt: options.prompt || "login",
|
|
16780
16765
|
})];
|
|
16781
|
-
case 5:
|
|
16782
|
-
_d.sent();
|
|
16783
|
-
return [2 /*return*/];
|
|
16784
16766
|
case 6:
|
|
16785
|
-
|
|
16767
|
+
_e.sent();
|
|
16768
|
+
return [2 /*return*/];
|
|
16769
|
+
case 7:
|
|
16770
|
+
redirectErr_1 = _e.sent();
|
|
16786
16771
|
camsError_1 = new camsSdk.CAMSError(camsSdk.CAMSErrorType.POPUP_BLOCKED, "Both popup and redirect failed: " + redirectErr_1);
|
|
16787
16772
|
setError(camsError_1);
|
|
16788
|
-
(
|
|
16773
|
+
(_c = options.onAuthError) === null || _c === void 0 ? void 0 : _c.call(options, camsError_1);
|
|
16789
16774
|
return [2 /*return*/];
|
|
16790
|
-
case
|
|
16775
|
+
case 8:
|
|
16791
16776
|
camsError = new camsSdk.CAMSError(camsSdk.CAMSErrorType.API_VALIDATION_ERROR, "Login failed: " + err_1);
|
|
16792
16777
|
setError(camsError);
|
|
16793
|
-
(
|
|
16794
|
-
return [3 /*break*/,
|
|
16795
|
-
case
|
|
16778
|
+
(_d = options.onAuthError) === null || _d === void 0 ? void 0 : _d.call(options, camsError);
|
|
16779
|
+
return [3 /*break*/, 9];
|
|
16780
|
+
case 9: return [2 /*return*/];
|
|
16796
16781
|
}
|
|
16797
16782
|
});
|
|
16798
16783
|
}); }, [instance, scopes, options]);
|
|
@@ -16807,7 +16792,6 @@ function useCAMSMSALAuth(options) {
|
|
|
16807
16792
|
_a.sent();
|
|
16808
16793
|
setToken(null);
|
|
16809
16794
|
setError(null);
|
|
16810
|
-
setIsMFAPending(false);
|
|
16811
16795
|
return [3 /*break*/, 3];
|
|
16812
16796
|
case 2:
|
|
16813
16797
|
err_2 = _a.sent();
|
|
@@ -16823,7 +16807,6 @@ function useCAMSMSALAuth(options) {
|
|
|
16823
16807
|
logout: logout,
|
|
16824
16808
|
isAuthenticated: isAuthenticated,
|
|
16825
16809
|
isLoading: isLoading,
|
|
16826
|
-
isMFAPending: isMFAPending,
|
|
16827
16810
|
error: error,
|
|
16828
16811
|
token: token,
|
|
16829
16812
|
idToken: idToken,
|