acsi-core 0.9.23 → 0.9.24

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.
@@ -2189,7 +2189,7 @@ var msalConfig = function msalConfig(clientId, redirectUri) {
2189
2189
  navigateToLoginRequestUrl: false
2190
2190
  },
2191
2191
  cache: {
2192
- cacheLocation: "sessionStorage",
2192
+ cacheLocation: "localStorage",
2193
2193
  storeAuthStateInCookie: false
2194
2194
  },
2195
2195
  system: {
@@ -2232,7 +2232,18 @@ var getMSALInstance = function getMSALInstance(clientId, redirectUri) {
2232
2232
  return null;
2233
2233
  }
2234
2234
  if (!msalInstance) {
2235
+ console.log('[MSAL] Creating new MSAL instance with:', {
2236
+ clientId: finalClientId ? 'configured' : 'missing',
2237
+ redirectUri: finalRedirectUri
2238
+ });
2235
2239
  msalInstance = new PublicClientApplication(msalConfig(finalClientId, finalRedirectUri));
2240
+ } else {
2241
+ var _existingConfig$auth, _existingConfig$auth2;
2242
+ var existingConfig = msalInstance.config;
2243
+ if ((existingConfig === null || existingConfig === void 0 ? void 0 : (_existingConfig$auth = existingConfig.auth) === null || _existingConfig$auth === void 0 ? void 0 : _existingConfig$auth.clientId) !== finalClientId || (existingConfig === null || existingConfig === void 0 ? void 0 : (_existingConfig$auth2 = existingConfig.auth) === null || _existingConfig$auth2 === void 0 ? void 0 : _existingConfig$auth2.redirectUri) !== finalRedirectUri) {
2244
+ console.warn('[MSAL] Config mismatch detected, creating new instance');
2245
+ msalInstance = new PublicClientApplication(msalConfig(finalClientId, finalRedirectUri));
2246
+ }
2236
2247
  }
2237
2248
  return msalInstance;
2238
2249
  };
@@ -2253,6 +2264,7 @@ var initializeMSAL = function initializeMSAL(clientId, redirectUri) {
2253
2264
  isInitializing = true;
2254
2265
  initPromise = instance.initialize().then(function () {
2255
2266
  isInitializing = false;
2267
+ console.log('[MSAL] Instance initialized successfully');
2256
2268
  return instance;
2257
2269
  })["catch"](function (error) {
2258
2270
  isInitializing = false;
@@ -2299,18 +2311,108 @@ var handleMSALRedirect = function handleMSALRedirect(clientId, redirectUri) {
2299
2311
  return null;
2300
2312
  }
2301
2313
  console.log('[MSAL] handleMSALRedirect: Calling handleRedirectPromise...');
2314
+ var accounts = instance.getAllAccounts();
2315
+ console.log('[MSAL] handleMSALRedirect: Current accounts:', accounts.length);
2302
2316
  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;
2317
+ var _exit = false;
2318
+ var _temp = function () {
2319
+ if (response) {
2320
+ var _response$account;
2321
+ console.log('[MSAL] handleMSALRedirect: Got response from handleRedirectPromise', {
2322
+ account: (_response$account = response.account) === null || _response$account === void 0 ? void 0 : _response$account.username,
2323
+ hasAccessToken: !!response.accessToken,
2324
+ scopes: response.scopes
2325
+ });
2326
+ } else {
2327
+ console.log('[MSAL] handleMSALRedirect: handleRedirectPromise returned null/undefined');
2328
+ console.log('[MSAL] handleMSALRedirect: This might mean the redirect was already processed or state mismatch');
2329
+ console.log('[MSAL] handleMSALRedirect: Checking localStorage for interaction state...');
2330
+ try {
2331
+ var msalCacheKeys = Object.keys(localStorage).filter(function (key) {
2332
+ return key.startsWith('msal.');
2333
+ });
2334
+ console.log('[MSAL] handleMSALRedirect: Found MSAL cache keys:', msalCacheKeys.length);
2335
+ var interactionStateKey = msalCacheKeys.find(function (key) {
2336
+ return key.includes('interaction');
2337
+ });
2338
+ if (interactionStateKey) {
2339
+ console.log('[MSAL] handleMSALRedirect: Found interaction state key:', interactionStateKey);
2340
+ }
2341
+ } catch (cacheError) {
2342
+ console.error('[MSAL] handleMSALRedirect: Error checking cache:', cacheError);
2343
+ }
2344
+ return function () {
2345
+ if (hashParams.has('code')) {
2346
+ console.log('[MSAL] handleMSALRedirect: Attempting to extract account info from client_info...');
2347
+ return _catch(function () {
2348
+ var clientInfo = hashParams.get('client_info');
2349
+ return function () {
2350
+ if (clientInfo) {
2351
+ var decodedClientInfo = JSON.parse(atob(clientInfo));
2352
+ console.log('[MSAL] handleMSALRedirect: Decoded client_info:', decodedClientInfo);
2353
+ var allAccounts = instance.getAllAccounts();
2354
+ console.log('[MSAL] handleMSALRedirect: Accounts in cache:', allAccounts.length);
2355
+ var matchingAccount = allAccounts.find(function (acc) {
2356
+ return acc.homeAccountId === decodedClientInfo.uid || acc.username === decodedClientInfo.preferred_username || acc.username === decodedClientInfo.email;
2357
+ });
2358
+ if (!matchingAccount && allAccounts.length > 0) {
2359
+ matchingAccount = allAccounts[0];
2360
+ console.log('[MSAL] handleMSALRedirect: Using first available account');
2361
+ }
2362
+ return function () {
2363
+ if (matchingAccount) {
2364
+ console.log('[MSAL] handleMSALRedirect: Found matching account, trying silent token acquisition...');
2365
+ return _catch(function () {
2366
+ return Promise.resolve(instance.acquireTokenSilent({
2367
+ scopes: ["openid", "profile", "User.Read"],
2368
+ account: matchingAccount
2369
+ })).then(function (silentResult) {
2370
+ if (silentResult) {
2371
+ console.log('[MSAL] handleMSALRedirect: Got token via silent acquisition');
2372
+ _exit = true;
2373
+ return silentResult;
2374
+ }
2375
+ });
2376
+ }, function (silentError) {
2377
+ console.error('[MSAL] handleMSALRedirect: Silent acquisition failed:', silentError);
2378
+ });
2379
+ } else {
2380
+ console.log('[MSAL] handleMSALRedirect: No account in cache, creating account from client_info...');
2381
+ var accountInfo = {
2382
+ homeAccountId: decodedClientInfo.uid || decodedClientInfo.sub,
2383
+ environment: 'login.microsoftonline.com',
2384
+ tenantId: decodedClientInfo.tid,
2385
+ username: decodedClientInfo.preferred_username || decodedClientInfo.email,
2386
+ name: decodedClientInfo.name,
2387
+ localAccountId: decodedClientInfo.oid || decodedClientInfo.sub
2388
+ };
2389
+ console.log('[MSAL] handleMSALRedirect: Created account info:', accountInfo);
2390
+ var _account$accessToken$ = {
2391
+ account: accountInfo,
2392
+ accessToken: '',
2393
+ idToken: '',
2394
+ scopes: ["openid", "profile", "User.Read"],
2395
+ expiresOn: null,
2396
+ tenantId: decodedClientInfo.tid,
2397
+ uniqueId: decodedClientInfo.oid || decodedClientInfo.sub,
2398
+ tokenType: 'Bearer'
2399
+ };
2400
+ _exit = true;
2401
+ return _account$accessToken$;
2402
+ }
2403
+ }();
2404
+ }
2405
+ }();
2406
+ }, function (manualError) {
2407
+ console.error('[MSAL] handleMSALRedirect: Manual code processing failed:', manualError);
2408
+ });
2409
+ }
2410
+ }();
2411
+ }
2412
+ }();
2413
+ return _temp && _temp.then ? _temp.then(function (_result6) {
2414
+ return _exit ? _result6 : response;
2415
+ }) : _exit ? _temp : response;
2314
2416
  });
2315
2417
  });
2316
2418
  }, function (error) {
@@ -2700,15 +2802,25 @@ var BlockLogin = function BlockLogin(_ref) {
2700
2802
  }
2701
2803
  }, []);
2702
2804
  useEffect(function () {
2805
+ console.log('[MSAL] BlockLogin: useEffect mounted, checking for pending MSAL login...');
2703
2806
  var handleMSALLoginSuccess = function handleMSALLoginSuccess(event) {
2704
2807
  try {
2808
+ console.log('[MSAL] BlockLogin: Received msal-login-success event', event.detail);
2705
2809
  var _event$detail = event.detail,
2706
2810
  account = _event$detail.account,
2707
- accessToken = _event$detail.accessToken;
2811
+ _accessToken = _event$detail.accessToken;
2708
2812
  var _temp2 = function () {
2709
- if (account && accessToken) {
2813
+ if (account && _accessToken) {
2814
+ console.log('[MSAL] BlockLogin: Processing login from event...');
2710
2815
  localStorage.removeItem('MSAL_LOGIN_PENDING');
2711
- return Promise.resolve(processMSALLogin(account, accessToken)).then(function () {});
2816
+ localStorage.removeItem('MSAL_ACCOUNT');
2817
+ localStorage.removeItem('MSAL_ACCESS_TOKEN');
2818
+ sessionStorage.removeItem('MSAL_LOGIN_PENDING');
2819
+ sessionStorage.removeItem('MSAL_ACCOUNT');
2820
+ sessionStorage.removeItem('MSAL_ACCESS_TOKEN');
2821
+ return Promise.resolve(processMSALLogin(account, _accessToken)).then(function () {});
2822
+ } else {
2823
+ console.warn('[MSAL] BlockLogin: Event received but missing account or accessToken');
2712
2824
  }
2713
2825
  }();
2714
2826
  return Promise.resolve(_temp2 && _temp2.then ? _temp2.then(function () {}) : void 0);
@@ -2716,28 +2828,57 @@ var BlockLogin = function BlockLogin(_ref) {
2716
2828
  return Promise.reject(e);
2717
2829
  }
2718
2830
  };
2831
+ window.addEventListener('msal-login-success', handleMSALLoginSuccess);
2832
+ console.log('[MSAL] BlockLogin: Event listener registered');
2719
2833
  var pendingLogin = localStorage.getItem('MSAL_LOGIN_PENDING');
2834
+ var accountStr = localStorage.getItem('MSAL_ACCOUNT');
2835
+ var accessToken = localStorage.getItem('MSAL_ACCESS_TOKEN');
2836
+ if (!pendingLogin || pendingLogin !== 'true') {
2837
+ console.log('[MSAL] BlockLogin: Not found in localStorage, checking sessionStorage...');
2838
+ pendingLogin = sessionStorage.getItem('MSAL_LOGIN_PENDING');
2839
+ accountStr = sessionStorage.getItem('MSAL_ACCOUNT');
2840
+ accessToken = sessionStorage.getItem('MSAL_ACCESS_TOKEN');
2841
+ if (pendingLogin === 'true' && accountStr && accessToken) {
2842
+ console.log('[MSAL] BlockLogin: Found in sessionStorage, copying to localStorage...');
2843
+ localStorage.setItem('MSAL_ACCOUNT', accountStr);
2844
+ localStorage.setItem('MSAL_ACCESS_TOKEN', accessToken);
2845
+ localStorage.setItem('MSAL_LOGIN_PENDING', pendingLogin);
2846
+ }
2847
+ }
2848
+ console.log('[MSAL] BlockLogin: Pending login check:', pendingLogin);
2720
2849
  if (pendingLogin === 'true') {
2721
- var accountStr = localStorage.getItem('MSAL_ACCOUNT');
2722
- var accessToken = localStorage.getItem('MSAL_ACCESS_TOKEN');
2850
+ console.log('[MSAL] BlockLogin: Found pending login', {
2851
+ hasAccount: !!accountStr,
2852
+ hasAccessToken: !!accessToken
2853
+ });
2723
2854
  if (accountStr && accessToken) {
2724
2855
  try {
2725
2856
  var account = JSON.parse(accountStr);
2857
+ console.log('[MSAL] BlockLogin: Parsed account:', account.username);
2726
2858
  localStorage.removeItem('MSAL_LOGIN_PENDING');
2727
2859
  localStorage.removeItem('MSAL_ACCOUNT');
2728
2860
  localStorage.removeItem('MSAL_ACCESS_TOKEN');
2861
+ sessionStorage.removeItem('MSAL_LOGIN_PENDING');
2862
+ sessionStorage.removeItem('MSAL_ACCOUNT');
2863
+ sessionStorage.removeItem('MSAL_ACCESS_TOKEN');
2864
+ console.log('[MSAL] BlockLogin: Calling processMSALLogin...');
2729
2865
  processMSALLogin(account, accessToken);
2730
2866
  } catch (error) {
2731
- console.error('[MSAL] Error parsing stored account:', error);
2867
+ console.error('[MSAL] BlockLogin: Error parsing stored account:', error);
2732
2868
  localStorage.removeItem('MSAL_LOGIN_PENDING');
2733
2869
  localStorage.removeItem('MSAL_ACCOUNT');
2734
2870
  localStorage.removeItem('MSAL_ACCESS_TOKEN');
2871
+ sessionStorage.removeItem('MSAL_LOGIN_PENDING');
2872
+ sessionStorage.removeItem('MSAL_ACCOUNT');
2873
+ sessionStorage.removeItem('MSAL_ACCESS_TOKEN');
2735
2874
  }
2875
+ } else {
2876
+ console.warn('[MSAL] BlockLogin: Pending login flag set but missing account or token');
2736
2877
  }
2737
2878
  }
2738
- window.addEventListener('msal-login-success', handleMSALLoginSuccess);
2739
2879
  return function () {
2740
2880
  window.removeEventListener('msal-login-success', handleMSALLoginSuccess);
2881
+ console.log('[MSAL] BlockLogin: Event listener removed');
2741
2882
  };
2742
2883
  }, []);
2743
2884
  var googleLogin = useGoogleLogin({