@nibssplc/cams-sdk-react 0.0.1-beta.19 → 0.0.1-beta.21
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 +1 -0
- package/dist/index.cjs.js +50 -56
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +50 -56
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -16701,77 +16701,71 @@ 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 && !isMFAPending) {
|
|
16705
|
-
|
|
16706
|
-
|
|
16707
|
-
.
|
|
16708
|
-
scopes: scopes,
|
|
16709
|
-
account: account,
|
|
16710
|
-
})
|
|
16711
|
-
.then(function (response) {
|
|
16712
|
-
var _a, _b;
|
|
16713
|
-
if (options.mfaUrl) {
|
|
16714
|
-
// Redirect to MFA page
|
|
16715
|
-
setIsMFAPending(true);
|
|
16716
|
-
(_a = options.onMFARequired) === null || _a === void 0 ? void 0 : _a.call(options, response.accessToken, account);
|
|
16717
|
-
window.location.href = "".concat(options.mfaUrl, "?token=").concat(encodeURIComponent(response.accessToken));
|
|
16718
|
-
}
|
|
16719
|
-
else {
|
|
16720
|
-
// Complete auth without MFA
|
|
16721
|
-
setToken(response.accessToken);
|
|
16722
|
-
setProfile({
|
|
16723
|
-
type: "AUTH_SUCCESS",
|
|
16724
|
-
userProfile: {
|
|
16725
|
-
name: account.name || "",
|
|
16726
|
-
email: account.username || "",
|
|
16727
|
-
isAuthenticated: true,
|
|
16728
|
-
mfaIsEnabled: true,
|
|
16729
|
-
message: "Authentication successful",
|
|
16730
|
-
userType: "USER",
|
|
16731
|
-
tokens: {
|
|
16732
|
-
Nonce: "",
|
|
16733
|
-
Bearer: response.accessToken,
|
|
16734
|
-
},
|
|
16735
|
-
},
|
|
16736
|
-
});
|
|
16737
|
-
(_b = options.onAuthSuccess) === null || _b === void 0 ? void 0 : _b.call(options, response.accessToken);
|
|
16738
|
-
}
|
|
16739
|
-
})
|
|
16740
|
-
.catch(function (err) {
|
|
16741
|
-
var _a;
|
|
16742
|
-
var camsError = new CAMSError(CAMSErrorType.API_VALIDATION_ERROR, "Failed to acquire token silently: " + err);
|
|
16743
|
-
setError(camsError);
|
|
16744
|
-
(_a = options.onAuthError) === null || _a === void 0 ? void 0 : _a.call(options, camsError);
|
|
16704
|
+
if (account && !token && !isMFAPending) {
|
|
16705
|
+
login().catch(function (err) {
|
|
16706
|
+
// Error is already handled in login function
|
|
16707
|
+
console.error("Failed to automatically log in on mount:", err);
|
|
16745
16708
|
});
|
|
16746
16709
|
}
|
|
16747
16710
|
}, [account, instance, isMFAPending]);
|
|
16748
16711
|
var login = useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
16749
|
-
var err_1, camsError;
|
|
16750
|
-
var _a;
|
|
16751
|
-
return __generator(this, function (
|
|
16752
|
-
switch (
|
|
16712
|
+
var loginResponse, tokenResponse, err_1, camsError;
|
|
16713
|
+
var _a, _b, _c;
|
|
16714
|
+
return __generator(this, function (_d) {
|
|
16715
|
+
switch (_d.label) {
|
|
16753
16716
|
case 0:
|
|
16754
16717
|
setError(null);
|
|
16755
|
-
|
|
16718
|
+
_d.label = 1;
|
|
16756
16719
|
case 1:
|
|
16757
|
-
|
|
16758
|
-
return [4 /*yield*/, instance.
|
|
16720
|
+
_d.trys.push([1, 5, , 6]);
|
|
16721
|
+
return [4 /*yield*/, instance.loginPopup({
|
|
16759
16722
|
scopes: scopes,
|
|
16760
|
-
prompt: "select_account",
|
|
16723
|
+
prompt: options.prompt || "select_account",
|
|
16761
16724
|
})];
|
|
16762
16725
|
case 2:
|
|
16763
|
-
|
|
16764
|
-
return [3 /*break*/, 4];
|
|
16726
|
+
loginResponse = _d.sent();
|
|
16727
|
+
if (!loginResponse.account) return [3 /*break*/, 4];
|
|
16728
|
+
return [4 /*yield*/, instance.acquireTokenPopup({
|
|
16729
|
+
scopes: scopes,
|
|
16730
|
+
account: loginResponse.account,
|
|
16731
|
+
})];
|
|
16765
16732
|
case 3:
|
|
16766
|
-
|
|
16733
|
+
tokenResponse = _d.sent();
|
|
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
16761
|
camsError = new CAMSError(CAMSErrorType.API_VALIDATION_ERROR, "Login failed: " + err_1);
|
|
16768
16762
|
setError(camsError);
|
|
16769
|
-
(
|
|
16770
|
-
return [3 /*break*/,
|
|
16771
|
-
case
|
|
16763
|
+
(_c = options.onAuthError) === null || _c === void 0 ? void 0 : _c.call(options, camsError);
|
|
16764
|
+
return [3 /*break*/, 6];
|
|
16765
|
+
case 6: return [2 /*return*/];
|
|
16772
16766
|
}
|
|
16773
16767
|
});
|
|
16774
|
-
}); }, [instance, scopes]);
|
|
16768
|
+
}); }, [instance, scopes, options]);
|
|
16775
16769
|
var logout = useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
16776
16770
|
var err_2, camsError;
|
|
16777
16771
|
return __generator(this, function (_a) {
|