@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.cjs.js
CHANGED
|
@@ -16720,68 +16720,75 @@ 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
|
+
.acquireTokenPopup({
|
|
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
|
|
16732
|
-
var _a
|
|
16733
|
-
return __generator(this, function (
|
|
16734
|
-
switch (
|
|
16769
|
+
var err_1, camsError;
|
|
16770
|
+
var _a;
|
|
16771
|
+
return __generator(this, function (_b) {
|
|
16772
|
+
switch (_b.label) {
|
|
16735
16773
|
case 0:
|
|
16736
16774
|
setError(null);
|
|
16737
|
-
|
|
16775
|
+
_b.label = 1;
|
|
16738
16776
|
case 1:
|
|
16739
|
-
|
|
16740
|
-
return [4 /*yield*/, instance.
|
|
16777
|
+
_b.trys.push([1, 3, , 4]);
|
|
16778
|
+
return [4 /*yield*/, instance.loginRedirect({
|
|
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
|
+
_b.sent();
|
|
16784
|
+
return [3 /*break*/, 4];
|
|
16751
16785
|
case 3:
|
|
16752
|
-
|
|
16753
|
-
if (options.mfaUrl) {
|
|
16754
|
-
setIsMFAPending(true);
|
|
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
|
-
}
|
|
16776
|
-
_d.label = 4;
|
|
16777
|
-
case 4: return [3 /*break*/, 6];
|
|
16778
|
-
case 5:
|
|
16779
|
-
err_1 = _d.sent();
|
|
16786
|
+
err_1 = _b.sent();
|
|
16780
16787
|
camsError = new camsSdk.CAMSError(camsSdk.CAMSErrorType.API_VALIDATION_ERROR, "Login failed: " + err_1);
|
|
16781
16788
|
setError(camsError);
|
|
16782
|
-
(
|
|
16783
|
-
return [3 /*break*/,
|
|
16784
|
-
case
|
|
16789
|
+
(_a = options.onAuthError) === null || _a === void 0 ? void 0 : _a.call(options, camsError);
|
|
16790
|
+
return [3 /*break*/, 4];
|
|
16791
|
+
case 4: return [2 /*return*/];
|
|
16785
16792
|
}
|
|
16786
16793
|
});
|
|
16787
16794
|
}); }, [instance, scopes, options]);
|