@nibssplc/cams-sdk-react 0.0.1-beta.21 → 0.0.1-beta.22
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 +55 -48
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +55 -48
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -16701,68 +16701,75 @@ 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
|
+
.acquireTokenPopup({
|
|
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
|
|
16713
|
-
var _a
|
|
16714
|
-
return __generator(this, function (
|
|
16715
|
-
switch (
|
|
16750
|
+
var err_1, camsError;
|
|
16751
|
+
var _a;
|
|
16752
|
+
return __generator(this, function (_b) {
|
|
16753
|
+
switch (_b.label) {
|
|
16716
16754
|
case 0:
|
|
16717
16755
|
setError(null);
|
|
16718
|
-
|
|
16756
|
+
_b.label = 1;
|
|
16719
16757
|
case 1:
|
|
16720
|
-
|
|
16721
|
-
return [4 /*yield*/, instance.
|
|
16758
|
+
_b.trys.push([1, 3, , 4]);
|
|
16759
|
+
return [4 /*yield*/, instance.loginRedirect({
|
|
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
|
+
_b.sent();
|
|
16765
|
+
return [3 /*break*/, 4];
|
|
16732
16766
|
case 3:
|
|
16733
|
-
|
|
16734
|
-
if (options.mfaUrl) {
|
|
16735
|
-
setIsMFAPending(true);
|
|
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
|
-
}
|
|
16757
|
-
_d.label = 4;
|
|
16758
|
-
case 4: return [3 /*break*/, 6];
|
|
16759
|
-
case 5:
|
|
16760
|
-
err_1 = _d.sent();
|
|
16767
|
+
err_1 = _b.sent();
|
|
16761
16768
|
camsError = new CAMSError(CAMSErrorType.API_VALIDATION_ERROR, "Login failed: " + err_1);
|
|
16762
16769
|
setError(camsError);
|
|
16763
|
-
(
|
|
16764
|
-
return [3 /*break*/,
|
|
16765
|
-
case
|
|
16770
|
+
(_a = options.onAuthError) === null || _a === void 0 ? void 0 : _a.call(options, camsError);
|
|
16771
|
+
return [3 /*break*/, 4];
|
|
16772
|
+
case 4: return [2 /*return*/];
|
|
16766
16773
|
}
|
|
16767
16774
|
});
|
|
16768
16775
|
}); }, [instance, scopes, options]);
|