acsi-core 0.9.21 → 0.9.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/components/MSALRedirectHandler/index.d.ts +5 -2
- package/dist/containers/Login/configs/constants.d.ts +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +340 -122
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +336 -124
- package/dist/index.modern.js.map +1 -1
- package/dist/utils/msalInstance.d.ts +38 -0
- package/package.json +1 -1
|
@@ -4,8 +4,11 @@
|
|
|
4
4
|
* This component handles MSAL redirect authentication flows by processing
|
|
5
5
|
* the hash fragment in the URL before any router code can clear it.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
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.
|
|
9
12
|
*/
|
|
10
13
|
declare const MSALRedirectHandler: () => null;
|
|
11
14
|
export default MSALRedirectHandler;
|
package/dist/index.d.ts
CHANGED
|
@@ -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
|
@@ -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"];
|
|
@@ -2185,7 +2185,8 @@ var msalConfig = function msalConfig(clientId, redirectUri) {
|
|
|
2185
2185
|
auth: {
|
|
2186
2186
|
clientId: clientId,
|
|
2187
2187
|
authority: "https://login.microsoftonline.com/common",
|
|
2188
|
-
redirectUri: redirectUri
|
|
2188
|
+
redirectUri: redirectUri,
|
|
2189
|
+
navigateToLoginRequestUrl: false
|
|
2189
2190
|
},
|
|
2190
2191
|
cache: {
|
|
2191
2192
|
cacheLocation: "sessionStorage",
|
|
@@ -2197,18 +2198,19 @@ var msalConfig = function msalConfig(clientId, redirectUri) {
|
|
|
2197
2198
|
if (containsPii) {
|
|
2198
2199
|
return;
|
|
2199
2200
|
}
|
|
2201
|
+
var prefix = '[MSAL]';
|
|
2200
2202
|
switch (level) {
|
|
2201
2203
|
case msalBrowser.LogLevel.Error:
|
|
2202
|
-
console.error(message);
|
|
2204
|
+
console.error(prefix + " " + message);
|
|
2203
2205
|
return;
|
|
2204
2206
|
case msalBrowser.LogLevel.Info:
|
|
2205
|
-
console.info(message);
|
|
2207
|
+
console.info(prefix + " " + message);
|
|
2206
2208
|
return;
|
|
2207
2209
|
case msalBrowser.LogLevel.Verbose:
|
|
2208
|
-
console.debug(message);
|
|
2210
|
+
console.debug(prefix + " " + message);
|
|
2209
2211
|
return;
|
|
2210
2212
|
case msalBrowser.LogLevel.Warning:
|
|
2211
|
-
console.warn(message);
|
|
2213
|
+
console.warn(prefix + " " + message);
|
|
2212
2214
|
return;
|
|
2213
2215
|
default:
|
|
2214
2216
|
return;
|
|
@@ -2219,45 +2221,203 @@ var msalConfig = function msalConfig(clientId, redirectUri) {
|
|
|
2219
2221
|
};
|
|
2220
2222
|
};
|
|
2221
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
|
+
console.log('[MSAL] handleMSALRedirect: No hash found in URL');
|
|
2271
|
+
return Promise.resolve(null);
|
|
2272
|
+
}
|
|
2273
|
+
console.log('[MSAL] handleMSALRedirect: Hash found:', window.location.hash.substring(0, 100) + '...');
|
|
2274
|
+
var hashParams = new URLSearchParams(window.location.hash.substring(1));
|
|
2275
|
+
var hasAccessToken = hashParams.has('access_token');
|
|
2276
|
+
var hasIdToken = hashParams.has('id_token');
|
|
2277
|
+
var hasError = hashParams.has('error');
|
|
2278
|
+
var hasCode = hashParams.has('code');
|
|
2279
|
+
var hasMSALParams = hasAccessToken || hasIdToken || hasError || hasCode;
|
|
2280
|
+
console.log('[MSAL] handleMSALRedirect: Hash params check:', {
|
|
2281
|
+
hasAccessToken: hasAccessToken,
|
|
2282
|
+
hasIdToken: hasIdToken,
|
|
2283
|
+
hasError: hasError,
|
|
2284
|
+
hasCode: hasCode,
|
|
2285
|
+
hasMSALParams: hasMSALParams
|
|
2286
|
+
});
|
|
2287
|
+
if (!hasMSALParams) {
|
|
2288
|
+
console.log('[MSAL] handleMSALRedirect: No MSAL parameters found in hash');
|
|
2289
|
+
return Promise.resolve(null);
|
|
2290
|
+
}
|
|
2291
|
+
return Promise.resolve(_catch(function () {
|
|
2292
|
+
console.log('[MSAL] handleMSALRedirect: Initializing MSAL with:', {
|
|
2293
|
+
clientId: clientId ? 'configured' : 'missing',
|
|
2294
|
+
redirectUri: redirectUri
|
|
2295
|
+
});
|
|
2296
|
+
return Promise.resolve(initializeMSAL(clientId, redirectUri)).then(function (instance) {
|
|
2297
|
+
if (!instance) {
|
|
2298
|
+
console.error('[MSAL] handleMSALRedirect: Failed to initialize instance');
|
|
2299
|
+
return null;
|
|
2300
|
+
}
|
|
2301
|
+
console.log('[MSAL] handleMSALRedirect: Calling handleRedirectPromise...');
|
|
2302
|
+
return Promise.resolve(instance.handleRedirectPromise()).then(function (response) {
|
|
2303
|
+
if (response) {
|
|
2304
|
+
var _response$account;
|
|
2305
|
+
console.log('[MSAL] handleMSALRedirect: Got response from handleRedirectPromise', {
|
|
2306
|
+
account: (_response$account = response.account) === null || _response$account === void 0 ? void 0 : _response$account.username,
|
|
2307
|
+
hasAccessToken: !!response.accessToken,
|
|
2308
|
+
scopes: response.scopes
|
|
2309
|
+
});
|
|
2310
|
+
} else {
|
|
2311
|
+
console.log('[MSAL] handleMSALRedirect: handleRedirectPromise returned null/undefined');
|
|
2312
|
+
}
|
|
2313
|
+
return response;
|
|
2314
|
+
});
|
|
2315
|
+
});
|
|
2316
|
+
}, function (error) {
|
|
2317
|
+
console.error('[MSAL] handleMSALRedirect: Error during processing:', error);
|
|
2318
|
+
if (error instanceof Error) {
|
|
2319
|
+
var _error$stack;
|
|
2320
|
+
console.error('[MSAL] handleMSALRedirect: Error details:', {
|
|
2321
|
+
name: error.name,
|
|
2322
|
+
message: error.message,
|
|
2323
|
+
stack: (_error$stack = error.stack) === null || _error$stack === void 0 ? void 0 : _error$stack.substring(0, 200)
|
|
2324
|
+
});
|
|
2325
|
+
}
|
|
2326
|
+
return null;
|
|
2327
|
+
}));
|
|
2328
|
+
} catch (e) {
|
|
2329
|
+
return Promise.reject(e);
|
|
2330
|
+
}
|
|
2331
|
+
};
|
|
2332
|
+
var isMSALRedirect = function isMSALRedirect() {
|
|
2333
|
+
if (!window.location.hash) {
|
|
2334
|
+
return false;
|
|
2335
|
+
}
|
|
2336
|
+
var hashParams = new URLSearchParams(window.location.hash.substring(1));
|
|
2337
|
+
return hashParams.has('access_token') || hashParams.has('id_token') || hashParams.has('error') || hashParams.has('code');
|
|
2338
|
+
};
|
|
2339
|
+
var getAllAccounts = function getAllAccounts() {
|
|
2340
|
+
var instance = getMSALInstance();
|
|
2341
|
+
if (!instance) {
|
|
2342
|
+
return [];
|
|
2343
|
+
}
|
|
2344
|
+
return instance.getAllAccounts();
|
|
2345
|
+
};
|
|
2346
|
+
var getActiveAccount = function getActiveAccount() {
|
|
2347
|
+
var instance = getMSALInstance();
|
|
2348
|
+
if (!instance) {
|
|
2349
|
+
return null;
|
|
2350
|
+
}
|
|
2351
|
+
return instance.getActiveAccount();
|
|
2352
|
+
};
|
|
2353
|
+
|
|
2222
2354
|
var MSALRedirectHandler = function MSALRedirectHandler() {
|
|
2223
|
-
React.
|
|
2355
|
+
React.useLayoutEffect(function () {
|
|
2224
2356
|
var handleRedirect = function handleRedirect() {
|
|
2225
2357
|
try {
|
|
2226
|
-
|
|
2358
|
+
var alreadyProcessed = localStorage.getItem('MSAL_LOGIN_PENDING');
|
|
2359
|
+
if (alreadyProcessed === 'true') {
|
|
2360
|
+
console.log('[MSAL] RedirectHandler: Already processed by pre-init, skipping');
|
|
2227
2361
|
return Promise.resolve();
|
|
2228
2362
|
}
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
if (!hasMSALParams) {
|
|
2363
|
+
if (!isMSALRedirect()) {
|
|
2364
|
+
console.log('[MSAL] RedirectHandler: No MSAL redirect detected');
|
|
2232
2365
|
return Promise.resolve();
|
|
2233
2366
|
}
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2367
|
+
console.log('[MSAL] RedirectHandler: Redirect detected, processing...');
|
|
2368
|
+
console.log('[MSAL] RedirectHandler: Hash:', window.location.hash);
|
|
2369
|
+
console.log('[MSAL] RedirectHandler: Full URL:', window.location.href);
|
|
2370
|
+
var _temp = _catch(function () {
|
|
2371
|
+
return Promise.resolve(handleMSALRedirect()).then(function (response) {
|
|
2372
|
+
if (response && response.account) {
|
|
2373
|
+
console.log('[MSAL] Redirect handled successfully', {
|
|
2374
|
+
account: response.account.username,
|
|
2375
|
+
scopes: response.scopes
|
|
2376
|
+
});
|
|
2377
|
+
if (window.history.replaceState) {
|
|
2378
|
+
window.history.replaceState(null, '', window.location.pathname + window.location.search);
|
|
2379
|
+
}
|
|
2380
|
+
localStorage.setItem('MSAL_ACCOUNT', JSON.stringify(response.account));
|
|
2381
|
+
localStorage.setItem('MSAL_ACCESS_TOKEN', response.accessToken || '');
|
|
2382
|
+
localStorage.setItem('MSAL_LOGIN_PENDING', 'true');
|
|
2383
|
+
window.dispatchEvent(new CustomEvent('msal-login-success', {
|
|
2384
|
+
detail: {
|
|
2385
|
+
account: response.account,
|
|
2386
|
+
accessToken: response.accessToken,
|
|
2387
|
+
idToken: response.idToken
|
|
2247
2388
|
}
|
|
2389
|
+
}));
|
|
2390
|
+
if (window.location.pathname.includes('/login')) {
|
|
2391
|
+
window.location.reload();
|
|
2248
2392
|
} else {
|
|
2249
|
-
|
|
2250
|
-
|
|
2393
|
+
window.location.href = '/dashboard';
|
|
2394
|
+
}
|
|
2395
|
+
} else {
|
|
2396
|
+
var hashParams = new URLSearchParams(window.location.hash.substring(1));
|
|
2397
|
+
var error = hashParams.get('error');
|
|
2398
|
+
var errorDescription = hashParams.get('error_description');
|
|
2399
|
+
if (error) {
|
|
2400
|
+
console.error('[MSAL] Authentication error:', error, errorDescription);
|
|
2401
|
+
if (error === 'access_denied') {
|
|
2402
|
+
console.error('[MSAL] User denied access or scopes not configured in Azure AD');
|
|
2251
2403
|
}
|
|
2252
2404
|
}
|
|
2253
|
-
|
|
2405
|
+
if (window.history.replaceState) {
|
|
2406
|
+
window.history.replaceState(null, '', window.location.pathname + window.location.search);
|
|
2407
|
+
}
|
|
2408
|
+
}
|
|
2254
2409
|
});
|
|
2255
2410
|
}, function (error) {
|
|
2256
|
-
|
|
2411
|
+
var _error$message;
|
|
2412
|
+
console.error('[MSAL] Redirect handling error:', error);
|
|
2413
|
+
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')) {
|
|
2414
|
+
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.');
|
|
2415
|
+
}
|
|
2257
2416
|
if (window.history.replaceState) {
|
|
2258
2417
|
window.history.replaceState(null, '', window.location.pathname + window.location.search);
|
|
2259
2418
|
}
|
|
2260
|
-
})
|
|
2419
|
+
});
|
|
2420
|
+
return Promise.resolve(_temp && _temp.then ? _temp.then(function () {}) : void 0);
|
|
2261
2421
|
} catch (e) {
|
|
2262
2422
|
return Promise.reject(e);
|
|
2263
2423
|
}
|
|
@@ -2465,11 +2625,120 @@ var BlockLogin = function BlockLogin(_ref) {
|
|
|
2465
2625
|
return Promise.reject(e);
|
|
2466
2626
|
}
|
|
2467
2627
|
};
|
|
2628
|
+
var processMSALLogin = function processMSALLogin(account, accessToken) {
|
|
2629
|
+
try {
|
|
2630
|
+
return Promise.resolve(_catch(function () {
|
|
2631
|
+
dispatch(setLoading(true));
|
|
2632
|
+
var fullName = (account === null || account === void 0 ? void 0 : account.name) || "";
|
|
2633
|
+
var infoLogin = {
|
|
2634
|
+
firstName: fullName.split(' ').slice(0, -1).join(' '),
|
|
2635
|
+
lastName: fullName.split(' ').slice(-1).join(' '),
|
|
2636
|
+
fullName: fullName,
|
|
2637
|
+
imageUrl: "",
|
|
2638
|
+
email: (account === null || account === void 0 ? void 0 : account.username) || "",
|
|
2639
|
+
token: accessToken || "",
|
|
2640
|
+
googleId: (account === null || account === void 0 ? void 0 : account.homeAccountId) || "",
|
|
2641
|
+
role: role,
|
|
2642
|
+
type: TypeLogin.Microsoft
|
|
2643
|
+
};
|
|
2644
|
+
return Promise.resolve(apiLoginGoogle(infoLogin)).then(function (authResult) {
|
|
2645
|
+
var _authResult$data;
|
|
2646
|
+
if (((_authResult$data = authResult.data) === null || _authResult$data === void 0 ? void 0 : _authResult$data.id) == null) {
|
|
2647
|
+
dispatch(setLoading(false));
|
|
2648
|
+
alert("Please contact admin.");
|
|
2649
|
+
return;
|
|
2650
|
+
}
|
|
2651
|
+
localStorage.clear();
|
|
2652
|
+
var tokenJWT = authResult.data.token;
|
|
2653
|
+
trackEvent === null || trackEvent === void 0 ? void 0 : trackEvent({
|
|
2654
|
+
eventName: exports.AmplitudeEvent.LOGIN,
|
|
2655
|
+
eventProperties: {
|
|
2656
|
+
email: (account === null || account === void 0 ? void 0 : account.username) || email,
|
|
2657
|
+
login_method: 'microsoft',
|
|
2658
|
+
user_role: authResult.data.role,
|
|
2659
|
+
success: true,
|
|
2660
|
+
timestamp: new Date().toISOString()
|
|
2661
|
+
}
|
|
2662
|
+
});
|
|
2663
|
+
if (role === "LandingPage") {
|
|
2664
|
+
CookieService.setAuthCookie({
|
|
2665
|
+
token: tokenJWT,
|
|
2666
|
+
expiresAt: Date.now() + 24 * 60 * 60 * 1000
|
|
2667
|
+
});
|
|
2668
|
+
var getRedirectUrl = function getRedirectUrl(role) {
|
|
2669
|
+
switch (role) {
|
|
2670
|
+
case "Admin":
|
|
2671
|
+
return ADMIN_ORIGIN;
|
|
2672
|
+
case "Teacher":
|
|
2673
|
+
return TEACHER_ORIGIN;
|
|
2674
|
+
default:
|
|
2675
|
+
return role + "." + REQUEST_ORIGIN;
|
|
2676
|
+
}
|
|
2677
|
+
};
|
|
2678
|
+
var redirectUrl = getRedirectUrl(authResult.data.role);
|
|
2679
|
+
window.location.href = redirectUrl + "/dashboard";
|
|
2680
|
+
dispatch(setLoading(false));
|
|
2681
|
+
} else {
|
|
2682
|
+
localStorage.setItem(ACCESS_TOKEN, tokenJWT);
|
|
2683
|
+
onNavigate("/dashboard");
|
|
2684
|
+
dispatch(setLoading(false));
|
|
2685
|
+
}
|
|
2686
|
+
});
|
|
2687
|
+
}, function (error) {
|
|
2688
|
+
console.error("[MSAL] Error processing login:", error);
|
|
2689
|
+
dispatch(setLoading(false));
|
|
2690
|
+
alert("An error occurred while processing your login. Please try again.");
|
|
2691
|
+
}));
|
|
2692
|
+
} catch (e) {
|
|
2693
|
+
return Promise.reject(e);
|
|
2694
|
+
}
|
|
2695
|
+
};
|
|
2468
2696
|
React.useEffect(function () {
|
|
2469
2697
|
if (role === "Teacher" || role === "LandingPage") {
|
|
2470
2698
|
handleGetImage();
|
|
2471
2699
|
}
|
|
2472
2700
|
}, []);
|
|
2701
|
+
React.useEffect(function () {
|
|
2702
|
+
var handleMSALLoginSuccess = function handleMSALLoginSuccess(event) {
|
|
2703
|
+
try {
|
|
2704
|
+
var _event$detail = event.detail,
|
|
2705
|
+
account = _event$detail.account,
|
|
2706
|
+
accessToken = _event$detail.accessToken;
|
|
2707
|
+
var _temp2 = function () {
|
|
2708
|
+
if (account && accessToken) {
|
|
2709
|
+
localStorage.removeItem('MSAL_LOGIN_PENDING');
|
|
2710
|
+
return Promise.resolve(processMSALLogin(account, accessToken)).then(function () {});
|
|
2711
|
+
}
|
|
2712
|
+
}();
|
|
2713
|
+
return Promise.resolve(_temp2 && _temp2.then ? _temp2.then(function () {}) : void 0);
|
|
2714
|
+
} catch (e) {
|
|
2715
|
+
return Promise.reject(e);
|
|
2716
|
+
}
|
|
2717
|
+
};
|
|
2718
|
+
var pendingLogin = localStorage.getItem('MSAL_LOGIN_PENDING');
|
|
2719
|
+
if (pendingLogin === 'true') {
|
|
2720
|
+
var accountStr = localStorage.getItem('MSAL_ACCOUNT');
|
|
2721
|
+
var accessToken = localStorage.getItem('MSAL_ACCESS_TOKEN');
|
|
2722
|
+
if (accountStr && accessToken) {
|
|
2723
|
+
try {
|
|
2724
|
+
var account = JSON.parse(accountStr);
|
|
2725
|
+
localStorage.removeItem('MSAL_LOGIN_PENDING');
|
|
2726
|
+
localStorage.removeItem('MSAL_ACCOUNT');
|
|
2727
|
+
localStorage.removeItem('MSAL_ACCESS_TOKEN');
|
|
2728
|
+
processMSALLogin(account, accessToken);
|
|
2729
|
+
} catch (error) {
|
|
2730
|
+
console.error('[MSAL] Error parsing stored account:', error);
|
|
2731
|
+
localStorage.removeItem('MSAL_LOGIN_PENDING');
|
|
2732
|
+
localStorage.removeItem('MSAL_ACCOUNT');
|
|
2733
|
+
localStorage.removeItem('MSAL_ACCESS_TOKEN');
|
|
2734
|
+
}
|
|
2735
|
+
}
|
|
2736
|
+
}
|
|
2737
|
+
window.addEventListener('msal-login-success', handleMSALLoginSuccess);
|
|
2738
|
+
return function () {
|
|
2739
|
+
window.removeEventListener('msal-login-success', handleMSALLoginSuccess);
|
|
2740
|
+
};
|
|
2741
|
+
}, []);
|
|
2473
2742
|
var googleLogin = google.useGoogleLogin({
|
|
2474
2743
|
onSuccess: function (tokenResponse) {
|
|
2475
2744
|
try {
|
|
@@ -2501,8 +2770,8 @@ var BlockLogin = function BlockLogin(_ref) {
|
|
|
2501
2770
|
};
|
|
2502
2771
|
dispatch(setLoading(true));
|
|
2503
2772
|
return Promise.resolve(apiLoginGoogle(infoLogin)).then(function (authResult) {
|
|
2504
|
-
var _authResult$
|
|
2505
|
-
if (((_authResult$
|
|
2773
|
+
var _authResult$data2;
|
|
2774
|
+
if (((_authResult$data2 = authResult.data) === null || _authResult$data2 === void 0 ? void 0 : _authResult$data2.id) == null) {
|
|
2506
2775
|
dispatch(setLoading(false));
|
|
2507
2776
|
alert("Please contact admin.");
|
|
2508
2777
|
return;
|
|
@@ -2555,84 +2824,27 @@ var BlockLogin = function BlockLogin(_ref) {
|
|
|
2555
2824
|
});
|
|
2556
2825
|
var fnLoginMicrosoft = function fnLoginMicrosoft() {
|
|
2557
2826
|
try {
|
|
2558
|
-
var msalInstance = new msalBrowser.PublicClientApplication(msalConfig(MICROSOFT_CLIENT_ID, MICROSOFT_URL_DIRECT));
|
|
2559
|
-
if (!msalInstance) {
|
|
2560
|
-
console.error("MSAL instance not initialized");
|
|
2561
|
-
return Promise.resolve();
|
|
2562
|
-
}
|
|
2563
2827
|
return Promise.resolve(_catch(function () {
|
|
2564
|
-
|
|
2828
|
+
var msalInstance = getMSALInstance(MICROSOFT_CLIENT_ID, MICROSOFT_URL_DIRECT);
|
|
2829
|
+
if (!msalInstance) {
|
|
2830
|
+
console.error("[MSAL] Instance not initialized - check client ID configuration");
|
|
2831
|
+
alert("Microsoft login is not configured. Please contact admin.");
|
|
2832
|
+
return;
|
|
2833
|
+
}
|
|
2834
|
+
return Promise.resolve(initializeMSAL(MICROSOFT_CLIENT_ID, MICROSOFT_URL_DIRECT)).then(function () {
|
|
2565
2835
|
var loginRequest = {
|
|
2566
|
-
scopes: ["openid", "profile", "
|
|
2567
|
-
};
|
|
2568
|
-
var silentRequest = _extends$1({}, loginRequest, {
|
|
2836
|
+
scopes: ["openid", "profile", "User.Read"],
|
|
2569
2837
|
prompt: "select_account"
|
|
2570
|
-
}
|
|
2571
|
-
return Promise.resolve(msalInstance.
|
|
2572
|
-
return function () {
|
|
2573
|
-
if (response && response.account) {
|
|
2574
|
-
var account = response.account;
|
|
2575
|
-
var fullName = (account === null || account === void 0 ? void 0 : account.name) || "";
|
|
2576
|
-
var infoLogin = {
|
|
2577
|
-
firstName: fullName.split(' ').slice(0, -1).join(' '),
|
|
2578
|
-
lastName: fullName.split(' ').slice(-1).join(' '),
|
|
2579
|
-
fullName: fullName,
|
|
2580
|
-
imageUrl: "",
|
|
2581
|
-
email: (account === null || account === void 0 ? void 0 : account.username) || "",
|
|
2582
|
-
token: (response === null || response === void 0 ? void 0 : response.accessToken) || "",
|
|
2583
|
-
googleId: (account === null || account === void 0 ? void 0 : account.homeAccountId) || "",
|
|
2584
|
-
role: role,
|
|
2585
|
-
type: TypeLogin.Microsoft
|
|
2586
|
-
};
|
|
2587
|
-
dispatch(setLoading(true));
|
|
2588
|
-
return Promise.resolve(apiLoginGoogle(infoLogin)).then(function (authResult) {
|
|
2589
|
-
var _authResult$data2;
|
|
2590
|
-
if (((_authResult$data2 = authResult.data) === null || _authResult$data2 === void 0 ? void 0 : _authResult$data2.id) == null) {
|
|
2591
|
-
dispatch(setLoading(false));
|
|
2592
|
-
alert("Please contact admin.");
|
|
2593
|
-
return;
|
|
2594
|
-
}
|
|
2595
|
-
localStorage.clear();
|
|
2596
|
-
var tokenJWT = authResult.data.token;
|
|
2597
|
-
trackEvent === null || trackEvent === void 0 ? void 0 : trackEvent({
|
|
2598
|
-
eventName: exports.AmplitudeEvent.LOGIN,
|
|
2599
|
-
eventProperties: {
|
|
2600
|
-
email: email,
|
|
2601
|
-
login_method: 'google',
|
|
2602
|
-
user_role: authResult.data.role,
|
|
2603
|
-
success: true,
|
|
2604
|
-
timestamp: new Date().toISOString()
|
|
2605
|
-
}
|
|
2606
|
-
});
|
|
2607
|
-
if (role === "LandingPage") {
|
|
2608
|
-
CookieService.setAuthCookie({
|
|
2609
|
-
token: tokenJWT,
|
|
2610
|
-
expiresAt: Date.now() + 24 * 60 * 60 * 1000
|
|
2611
|
-
});
|
|
2612
|
-
var getRedirectUrl = function getRedirectUrl(role) {
|
|
2613
|
-
switch (role) {
|
|
2614
|
-
case "Admin":
|
|
2615
|
-
return ADMIN_ORIGIN;
|
|
2616
|
-
case "Teacher":
|
|
2617
|
-
return TEACHER_ORIGIN;
|
|
2618
|
-
default:
|
|
2619
|
-
return role + "." + REQUEST_ORIGIN;
|
|
2620
|
-
}
|
|
2621
|
-
};
|
|
2622
|
-
var redirectUrl = getRedirectUrl(authResult.data.role);
|
|
2623
|
-
window.location.href = redirectUrl + "/dashboard";
|
|
2624
|
-
dispatch(setLoading(false));
|
|
2625
|
-
}
|
|
2626
|
-
localStorage.setItem(ACCESS_TOKEN, tokenJWT);
|
|
2627
|
-
onNavigate("/dashboard");
|
|
2628
|
-
dispatch(setLoading(false));
|
|
2629
|
-
});
|
|
2630
|
-
}
|
|
2631
|
-
}();
|
|
2632
|
-
});
|
|
2838
|
+
};
|
|
2839
|
+
return Promise.resolve(msalInstance.loginRedirect(loginRequest)).then(function () {});
|
|
2633
2840
|
});
|
|
2634
2841
|
}, function (error) {
|
|
2635
|
-
|
|
2842
|
+
var _error$message;
|
|
2843
|
+
console.error("[MSAL] Microsoft login error:", error);
|
|
2844
|
+
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')) {
|
|
2845
|
+
console.error("[MSAL] Popup blocked or COOP error - this should not happen with redirect flow");
|
|
2846
|
+
}
|
|
2847
|
+
alert("An error occurred during Microsoft login. Please try again.");
|
|
2636
2848
|
}));
|
|
2637
2849
|
} catch (e) {
|
|
2638
2850
|
return Promise.reject(e);
|
|
@@ -4146,11 +4358,17 @@ exports.api = api;
|
|
|
4146
4358
|
exports.apiUpload = apiUpload;
|
|
4147
4359
|
exports.firstCheckToken = firstCheckToken;
|
|
4148
4360
|
exports.getAccessToken = getAccessToken;
|
|
4361
|
+
exports.getActiveAccount = getActiveAccount;
|
|
4362
|
+
exports.getAllAccounts = getAllAccounts;
|
|
4149
4363
|
exports.getErrorMessage = getErrorMessage;
|
|
4150
4364
|
exports.getImageUrl = getImageUrl;
|
|
4365
|
+
exports.getMSALInstance = getMSALInstance;
|
|
4366
|
+
exports.handleMSALRedirect = handleMSALRedirect;
|
|
4151
4367
|
exports.historyCore = historyCore;
|
|
4152
4368
|
exports.initSentry = initSentry;
|
|
4153
4369
|
exports.initializeAmplitude = initializeAmplitude;
|
|
4370
|
+
exports.initializeMSAL = initializeMSAL;
|
|
4371
|
+
exports.isMSALRedirect = isMSALRedirect;
|
|
4154
4372
|
exports.setAddTenant = setAddTenant;
|
|
4155
4373
|
exports.setAlert = setAlert;
|
|
4156
4374
|
exports.setIsRefetchSidebar = setIsRefetchSidebar;
|