@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.esm.js
CHANGED
|
@@ -16701,15 +16701,53 @@ function useCAMSMSALAuth(options) {
|
|
|
16701
16701
|
var isAuthenticated = !!account && !!token && !isMFAPending;
|
|
16702
16702
|
var scopes = options.scopes || ["openid", "profile", "email"];
|
|
16703
16703
|
useEffect(function () {
|
|
16704
|
-
if (account && !
|
|
16705
|
-
|
|
16706
|
-
|
|
16707
|
-
|
|
16704
|
+
if (account && !isMFAPending) {
|
|
16705
|
+
// Get token in foreground popup
|
|
16706
|
+
instance
|
|
16707
|
+
.acquireTokenSilent({
|
|
16708
|
+
scopes: scopes,
|
|
16709
|
+
account: account,
|
|
16710
|
+
prompt: options.prompt || "select_account",
|
|
16711
|
+
})
|
|
16712
|
+
.then(function (response) {
|
|
16713
|
+
var _a, _b;
|
|
16714
|
+
if (options.mfaUrl) {
|
|
16715
|
+
setIsMFAPending(true);
|
|
16716
|
+
(_a = options.onMFARequired) === null || _a === void 0 ? void 0 : _a.call(options, response.accessToken, account);
|
|
16717
|
+
if (typeof window !== "undefined") {
|
|
16718
|
+
window.location.href = options.mfaUrl;
|
|
16719
|
+
}
|
|
16720
|
+
}
|
|
16721
|
+
else {
|
|
16722
|
+
setToken(response.accessToken);
|
|
16723
|
+
setProfile({
|
|
16724
|
+
type: "AUTH_SUCCESS",
|
|
16725
|
+
userProfile: {
|
|
16726
|
+
name: account.name || "",
|
|
16727
|
+
email: account.username || "",
|
|
16728
|
+
isAuthenticated: true,
|
|
16729
|
+
mfaIsEnabled: true,
|
|
16730
|
+
message: "Authentication successful",
|
|
16731
|
+
userType: "USER",
|
|
16732
|
+
tokens: {
|
|
16733
|
+
Nonce: "",
|
|
16734
|
+
Bearer: response.accessToken,
|
|
16735
|
+
},
|
|
16736
|
+
},
|
|
16737
|
+
});
|
|
16738
|
+
(_b = options.onAuthSuccess) === null || _b === void 0 ? void 0 : _b.call(options, response.accessToken);
|
|
16739
|
+
}
|
|
16740
|
+
})
|
|
16741
|
+
.catch(function (err) {
|
|
16742
|
+
var _a;
|
|
16743
|
+
var camsError = new CAMSError(CAMSErrorType.API_VALIDATION_ERROR, "Failed to acquire token: " + err);
|
|
16744
|
+
setError(camsError);
|
|
16745
|
+
(_a = options.onAuthError) === null || _a === void 0 ? void 0 : _a.call(options, camsError);
|
|
16708
16746
|
});
|
|
16709
16747
|
}
|
|
16710
16748
|
}, [account, instance, isMFAPending]);
|
|
16711
16749
|
var login = useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
16712
|
-
var
|
|
16750
|
+
var err_1, redirectErr_1, camsError_1, camsError;
|
|
16713
16751
|
var _a, _b, _c;
|
|
16714
16752
|
return __generator(this, function (_d) {
|
|
16715
16753
|
switch (_d.label) {
|
|
@@ -16717,52 +16755,40 @@ function useCAMSMSALAuth(options) {
|
|
|
16717
16755
|
setError(null);
|
|
16718
16756
|
_d.label = 1;
|
|
16719
16757
|
case 1:
|
|
16720
|
-
_d.trys.push([1,
|
|
16758
|
+
_d.trys.push([1, 3, , 8]);
|
|
16721
16759
|
return [4 /*yield*/, instance.loginPopup({
|
|
16722
16760
|
scopes: scopes,
|
|
16723
16761
|
prompt: options.prompt || "select_account",
|
|
16724
16762
|
})];
|
|
16725
16763
|
case 2:
|
|
16726
|
-
|
|
16727
|
-
|
|
16728
|
-
return [4 /*yield*/, instance.acquireTokenPopup({
|
|
16729
|
-
scopes: scopes,
|
|
16730
|
-
account: loginResponse.account,
|
|
16731
|
-
})];
|
|
16764
|
+
_d.sent();
|
|
16765
|
+
return [3 /*break*/, 8];
|
|
16732
16766
|
case 3:
|
|
16733
|
-
|
|
16734
|
-
if (
|
|
16735
|
-
|
|
16736
|
-
(_a = options.onMFARequired) === null || _a === void 0 ? void 0 : _a.call(options, tokenResponse.accessToken, loginResponse.account);
|
|
16737
|
-
}
|
|
16738
|
-
else {
|
|
16739
|
-
setToken(tokenResponse.accessToken);
|
|
16740
|
-
setProfile({
|
|
16741
|
-
type: "AUTH_SUCCESS",
|
|
16742
|
-
userProfile: {
|
|
16743
|
-
name: loginResponse.account.name || "",
|
|
16744
|
-
email: loginResponse.account.username || "",
|
|
16745
|
-
isAuthenticated: true,
|
|
16746
|
-
mfaIsEnabled: true,
|
|
16747
|
-
message: "Authentication successful",
|
|
16748
|
-
userType: "USER",
|
|
16749
|
-
tokens: {
|
|
16750
|
-
Nonce: "",
|
|
16751
|
-
Bearer: tokenResponse.accessToken,
|
|
16752
|
-
},
|
|
16753
|
-
},
|
|
16754
|
-
});
|
|
16755
|
-
(_b = options.onAuthSuccess) === null || _b === void 0 ? void 0 : _b.call(options, tokenResponse.accessToken);
|
|
16756
|
-
}
|
|
16767
|
+
err_1 = _d.sent();
|
|
16768
|
+
if (!(err_1.errorCode === "popup_window_error" ||
|
|
16769
|
+
((_a = err_1.message) === null || _a === void 0 ? void 0 : _a.includes("popup")))) return [3 /*break*/, 7];
|
|
16757
16770
|
_d.label = 4;
|
|
16758
|
-
case 4:
|
|
16771
|
+
case 4:
|
|
16772
|
+
_d.trys.push([4, 6, , 7]);
|
|
16773
|
+
return [4 /*yield*/, instance.loginRedirect({
|
|
16774
|
+
scopes: scopes,
|
|
16775
|
+
prompt: options.prompt || "select_account",
|
|
16776
|
+
})];
|
|
16759
16777
|
case 5:
|
|
16760
|
-
|
|
16778
|
+
_d.sent();
|
|
16779
|
+
return [2 /*return*/];
|
|
16780
|
+
case 6:
|
|
16781
|
+
redirectErr_1 = _d.sent();
|
|
16782
|
+
camsError_1 = new CAMSError(CAMSErrorType.POPUP_BLOCKED, "Both popup and redirect failed: " + redirectErr_1);
|
|
16783
|
+
setError(camsError_1);
|
|
16784
|
+
(_b = options.onAuthError) === null || _b === void 0 ? void 0 : _b.call(options, camsError_1);
|
|
16785
|
+
return [2 /*return*/];
|
|
16786
|
+
case 7:
|
|
16761
16787
|
camsError = new CAMSError(CAMSErrorType.API_VALIDATION_ERROR, "Login failed: " + err_1);
|
|
16762
16788
|
setError(camsError);
|
|
16763
16789
|
(_c = options.onAuthError) === null || _c === void 0 ? void 0 : _c.call(options, camsError);
|
|
16764
|
-
return [3 /*break*/,
|
|
16765
|
-
case
|
|
16790
|
+
return [3 /*break*/, 8];
|
|
16791
|
+
case 8: return [2 /*return*/];
|
|
16766
16792
|
}
|
|
16767
16793
|
});
|
|
16768
16794
|
}); }, [instance, scopes, options]);
|