@nibssplc/cams-sdk-react 0.0.1-beta.21 → 0.0.1-beta.23
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/index.cjs.js +66 -40
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +66 -40
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -16720,15 +16720,53 @@ function useCAMSMSALAuth(options) {
|
|
|
16720
16720
|
var isAuthenticated = !!account && !!token && !isMFAPending;
|
|
16721
16721
|
var scopes = options.scopes || ["openid", "profile", "email"];
|
|
16722
16722
|
React__default.useEffect(function () {
|
|
16723
|
-
if (account && !
|
|
16724
|
-
|
|
16725
|
-
|
|
16726
|
-
|
|
16723
|
+
if (account && !isMFAPending) {
|
|
16724
|
+
// Get token in foreground popup
|
|
16725
|
+
instance
|
|
16726
|
+
.acquireTokenSilent({
|
|
16727
|
+
scopes: scopes,
|
|
16728
|
+
account: account,
|
|
16729
|
+
prompt: options.prompt || "select_account",
|
|
16730
|
+
})
|
|
16731
|
+
.then(function (response) {
|
|
16732
|
+
var _a, _b;
|
|
16733
|
+
if (options.mfaUrl) {
|
|
16734
|
+
setIsMFAPending(true);
|
|
16735
|
+
(_a = options.onMFARequired) === null || _a === void 0 ? void 0 : _a.call(options, response.accessToken, account);
|
|
16736
|
+
if (typeof window !== "undefined") {
|
|
16737
|
+
window.location.href = options.mfaUrl;
|
|
16738
|
+
}
|
|
16739
|
+
}
|
|
16740
|
+
else {
|
|
16741
|
+
setToken(response.accessToken);
|
|
16742
|
+
setProfile({
|
|
16743
|
+
type: "AUTH_SUCCESS",
|
|
16744
|
+
userProfile: {
|
|
16745
|
+
name: account.name || "",
|
|
16746
|
+
email: account.username || "",
|
|
16747
|
+
isAuthenticated: true,
|
|
16748
|
+
mfaIsEnabled: true,
|
|
16749
|
+
message: "Authentication successful",
|
|
16750
|
+
userType: "USER",
|
|
16751
|
+
tokens: {
|
|
16752
|
+
Nonce: "",
|
|
16753
|
+
Bearer: response.accessToken,
|
|
16754
|
+
},
|
|
16755
|
+
},
|
|
16756
|
+
});
|
|
16757
|
+
(_b = options.onAuthSuccess) === null || _b === void 0 ? void 0 : _b.call(options, response.accessToken);
|
|
16758
|
+
}
|
|
16759
|
+
})
|
|
16760
|
+
.catch(function (err) {
|
|
16761
|
+
var _a;
|
|
16762
|
+
var camsError = new camsSdk.CAMSError(camsSdk.CAMSErrorType.API_VALIDATION_ERROR, "Failed to acquire token: " + err);
|
|
16763
|
+
setError(camsError);
|
|
16764
|
+
(_a = options.onAuthError) === null || _a === void 0 ? void 0 : _a.call(options, camsError);
|
|
16727
16765
|
});
|
|
16728
16766
|
}
|
|
16729
16767
|
}, [account, instance, isMFAPending]);
|
|
16730
16768
|
var login = React__default.useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
16731
|
-
var
|
|
16769
|
+
var err_1, redirectErr_1, camsError_1, camsError;
|
|
16732
16770
|
var _a, _b, _c;
|
|
16733
16771
|
return __generator(this, function (_d) {
|
|
16734
16772
|
switch (_d.label) {
|
|
@@ -16736,52 +16774,40 @@ function useCAMSMSALAuth(options) {
|
|
|
16736
16774
|
setError(null);
|
|
16737
16775
|
_d.label = 1;
|
|
16738
16776
|
case 1:
|
|
16739
|
-
_d.trys.push([1,
|
|
16777
|
+
_d.trys.push([1, 3, , 8]);
|
|
16740
16778
|
return [4 /*yield*/, instance.loginPopup({
|
|
16741
16779
|
scopes: scopes,
|
|
16742
16780
|
prompt: options.prompt || "select_account",
|
|
16743
16781
|
})];
|
|
16744
16782
|
case 2:
|
|
16745
|
-
|
|
16746
|
-
|
|
16747
|
-
return [4 /*yield*/, instance.acquireTokenPopup({
|
|
16748
|
-
scopes: scopes,
|
|
16749
|
-
account: loginResponse.account,
|
|
16750
|
-
})];
|
|
16783
|
+
_d.sent();
|
|
16784
|
+
return [3 /*break*/, 8];
|
|
16751
16785
|
case 3:
|
|
16752
|
-
|
|
16753
|
-
if (
|
|
16754
|
-
|
|
16755
|
-
(_a = options.onMFARequired) === null || _a === void 0 ? void 0 : _a.call(options, tokenResponse.accessToken, loginResponse.account);
|
|
16756
|
-
}
|
|
16757
|
-
else {
|
|
16758
|
-
setToken(tokenResponse.accessToken);
|
|
16759
|
-
setProfile({
|
|
16760
|
-
type: "AUTH_SUCCESS",
|
|
16761
|
-
userProfile: {
|
|
16762
|
-
name: loginResponse.account.name || "",
|
|
16763
|
-
email: loginResponse.account.username || "",
|
|
16764
|
-
isAuthenticated: true,
|
|
16765
|
-
mfaIsEnabled: true,
|
|
16766
|
-
message: "Authentication successful",
|
|
16767
|
-
userType: "USER",
|
|
16768
|
-
tokens: {
|
|
16769
|
-
Nonce: "",
|
|
16770
|
-
Bearer: tokenResponse.accessToken,
|
|
16771
|
-
},
|
|
16772
|
-
},
|
|
16773
|
-
});
|
|
16774
|
-
(_b = options.onAuthSuccess) === null || _b === void 0 ? void 0 : _b.call(options, tokenResponse.accessToken);
|
|
16775
|
-
}
|
|
16786
|
+
err_1 = _d.sent();
|
|
16787
|
+
if (!(err_1.errorCode === "popup_window_error" ||
|
|
16788
|
+
((_a = err_1.message) === null || _a === void 0 ? void 0 : _a.includes("popup")))) return [3 /*break*/, 7];
|
|
16776
16789
|
_d.label = 4;
|
|
16777
|
-
case 4:
|
|
16790
|
+
case 4:
|
|
16791
|
+
_d.trys.push([4, 6, , 7]);
|
|
16792
|
+
return [4 /*yield*/, instance.loginRedirect({
|
|
16793
|
+
scopes: scopes,
|
|
16794
|
+
prompt: options.prompt || "select_account",
|
|
16795
|
+
})];
|
|
16778
16796
|
case 5:
|
|
16779
|
-
|
|
16797
|
+
_d.sent();
|
|
16798
|
+
return [2 /*return*/];
|
|
16799
|
+
case 6:
|
|
16800
|
+
redirectErr_1 = _d.sent();
|
|
16801
|
+
camsError_1 = new camsSdk.CAMSError(camsSdk.CAMSErrorType.POPUP_BLOCKED, "Both popup and redirect failed: " + redirectErr_1);
|
|
16802
|
+
setError(camsError_1);
|
|
16803
|
+
(_b = options.onAuthError) === null || _b === void 0 ? void 0 : _b.call(options, camsError_1);
|
|
16804
|
+
return [2 /*return*/];
|
|
16805
|
+
case 7:
|
|
16780
16806
|
camsError = new camsSdk.CAMSError(camsSdk.CAMSErrorType.API_VALIDATION_ERROR, "Login failed: " + err_1);
|
|
16781
16807
|
setError(camsError);
|
|
16782
16808
|
(_c = options.onAuthError) === null || _c === void 0 ? void 0 : _c.call(options, camsError);
|
|
16783
|
-
return [3 /*break*/,
|
|
16784
|
-
case
|
|
16809
|
+
return [3 /*break*/, 8];
|
|
16810
|
+
case 8: return [2 /*return*/];
|
|
16785
16811
|
}
|
|
16786
16812
|
});
|
|
16787
16813
|
}); }, [instance, scopes, options]);
|