acsi-core 0.9.20 → 0.9.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/components/MSALRedirectHandler/index.d.ts +14 -0
- package/dist/components/UpdateNotifier.d.ts +3 -0
- package/dist/components/index.d.ts +1 -0
- package/dist/configs/api.d.ts +3 -0
- package/dist/configs/api_removed.d.ts +3 -0
- package/dist/containers/Login/configs/constants.d.ts +1 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +362 -144
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +358 -147
- package/dist/index.modern.js.map +1 -1
- package/dist/utils/configLoader.d.ts +2 -0
- package/dist/utils/hooks/useServiceWorker.d.ts +1 -0
- package/dist/utils/msalInstance.d.ts +38 -0
- package/package.json +1 -1
- package/dist/utils/timeSpanToLocalMoment.d.ts +0 -3
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MSALRedirectHandler component
|
|
3
|
+
*
|
|
4
|
+
* This component handles MSAL redirect authentication flows by processing
|
|
5
|
+
* the hash fragment in the URL before any router code can clear it.
|
|
6
|
+
*
|
|
7
|
+
* Uses useLayoutEffect to run synchronously before browser paint,
|
|
8
|
+
* ensuring it processes the redirect before React Router initializes.
|
|
9
|
+
*
|
|
10
|
+
* This component uses the singleton MSAL instance to avoid conflicts
|
|
11
|
+
* and ensure consistent state management.
|
|
12
|
+
*/
|
|
13
|
+
declare const MSALRedirectHandler: () => null;
|
|
14
|
+
export default MSALRedirectHandler;
|
|
@@ -13,3 +13,4 @@ export { default as CoreInputCompact } from "./CoreInputCompact";
|
|
|
13
13
|
export { default as CoreTitleInput } from "./CoreTitleInput";
|
|
14
14
|
export { default as CoreTooltip } from "./CoreTooltip";
|
|
15
15
|
export { default as MarkdownLatexRender } from "./MarkdownLatexRender";
|
|
16
|
+
export { default as MSALRedirectHandler } from "./MSALRedirectHandler";
|
package/dist/index.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ import useAmplitude from "./utils/hooks/useAmplitude";
|
|
|
20
20
|
import { AmplitudeEvent } from "./utils/types/amplitude";
|
|
21
21
|
import initializeAmplitude from "./configs/amplitude";
|
|
22
22
|
import { initSentry } from "./configs/sentry";
|
|
23
|
-
import { CoreButton, CoreInput, CoreSelect, CoreCheckbox, CoreRadio, CoreError, CoreModal, CoreRange, CoreTextArea, CoreSearch, CoreSelectCompact, CoreInputCompact, CoreTitleInput, CoreTooltip, MarkdownLatexRender } from "./components";
|
|
23
|
+
import { CoreButton, CoreInput, CoreSelect, CoreCheckbox, CoreRadio, CoreError, CoreModal, CoreRange, CoreTextArea, CoreSearch, CoreSelectCompact, CoreInputCompact, CoreTitleInput, CoreTooltip, MarkdownLatexRender, MSALRedirectHandler } from "./components";
|
|
24
24
|
import { getErrorMessage } from "./utils/getErrorMessage";
|
|
25
25
|
import { GoogleOAuthProvider } from '@react-oauth/google';
|
|
26
26
|
import CustomSelect from "./components/Selects/CustomSelect";
|
|
@@ -29,4 +29,5 @@ import CustomCreatable from "./components/Selects/CustomCreatable";
|
|
|
29
29
|
import CustomSelectOption from "./components/Selects/CustomSelectOption";
|
|
30
30
|
import utcToLocalTime from "./utils/utcToLocalTime";
|
|
31
31
|
import Cookies from "js-cookie";
|
|
32
|
-
|
|
32
|
+
import { getMSALInstance, initializeMSAL, handleMSALRedirect, isMSALRedirect, getAllAccounts, getActiveAccount } from "./utils/msalInstance";
|
|
33
|
+
export { setLoading, setLoadingPage, BASE_URL, OPENSALT_BASE_URL, ACCESS_TOKEN, DATE_TIME_MIN_VALUE, ORGANIZATION_TEAM, ORGANIZATION_TENANT, firstCheckToken, getImageUrl, Login, utcToLocalTime, getAccessToken, store, historyCore, setAlert, setUser, setTenant, setAddTenant, setTeam, setMenuCollapse, setIsRefetchSidebar, Loading, NotFound, LayoutContext, api, apiUpload, ConfirmDialog, CommonDialog, ToastContainer, toast, Role, Cookies, CustomPagination, useGoogleSignOut, CoreButton, CoreInput, CoreSelect, CoreCheckbox, CoreRadio, CoreError, CoreModal, CoreRange, CoreTextArea, CoreSearch, CoreSelectCompact, CoreInputCompact, CoreTitleInput, CoreTooltip, getErrorMessage, MarkdownLatexRender, MSALRedirectHandler, CustomSelect, CustomAsyncSelect, CustomCreatable, CustomSelectOption, GoogleOAuthProvider, useAmplitude, AmplitudeEvent, initializeAmplitude, initSentry, getMSALInstance, initializeMSAL, handleMSALRedirect, isMSALRedirect, getAllAccounts, getActiveAccount };
|
package/dist/index.js
CHANGED
|
@@ -17,9 +17,9 @@ var rehypeKatex = _interopDefault(require('rehype-katex'));
|
|
|
17
17
|
var remarkRehype = _interopDefault(require('remark-rehype'));
|
|
18
18
|
var rehypeRaw = _interopDefault(require('rehype-raw'));
|
|
19
19
|
require('katex/dist/katex.min.css');
|
|
20
|
+
var msalBrowser = require('@azure/msal-browser');
|
|
20
21
|
var Cookies = _interopDefault(require('js-cookie'));
|
|
21
22
|
var moment = _interopDefault(require('moment'));
|
|
22
|
-
var msalBrowser = require('@azure/msal-browser');
|
|
23
23
|
var reactToastify = require('react-toastify');
|
|
24
24
|
var reactGoogleLogin = require('@leecheuk/react-google-login');
|
|
25
25
|
var material = require('@mui/material');
|
|
@@ -672,6 +672,25 @@ var ORGANIZATION_TEAM = "ORGANIZATION_TEAM";
|
|
|
672
672
|
|
|
673
673
|
var styleGlobal = {"signup_wrap":"_1KLz9","box-signin":"_2Jo1o","signin_title":"_3egBO","signup_link":"_1DoIT","google_button":"_34hK_","microsoft_button":"_19ESb","box-field":"_2e9xO","box-input":"_3zXRp","box-text":"_8NJga","box-button-email":"_21FPk","box-signin-container":"_1QERu","box-signin-text":"_2-znH","box-signin-logo":"_1aB2m","box-right":"_3qndF","image-slideshow":"_1aM7m","active":"_Vx1zf","box-right-body":"_JzdCr","box-right-footer":"_19aCA","pr-30":"_2HB5r","width-400":"_4ehXP"};
|
|
674
674
|
|
|
675
|
+
// A type of promise-like that resolves synchronously and supports only one observer
|
|
676
|
+
|
|
677
|
+
const _iteratorSymbol = /*#__PURE__*/ typeof Symbol !== "undefined" ? (Symbol.iterator || (Symbol.iterator = Symbol("Symbol.iterator"))) : "@@iterator";
|
|
678
|
+
|
|
679
|
+
const _asyncIteratorSymbol = /*#__PURE__*/ typeof Symbol !== "undefined" ? (Symbol.asyncIterator || (Symbol.asyncIterator = Symbol("Symbol.asyncIterator"))) : "@@asyncIterator";
|
|
680
|
+
|
|
681
|
+
// Asynchronously call a function and send errors to recovery continuation
|
|
682
|
+
function _catch(body, recover) {
|
|
683
|
+
try {
|
|
684
|
+
var result = body();
|
|
685
|
+
} catch(e) {
|
|
686
|
+
return recover(e);
|
|
687
|
+
}
|
|
688
|
+
if (result && result.then) {
|
|
689
|
+
return result.then(void 0, recover);
|
|
690
|
+
}
|
|
691
|
+
return result;
|
|
692
|
+
}
|
|
693
|
+
|
|
675
694
|
function _arrayLikeToArray(r, a) {
|
|
676
695
|
(null == a || a > r.length) && (a = r.length);
|
|
677
696
|
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
|
|
@@ -720,25 +739,6 @@ function _unsupportedIterableToArray(r, a) {
|
|
|
720
739
|
}
|
|
721
740
|
}
|
|
722
741
|
|
|
723
|
-
// A type of promise-like that resolves synchronously and supports only one observer
|
|
724
|
-
|
|
725
|
-
const _iteratorSymbol = /*#__PURE__*/ typeof Symbol !== "undefined" ? (Symbol.iterator || (Symbol.iterator = Symbol("Symbol.iterator"))) : "@@iterator";
|
|
726
|
-
|
|
727
|
-
const _asyncIteratorSymbol = /*#__PURE__*/ typeof Symbol !== "undefined" ? (Symbol.asyncIterator || (Symbol.asyncIterator = Symbol("Symbol.asyncIterator"))) : "@@asyncIterator";
|
|
728
|
-
|
|
729
|
-
// Asynchronously call a function and send errors to recovery continuation
|
|
730
|
-
function _catch(body, recover) {
|
|
731
|
-
try {
|
|
732
|
-
var result = body();
|
|
733
|
-
} catch(e) {
|
|
734
|
-
return recover(e);
|
|
735
|
-
}
|
|
736
|
-
if (result && result.then) {
|
|
737
|
-
return result.then(void 0, recover);
|
|
738
|
-
}
|
|
739
|
-
return result;
|
|
740
|
-
}
|
|
741
|
-
|
|
742
742
|
var styles = {"core-button":"_xvNBN","primary":"_U9Qyp","secondary":"_1VzMy","text":"_pZNuj","danger":"_2uYm1","light":"_wxH5S"};
|
|
743
743
|
|
|
744
744
|
var _excluded = ["type", "children", "onClick", "icon", "disabled", "htmlType"];
|
|
@@ -2170,6 +2170,214 @@ function formatContent(content) {
|
|
|
2170
2170
|
return result.join("\n");
|
|
2171
2171
|
}
|
|
2172
2172
|
|
|
2173
|
+
var AuthenticationMessage;
|
|
2174
|
+
(function (AuthenticationMessage) {
|
|
2175
|
+
AuthenticationMessage["NotAllowedToRegister"] = "NotAllowedToRegister";
|
|
2176
|
+
AuthenticationMessage["InvalidGoogleToken"] = "InvalidGoogleToken";
|
|
2177
|
+
})(AuthenticationMessage || (AuthenticationMessage = {}));
|
|
2178
|
+
(function (Role) {
|
|
2179
|
+
Role["Student"] = "Student";
|
|
2180
|
+
Role["Teacher"] = "Teacher";
|
|
2181
|
+
Role["Admin"] = "Admin";
|
|
2182
|
+
})(exports.Role || (exports.Role = {}));
|
|
2183
|
+
var msalConfig = function msalConfig(clientId, redirectUri) {
|
|
2184
|
+
return {
|
|
2185
|
+
auth: {
|
|
2186
|
+
clientId: clientId,
|
|
2187
|
+
authority: "https://login.microsoftonline.com/common",
|
|
2188
|
+
redirectUri: redirectUri,
|
|
2189
|
+
navigateToLoginRequestUrl: false
|
|
2190
|
+
},
|
|
2191
|
+
cache: {
|
|
2192
|
+
cacheLocation: "sessionStorage",
|
|
2193
|
+
storeAuthStateInCookie: false
|
|
2194
|
+
},
|
|
2195
|
+
system: {
|
|
2196
|
+
loggerOptions: {
|
|
2197
|
+
loggerCallback: function loggerCallback(level, message, containsPii) {
|
|
2198
|
+
if (containsPii) {
|
|
2199
|
+
return;
|
|
2200
|
+
}
|
|
2201
|
+
var prefix = '[MSAL]';
|
|
2202
|
+
switch (level) {
|
|
2203
|
+
case msalBrowser.LogLevel.Error:
|
|
2204
|
+
console.error(prefix + " " + message);
|
|
2205
|
+
return;
|
|
2206
|
+
case msalBrowser.LogLevel.Info:
|
|
2207
|
+
console.info(prefix + " " + message);
|
|
2208
|
+
return;
|
|
2209
|
+
case msalBrowser.LogLevel.Verbose:
|
|
2210
|
+
console.debug(prefix + " " + message);
|
|
2211
|
+
return;
|
|
2212
|
+
case msalBrowser.LogLevel.Warning:
|
|
2213
|
+
console.warn(prefix + " " + message);
|
|
2214
|
+
return;
|
|
2215
|
+
default:
|
|
2216
|
+
return;
|
|
2217
|
+
}
|
|
2218
|
+
}
|
|
2219
|
+
}
|
|
2220
|
+
}
|
|
2221
|
+
};
|
|
2222
|
+
};
|
|
2223
|
+
|
|
2224
|
+
var msalInstance = null;
|
|
2225
|
+
var isInitializing = false;
|
|
2226
|
+
var initPromise = null;
|
|
2227
|
+
var getMSALInstance = function getMSALInstance(clientId, redirectUri) {
|
|
2228
|
+
var finalClientId = clientId || MICROSOFT_CLIENT_ID;
|
|
2229
|
+
var finalRedirectUri = redirectUri || MICROSOFT_URL_DIRECT || window.location.origin;
|
|
2230
|
+
if (!finalClientId) {
|
|
2231
|
+
console.warn('[MSAL] Client ID not configured');
|
|
2232
|
+
return null;
|
|
2233
|
+
}
|
|
2234
|
+
if (!msalInstance) {
|
|
2235
|
+
msalInstance = new msalBrowser.PublicClientApplication(msalConfig(finalClientId, finalRedirectUri));
|
|
2236
|
+
}
|
|
2237
|
+
return msalInstance;
|
|
2238
|
+
};
|
|
2239
|
+
var initializeMSAL = function initializeMSAL(clientId, redirectUri) {
|
|
2240
|
+
try {
|
|
2241
|
+
var instance = getMSALInstance(clientId, redirectUri);
|
|
2242
|
+
if (!instance) {
|
|
2243
|
+
return Promise.resolve(null);
|
|
2244
|
+
}
|
|
2245
|
+
if (isInitializing && initPromise) {
|
|
2246
|
+
return Promise.resolve(initPromise.then(function () {
|
|
2247
|
+
return instance;
|
|
2248
|
+
}));
|
|
2249
|
+
}
|
|
2250
|
+
if (isInitializing) {
|
|
2251
|
+
return Promise.resolve(instance);
|
|
2252
|
+
}
|
|
2253
|
+
isInitializing = true;
|
|
2254
|
+
initPromise = instance.initialize().then(function () {
|
|
2255
|
+
isInitializing = false;
|
|
2256
|
+
return instance;
|
|
2257
|
+
})["catch"](function (error) {
|
|
2258
|
+
isInitializing = false;
|
|
2259
|
+
console.error('[MSAL] Initialization error:', error);
|
|
2260
|
+
throw error;
|
|
2261
|
+
});
|
|
2262
|
+
return Promise.resolve(initPromise);
|
|
2263
|
+
} catch (e) {
|
|
2264
|
+
return Promise.reject(e);
|
|
2265
|
+
}
|
|
2266
|
+
};
|
|
2267
|
+
var handleMSALRedirect = function handleMSALRedirect(clientId, redirectUri) {
|
|
2268
|
+
try {
|
|
2269
|
+
if (!window.location.hash) {
|
|
2270
|
+
return Promise.resolve(null);
|
|
2271
|
+
}
|
|
2272
|
+
var hashParams = new URLSearchParams(window.location.hash.substring(1));
|
|
2273
|
+
var hasMSALParams = hashParams.has('access_token') || hashParams.has('id_token') || hashParams.has('error') || hashParams.has('code');
|
|
2274
|
+
if (!hasMSALParams) {
|
|
2275
|
+
return Promise.resolve(null);
|
|
2276
|
+
}
|
|
2277
|
+
return Promise.resolve(_catch(function () {
|
|
2278
|
+
return Promise.resolve(initializeMSAL(clientId, redirectUri)).then(function (instance) {
|
|
2279
|
+
return instance ? Promise.resolve(instance.handleRedirectPromise()) : null;
|
|
2280
|
+
});
|
|
2281
|
+
}, function (error) {
|
|
2282
|
+
console.error('[MSAL] Redirect handling error:', error);
|
|
2283
|
+
return null;
|
|
2284
|
+
}));
|
|
2285
|
+
} catch (e) {
|
|
2286
|
+
return Promise.reject(e);
|
|
2287
|
+
}
|
|
2288
|
+
};
|
|
2289
|
+
var isMSALRedirect = function isMSALRedirect() {
|
|
2290
|
+
if (!window.location.hash) {
|
|
2291
|
+
return false;
|
|
2292
|
+
}
|
|
2293
|
+
var hashParams = new URLSearchParams(window.location.hash.substring(1));
|
|
2294
|
+
return hashParams.has('access_token') || hashParams.has('id_token') || hashParams.has('error') || hashParams.has('code');
|
|
2295
|
+
};
|
|
2296
|
+
var getAllAccounts = function getAllAccounts() {
|
|
2297
|
+
var instance = getMSALInstance();
|
|
2298
|
+
if (!instance) {
|
|
2299
|
+
return [];
|
|
2300
|
+
}
|
|
2301
|
+
return instance.getAllAccounts();
|
|
2302
|
+
};
|
|
2303
|
+
var getActiveAccount = function getActiveAccount() {
|
|
2304
|
+
var instance = getMSALInstance();
|
|
2305
|
+
if (!instance) {
|
|
2306
|
+
return null;
|
|
2307
|
+
}
|
|
2308
|
+
return instance.getActiveAccount();
|
|
2309
|
+
};
|
|
2310
|
+
|
|
2311
|
+
var MSALRedirectHandler = function MSALRedirectHandler() {
|
|
2312
|
+
React.useLayoutEffect(function () {
|
|
2313
|
+
var handleRedirect = function handleRedirect() {
|
|
2314
|
+
try {
|
|
2315
|
+
if (!isMSALRedirect()) {
|
|
2316
|
+
return Promise.resolve();
|
|
2317
|
+
}
|
|
2318
|
+
console.log('[MSAL] Redirect detected, processing...');
|
|
2319
|
+
console.log('[MSAL] Hash:', window.location.hash);
|
|
2320
|
+
console.log('[MSAL] Full URL:', window.location.href);
|
|
2321
|
+
var _temp = _catch(function () {
|
|
2322
|
+
return Promise.resolve(handleMSALRedirect()).then(function (response) {
|
|
2323
|
+
if (response && response.account) {
|
|
2324
|
+
console.log('[MSAL] Redirect handled successfully', {
|
|
2325
|
+
account: response.account.username,
|
|
2326
|
+
scopes: response.scopes
|
|
2327
|
+
});
|
|
2328
|
+
if (window.history.replaceState) {
|
|
2329
|
+
window.history.replaceState(null, '', window.location.pathname + window.location.search);
|
|
2330
|
+
}
|
|
2331
|
+
localStorage.setItem('MSAL_ACCOUNT', JSON.stringify(response.account));
|
|
2332
|
+
localStorage.setItem('MSAL_ACCESS_TOKEN', response.accessToken || '');
|
|
2333
|
+
localStorage.setItem('MSAL_LOGIN_PENDING', 'true');
|
|
2334
|
+
window.dispatchEvent(new CustomEvent('msal-login-success', {
|
|
2335
|
+
detail: {
|
|
2336
|
+
account: response.account,
|
|
2337
|
+
accessToken: response.accessToken,
|
|
2338
|
+
idToken: response.idToken
|
|
2339
|
+
}
|
|
2340
|
+
}));
|
|
2341
|
+
if (window.location.pathname.includes('/login')) {
|
|
2342
|
+
window.location.reload();
|
|
2343
|
+
} else {
|
|
2344
|
+
window.location.href = '/dashboard';
|
|
2345
|
+
}
|
|
2346
|
+
} else {
|
|
2347
|
+
var hashParams = new URLSearchParams(window.location.hash.substring(1));
|
|
2348
|
+
var error = hashParams.get('error');
|
|
2349
|
+
var errorDescription = hashParams.get('error_description');
|
|
2350
|
+
if (error) {
|
|
2351
|
+
console.error('[MSAL] Authentication error:', error, errorDescription);
|
|
2352
|
+
if (error === 'access_denied') {
|
|
2353
|
+
console.error('[MSAL] User denied access or scopes not configured in Azure AD');
|
|
2354
|
+
}
|
|
2355
|
+
}
|
|
2356
|
+
if (window.history.replaceState) {
|
|
2357
|
+
window.history.replaceState(null, '', window.location.pathname + window.location.search);
|
|
2358
|
+
}
|
|
2359
|
+
}
|
|
2360
|
+
});
|
|
2361
|
+
}, function (error) {
|
|
2362
|
+
var _error$message;
|
|
2363
|
+
console.error('[MSAL] Redirect handling error:', error);
|
|
2364
|
+
if ((error === null || error === void 0 ? void 0 : error.errorCode) === 'hash_empty_error' || error !== null && error !== void 0 && (_error$message = error.message) !== null && _error$message !== void 0 && _error$message.includes('hash_empty')) {
|
|
2365
|
+
console.error('[MSAL] Hash was cleared before MSAL could process it. ' + 'This usually means code is running that clears the URL hash before MSAL handler executes.');
|
|
2366
|
+
}
|
|
2367
|
+
if (window.history.replaceState) {
|
|
2368
|
+
window.history.replaceState(null, '', window.location.pathname + window.location.search);
|
|
2369
|
+
}
|
|
2370
|
+
});
|
|
2371
|
+
return Promise.resolve(_temp && _temp.then ? _temp.then(function () {}) : void 0);
|
|
2372
|
+
} catch (e) {
|
|
2373
|
+
return Promise.reject(e);
|
|
2374
|
+
}
|
|
2375
|
+
};
|
|
2376
|
+
handleRedirect();
|
|
2377
|
+
}, []);
|
|
2378
|
+
return null;
|
|
2379
|
+
};
|
|
2380
|
+
|
|
2173
2381
|
var CookieService = /*#__PURE__*/function () {
|
|
2174
2382
|
function CookieService() {}
|
|
2175
2383
|
CookieService.setAuthCookie = function setAuthCookie(data) {
|
|
@@ -2322,55 +2530,6 @@ var TypeLogin;
|
|
|
2322
2530
|
TypeLogin[TypeLogin["Microsoft"] = 3] = "Microsoft";
|
|
2323
2531
|
})(TypeLogin || (TypeLogin = {}));
|
|
2324
2532
|
|
|
2325
|
-
var AuthenticationMessage;
|
|
2326
|
-
(function (AuthenticationMessage) {
|
|
2327
|
-
AuthenticationMessage["NotAllowedToRegister"] = "NotAllowedToRegister";
|
|
2328
|
-
AuthenticationMessage["InvalidGoogleToken"] = "InvalidGoogleToken";
|
|
2329
|
-
})(AuthenticationMessage || (AuthenticationMessage = {}));
|
|
2330
|
-
(function (Role) {
|
|
2331
|
-
Role["Student"] = "Student";
|
|
2332
|
-
Role["Teacher"] = "Teacher";
|
|
2333
|
-
Role["Admin"] = "Admin";
|
|
2334
|
-
})(exports.Role || (exports.Role = {}));
|
|
2335
|
-
var msalConfig = function msalConfig(clientId, redirectUri) {
|
|
2336
|
-
return {
|
|
2337
|
-
auth: {
|
|
2338
|
-
clientId: clientId,
|
|
2339
|
-
authority: "https://login.microsoftonline.com/common",
|
|
2340
|
-
redirectUri: redirectUri
|
|
2341
|
-
},
|
|
2342
|
-
cache: {
|
|
2343
|
-
cacheLocation: "sessionStorage",
|
|
2344
|
-
storeAuthStateInCookie: false
|
|
2345
|
-
},
|
|
2346
|
-
system: {
|
|
2347
|
-
loggerOptions: {
|
|
2348
|
-
loggerCallback: function loggerCallback(level, message, containsPii) {
|
|
2349
|
-
if (containsPii) {
|
|
2350
|
-
return;
|
|
2351
|
-
}
|
|
2352
|
-
switch (level) {
|
|
2353
|
-
case msalBrowser.LogLevel.Error:
|
|
2354
|
-
console.error(message);
|
|
2355
|
-
return;
|
|
2356
|
-
case msalBrowser.LogLevel.Info:
|
|
2357
|
-
console.info(message);
|
|
2358
|
-
return;
|
|
2359
|
-
case msalBrowser.LogLevel.Verbose:
|
|
2360
|
-
console.debug(message);
|
|
2361
|
-
return;
|
|
2362
|
-
case msalBrowser.LogLevel.Warning:
|
|
2363
|
-
console.warn(message);
|
|
2364
|
-
return;
|
|
2365
|
-
default:
|
|
2366
|
-
return;
|
|
2367
|
-
}
|
|
2368
|
-
}
|
|
2369
|
-
}
|
|
2370
|
-
}
|
|
2371
|
-
};
|
|
2372
|
-
};
|
|
2373
|
-
|
|
2374
2533
|
var BlockLogin = function BlockLogin(_ref) {
|
|
2375
2534
|
var onNavigate = _ref.onNavigate,
|
|
2376
2535
|
role = _ref.role,
|
|
@@ -2417,11 +2576,120 @@ var BlockLogin = function BlockLogin(_ref) {
|
|
|
2417
2576
|
return Promise.reject(e);
|
|
2418
2577
|
}
|
|
2419
2578
|
};
|
|
2579
|
+
var processMSALLogin = function processMSALLogin(account, accessToken) {
|
|
2580
|
+
try {
|
|
2581
|
+
return Promise.resolve(_catch(function () {
|
|
2582
|
+
dispatch(setLoading(true));
|
|
2583
|
+
var fullName = (account === null || account === void 0 ? void 0 : account.name) || "";
|
|
2584
|
+
var infoLogin = {
|
|
2585
|
+
firstName: fullName.split(' ').slice(0, -1).join(' '),
|
|
2586
|
+
lastName: fullName.split(' ').slice(-1).join(' '),
|
|
2587
|
+
fullName: fullName,
|
|
2588
|
+
imageUrl: "",
|
|
2589
|
+
email: (account === null || account === void 0 ? void 0 : account.username) || "",
|
|
2590
|
+
token: accessToken || "",
|
|
2591
|
+
googleId: (account === null || account === void 0 ? void 0 : account.homeAccountId) || "",
|
|
2592
|
+
role: role,
|
|
2593
|
+
type: TypeLogin.Microsoft
|
|
2594
|
+
};
|
|
2595
|
+
return Promise.resolve(apiLoginGoogle(infoLogin)).then(function (authResult) {
|
|
2596
|
+
var _authResult$data;
|
|
2597
|
+
if (((_authResult$data = authResult.data) === null || _authResult$data === void 0 ? void 0 : _authResult$data.id) == null) {
|
|
2598
|
+
dispatch(setLoading(false));
|
|
2599
|
+
alert("Please contact admin.");
|
|
2600
|
+
return;
|
|
2601
|
+
}
|
|
2602
|
+
localStorage.clear();
|
|
2603
|
+
var tokenJWT = authResult.data.token;
|
|
2604
|
+
trackEvent === null || trackEvent === void 0 ? void 0 : trackEvent({
|
|
2605
|
+
eventName: exports.AmplitudeEvent.LOGIN,
|
|
2606
|
+
eventProperties: {
|
|
2607
|
+
email: (account === null || account === void 0 ? void 0 : account.username) || email,
|
|
2608
|
+
login_method: 'microsoft',
|
|
2609
|
+
user_role: authResult.data.role,
|
|
2610
|
+
success: true,
|
|
2611
|
+
timestamp: new Date().toISOString()
|
|
2612
|
+
}
|
|
2613
|
+
});
|
|
2614
|
+
if (role === "LandingPage") {
|
|
2615
|
+
CookieService.setAuthCookie({
|
|
2616
|
+
token: tokenJWT,
|
|
2617
|
+
expiresAt: Date.now() + 24 * 60 * 60 * 1000
|
|
2618
|
+
});
|
|
2619
|
+
var getRedirectUrl = function getRedirectUrl(role) {
|
|
2620
|
+
switch (role) {
|
|
2621
|
+
case "Admin":
|
|
2622
|
+
return ADMIN_ORIGIN;
|
|
2623
|
+
case "Teacher":
|
|
2624
|
+
return TEACHER_ORIGIN;
|
|
2625
|
+
default:
|
|
2626
|
+
return role + "." + REQUEST_ORIGIN;
|
|
2627
|
+
}
|
|
2628
|
+
};
|
|
2629
|
+
var redirectUrl = getRedirectUrl(authResult.data.role);
|
|
2630
|
+
window.location.href = redirectUrl + "/dashboard";
|
|
2631
|
+
dispatch(setLoading(false));
|
|
2632
|
+
} else {
|
|
2633
|
+
localStorage.setItem(ACCESS_TOKEN, tokenJWT);
|
|
2634
|
+
onNavigate("/dashboard");
|
|
2635
|
+
dispatch(setLoading(false));
|
|
2636
|
+
}
|
|
2637
|
+
});
|
|
2638
|
+
}, function (error) {
|
|
2639
|
+
console.error("[MSAL] Error processing login:", error);
|
|
2640
|
+
dispatch(setLoading(false));
|
|
2641
|
+
alert("An error occurred while processing your login. Please try again.");
|
|
2642
|
+
}));
|
|
2643
|
+
} catch (e) {
|
|
2644
|
+
return Promise.reject(e);
|
|
2645
|
+
}
|
|
2646
|
+
};
|
|
2420
2647
|
React.useEffect(function () {
|
|
2421
2648
|
if (role === "Teacher" || role === "LandingPage") {
|
|
2422
2649
|
handleGetImage();
|
|
2423
2650
|
}
|
|
2424
2651
|
}, []);
|
|
2652
|
+
React.useEffect(function () {
|
|
2653
|
+
var handleMSALLoginSuccess = function handleMSALLoginSuccess(event) {
|
|
2654
|
+
try {
|
|
2655
|
+
var _event$detail = event.detail,
|
|
2656
|
+
account = _event$detail.account,
|
|
2657
|
+
accessToken = _event$detail.accessToken;
|
|
2658
|
+
var _temp2 = function () {
|
|
2659
|
+
if (account && accessToken) {
|
|
2660
|
+
localStorage.removeItem('MSAL_LOGIN_PENDING');
|
|
2661
|
+
return Promise.resolve(processMSALLogin(account, accessToken)).then(function () {});
|
|
2662
|
+
}
|
|
2663
|
+
}();
|
|
2664
|
+
return Promise.resolve(_temp2 && _temp2.then ? _temp2.then(function () {}) : void 0);
|
|
2665
|
+
} catch (e) {
|
|
2666
|
+
return Promise.reject(e);
|
|
2667
|
+
}
|
|
2668
|
+
};
|
|
2669
|
+
var pendingLogin = localStorage.getItem('MSAL_LOGIN_PENDING');
|
|
2670
|
+
if (pendingLogin === 'true') {
|
|
2671
|
+
var accountStr = localStorage.getItem('MSAL_ACCOUNT');
|
|
2672
|
+
var accessToken = localStorage.getItem('MSAL_ACCESS_TOKEN');
|
|
2673
|
+
if (accountStr && accessToken) {
|
|
2674
|
+
try {
|
|
2675
|
+
var account = JSON.parse(accountStr);
|
|
2676
|
+
localStorage.removeItem('MSAL_LOGIN_PENDING');
|
|
2677
|
+
localStorage.removeItem('MSAL_ACCOUNT');
|
|
2678
|
+
localStorage.removeItem('MSAL_ACCESS_TOKEN');
|
|
2679
|
+
processMSALLogin(account, accessToken);
|
|
2680
|
+
} catch (error) {
|
|
2681
|
+
console.error('[MSAL] Error parsing stored account:', error);
|
|
2682
|
+
localStorage.removeItem('MSAL_LOGIN_PENDING');
|
|
2683
|
+
localStorage.removeItem('MSAL_ACCOUNT');
|
|
2684
|
+
localStorage.removeItem('MSAL_ACCESS_TOKEN');
|
|
2685
|
+
}
|
|
2686
|
+
}
|
|
2687
|
+
}
|
|
2688
|
+
window.addEventListener('msal-login-success', handleMSALLoginSuccess);
|
|
2689
|
+
return function () {
|
|
2690
|
+
window.removeEventListener('msal-login-success', handleMSALLoginSuccess);
|
|
2691
|
+
};
|
|
2692
|
+
}, []);
|
|
2425
2693
|
var googleLogin = google.useGoogleLogin({
|
|
2426
2694
|
onSuccess: function (tokenResponse) {
|
|
2427
2695
|
try {
|
|
@@ -2453,8 +2721,8 @@ var BlockLogin = function BlockLogin(_ref) {
|
|
|
2453
2721
|
};
|
|
2454
2722
|
dispatch(setLoading(true));
|
|
2455
2723
|
return Promise.resolve(apiLoginGoogle(infoLogin)).then(function (authResult) {
|
|
2456
|
-
var _authResult$
|
|
2457
|
-
if (((_authResult$
|
|
2724
|
+
var _authResult$data2;
|
|
2725
|
+
if (((_authResult$data2 = authResult.data) === null || _authResult$data2 === void 0 ? void 0 : _authResult$data2.id) == null) {
|
|
2458
2726
|
dispatch(setLoading(false));
|
|
2459
2727
|
alert("Please contact admin.");
|
|
2460
2728
|
return;
|
|
@@ -2507,84 +2775,27 @@ var BlockLogin = function BlockLogin(_ref) {
|
|
|
2507
2775
|
});
|
|
2508
2776
|
var fnLoginMicrosoft = function fnLoginMicrosoft() {
|
|
2509
2777
|
try {
|
|
2510
|
-
var msalInstance = new msalBrowser.PublicClientApplication(msalConfig(MICROSOFT_CLIENT_ID, MICROSOFT_URL_DIRECT));
|
|
2511
|
-
if (!msalInstance) {
|
|
2512
|
-
console.error("MSAL instance not initialized");
|
|
2513
|
-
return Promise.resolve();
|
|
2514
|
-
}
|
|
2515
2778
|
return Promise.resolve(_catch(function () {
|
|
2516
|
-
|
|
2779
|
+
var msalInstance = getMSALInstance(MICROSOFT_CLIENT_ID, MICROSOFT_URL_DIRECT);
|
|
2780
|
+
if (!msalInstance) {
|
|
2781
|
+
console.error("[MSAL] Instance not initialized - check client ID configuration");
|
|
2782
|
+
alert("Microsoft login is not configured. Please contact admin.");
|
|
2783
|
+
return;
|
|
2784
|
+
}
|
|
2785
|
+
return Promise.resolve(initializeMSAL(MICROSOFT_CLIENT_ID, MICROSOFT_URL_DIRECT)).then(function () {
|
|
2517
2786
|
var loginRequest = {
|
|
2518
|
-
scopes: ["openid", "profile", "
|
|
2519
|
-
};
|
|
2520
|
-
var silentRequest = _extends$1({}, loginRequest, {
|
|
2787
|
+
scopes: ["openid", "profile", "User.Read"],
|
|
2521
2788
|
prompt: "select_account"
|
|
2522
|
-
}
|
|
2523
|
-
return Promise.resolve(msalInstance.
|
|
2524
|
-
return function () {
|
|
2525
|
-
if (response && response.account) {
|
|
2526
|
-
var account = response.account;
|
|
2527
|
-
var fullName = (account === null || account === void 0 ? void 0 : account.name) || "";
|
|
2528
|
-
var infoLogin = {
|
|
2529
|
-
firstName: fullName.split(' ').slice(0, -1).join(' '),
|
|
2530
|
-
lastName: fullName.split(' ').slice(-1).join(' '),
|
|
2531
|
-
fullName: fullName,
|
|
2532
|
-
imageUrl: "",
|
|
2533
|
-
email: (account === null || account === void 0 ? void 0 : account.username) || "",
|
|
2534
|
-
token: (response === null || response === void 0 ? void 0 : response.accessToken) || "",
|
|
2535
|
-
googleId: (account === null || account === void 0 ? void 0 : account.homeAccountId) || "",
|
|
2536
|
-
role: role,
|
|
2537
|
-
type: TypeLogin.Microsoft
|
|
2538
|
-
};
|
|
2539
|
-
dispatch(setLoading(true));
|
|
2540
|
-
return Promise.resolve(apiLoginGoogle(infoLogin)).then(function (authResult) {
|
|
2541
|
-
var _authResult$data2;
|
|
2542
|
-
if (((_authResult$data2 = authResult.data) === null || _authResult$data2 === void 0 ? void 0 : _authResult$data2.id) == null) {
|
|
2543
|
-
dispatch(setLoading(false));
|
|
2544
|
-
alert("Please contact admin.");
|
|
2545
|
-
return;
|
|
2546
|
-
}
|
|
2547
|
-
localStorage.clear();
|
|
2548
|
-
var tokenJWT = authResult.data.token;
|
|
2549
|
-
trackEvent === null || trackEvent === void 0 ? void 0 : trackEvent({
|
|
2550
|
-
eventName: exports.AmplitudeEvent.LOGIN,
|
|
2551
|
-
eventProperties: {
|
|
2552
|
-
email: email,
|
|
2553
|
-
login_method: 'google',
|
|
2554
|
-
user_role: authResult.data.role,
|
|
2555
|
-
success: true,
|
|
2556
|
-
timestamp: new Date().toISOString()
|
|
2557
|
-
}
|
|
2558
|
-
});
|
|
2559
|
-
if (role === "LandingPage") {
|
|
2560
|
-
CookieService.setAuthCookie({
|
|
2561
|
-
token: tokenJWT,
|
|
2562
|
-
expiresAt: Date.now() + 24 * 60 * 60 * 1000
|
|
2563
|
-
});
|
|
2564
|
-
var getRedirectUrl = function getRedirectUrl(role) {
|
|
2565
|
-
switch (role) {
|
|
2566
|
-
case "Admin":
|
|
2567
|
-
return ADMIN_ORIGIN;
|
|
2568
|
-
case "Teacher":
|
|
2569
|
-
return TEACHER_ORIGIN;
|
|
2570
|
-
default:
|
|
2571
|
-
return role + "." + REQUEST_ORIGIN;
|
|
2572
|
-
}
|
|
2573
|
-
};
|
|
2574
|
-
var redirectUrl = getRedirectUrl(authResult.data.role);
|
|
2575
|
-
window.location.href = redirectUrl + "/dashboard";
|
|
2576
|
-
dispatch(setLoading(false));
|
|
2577
|
-
}
|
|
2578
|
-
localStorage.setItem(ACCESS_TOKEN, tokenJWT);
|
|
2579
|
-
onNavigate("/dashboard");
|
|
2580
|
-
dispatch(setLoading(false));
|
|
2581
|
-
});
|
|
2582
|
-
}
|
|
2583
|
-
}();
|
|
2584
|
-
});
|
|
2789
|
+
};
|
|
2790
|
+
return Promise.resolve(msalInstance.loginRedirect(loginRequest)).then(function () {});
|
|
2585
2791
|
});
|
|
2586
2792
|
}, function (error) {
|
|
2587
|
-
|
|
2793
|
+
var _error$message;
|
|
2794
|
+
console.error("[MSAL] Microsoft login error:", error);
|
|
2795
|
+
if ((error === null || error === void 0 ? void 0 : error.errorCode) === 'popup_window_error' || error !== null && error !== void 0 && (_error$message = error.message) !== null && _error$message !== void 0 && _error$message.includes('popup')) {
|
|
2796
|
+
console.error("[MSAL] Popup blocked or COOP error - this should not happen with redirect flow");
|
|
2797
|
+
}
|
|
2798
|
+
alert("An error occurred during Microsoft login. Please try again.");
|
|
2588
2799
|
}));
|
|
2589
2800
|
} catch (e) {
|
|
2590
2801
|
return Promise.reject(e);
|
|
@@ -4088,6 +4299,7 @@ exports.DATE_TIME_MIN_VALUE = DATE_TIME_MIN_VALUE;
|
|
|
4088
4299
|
exports.LayoutContext = LayoutContext;
|
|
4089
4300
|
exports.Loading = Loading;
|
|
4090
4301
|
exports.Login = Login;
|
|
4302
|
+
exports.MSALRedirectHandler = MSALRedirectHandler;
|
|
4091
4303
|
exports.MarkdownLatexRender = MarkdownRenderer;
|
|
4092
4304
|
exports.NotFound = NotFound;
|
|
4093
4305
|
exports.OPENSALT_BASE_URL = OPENSALT_BASE_URL;
|
|
@@ -4097,11 +4309,17 @@ exports.api = api;
|
|
|
4097
4309
|
exports.apiUpload = apiUpload;
|
|
4098
4310
|
exports.firstCheckToken = firstCheckToken;
|
|
4099
4311
|
exports.getAccessToken = getAccessToken;
|
|
4312
|
+
exports.getActiveAccount = getActiveAccount;
|
|
4313
|
+
exports.getAllAccounts = getAllAccounts;
|
|
4100
4314
|
exports.getErrorMessage = getErrorMessage;
|
|
4101
4315
|
exports.getImageUrl = getImageUrl;
|
|
4316
|
+
exports.getMSALInstance = getMSALInstance;
|
|
4317
|
+
exports.handleMSALRedirect = handleMSALRedirect;
|
|
4102
4318
|
exports.historyCore = historyCore;
|
|
4103
4319
|
exports.initSentry = initSentry;
|
|
4104
4320
|
exports.initializeAmplitude = initializeAmplitude;
|
|
4321
|
+
exports.initializeMSAL = initializeMSAL;
|
|
4322
|
+
exports.isMSALRedirect = isMSALRedirect;
|
|
4105
4323
|
exports.setAddTenant = setAddTenant;
|
|
4106
4324
|
exports.setAlert = setAlert;
|
|
4107
4325
|
exports.setIsRefetchSidebar = setIsRefetchSidebar;
|