acsi-core 0.9.22 → 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.
package/dist/index.js CHANGED
@@ -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 msalBrowser.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 msalBrowser.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;
@@ -2267,19 +2279,152 @@ var initializeMSAL = function initializeMSAL(clientId, redirectUri) {
2267
2279
  var handleMSALRedirect = function handleMSALRedirect(clientId, redirectUri) {
2268
2280
  try {
2269
2281
  if (!window.location.hash) {
2282
+ console.log('[MSAL] handleMSALRedirect: No hash found in URL');
2270
2283
  return Promise.resolve(null);
2271
2284
  }
2285
+ console.log('[MSAL] handleMSALRedirect: Hash found:', window.location.hash.substring(0, 100) + '...');
2272
2286
  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');
2287
+ var hasAccessToken = hashParams.has('access_token');
2288
+ var hasIdToken = hashParams.has('id_token');
2289
+ var hasError = hashParams.has('error');
2290
+ var hasCode = hashParams.has('code');
2291
+ var hasMSALParams = hasAccessToken || hasIdToken || hasError || hasCode;
2292
+ console.log('[MSAL] handleMSALRedirect: Hash params check:', {
2293
+ hasAccessToken: hasAccessToken,
2294
+ hasIdToken: hasIdToken,
2295
+ hasError: hasError,
2296
+ hasCode: hasCode,
2297
+ hasMSALParams: hasMSALParams
2298
+ });
2274
2299
  if (!hasMSALParams) {
2300
+ console.log('[MSAL] handleMSALRedirect: No MSAL parameters found in hash');
2275
2301
  return Promise.resolve(null);
2276
2302
  }
2277
2303
  return Promise.resolve(_catch(function () {
2304
+ console.log('[MSAL] handleMSALRedirect: Initializing MSAL with:', {
2305
+ clientId: clientId ? 'configured' : 'missing',
2306
+ redirectUri: redirectUri
2307
+ });
2278
2308
  return Promise.resolve(initializeMSAL(clientId, redirectUri)).then(function (instance) {
2279
- return instance ? Promise.resolve(instance.handleRedirectPromise()) : null;
2309
+ if (!instance) {
2310
+ console.error('[MSAL] handleMSALRedirect: Failed to initialize instance');
2311
+ return null;
2312
+ }
2313
+ console.log('[MSAL] handleMSALRedirect: Calling handleRedirectPromise...');
2314
+ var accounts = instance.getAllAccounts();
2315
+ console.log('[MSAL] handleMSALRedirect: Current accounts:', accounts.length);
2316
+ return Promise.resolve(instance.handleRedirectPromise()).then(function (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;
2416
+ });
2280
2417
  });
2281
2418
  }, function (error) {
2282
- console.error('[MSAL] Redirect handling error:', error);
2419
+ console.error('[MSAL] handleMSALRedirect: Error during processing:', error);
2420
+ if (error instanceof Error) {
2421
+ var _error$stack;
2422
+ console.error('[MSAL] handleMSALRedirect: Error details:', {
2423
+ name: error.name,
2424
+ message: error.message,
2425
+ stack: (_error$stack = error.stack) === null || _error$stack === void 0 ? void 0 : _error$stack.substring(0, 200)
2426
+ });
2427
+ }
2283
2428
  return null;
2284
2429
  }));
2285
2430
  } catch (e) {
@@ -2312,12 +2457,18 @@ var MSALRedirectHandler = function MSALRedirectHandler() {
2312
2457
  React.useLayoutEffect(function () {
2313
2458
  var handleRedirect = function handleRedirect() {
2314
2459
  try {
2460
+ var alreadyProcessed = localStorage.getItem('MSAL_LOGIN_PENDING');
2461
+ if (alreadyProcessed === 'true') {
2462
+ console.log('[MSAL] RedirectHandler: Already processed by pre-init, skipping');
2463
+ return Promise.resolve();
2464
+ }
2315
2465
  if (!isMSALRedirect()) {
2466
+ console.log('[MSAL] RedirectHandler: No MSAL redirect detected');
2316
2467
  return Promise.resolve();
2317
2468
  }
2318
- console.log('[MSAL] Redirect detected, processing...');
2319
- console.log('[MSAL] Hash:', window.location.hash);
2320
- console.log('[MSAL] Full URL:', window.location.href);
2469
+ console.log('[MSAL] RedirectHandler: Redirect detected, processing...');
2470
+ console.log('[MSAL] RedirectHandler: Hash:', window.location.hash);
2471
+ console.log('[MSAL] RedirectHandler: Full URL:', window.location.href);
2321
2472
  var _temp = _catch(function () {
2322
2473
  return Promise.resolve(handleMSALRedirect()).then(function (response) {
2323
2474
  if (response && response.account) {
@@ -2650,15 +2801,25 @@ var BlockLogin = function BlockLogin(_ref) {
2650
2801
  }
2651
2802
  }, []);
2652
2803
  React.useEffect(function () {
2804
+ console.log('[MSAL] BlockLogin: useEffect mounted, checking for pending MSAL login...');
2653
2805
  var handleMSALLoginSuccess = function handleMSALLoginSuccess(event) {
2654
2806
  try {
2807
+ console.log('[MSAL] BlockLogin: Received msal-login-success event', event.detail);
2655
2808
  var _event$detail = event.detail,
2656
2809
  account = _event$detail.account,
2657
- accessToken = _event$detail.accessToken;
2810
+ _accessToken = _event$detail.accessToken;
2658
2811
  var _temp2 = function () {
2659
- if (account && accessToken) {
2812
+ if (account && _accessToken) {
2813
+ console.log('[MSAL] BlockLogin: Processing login from event...');
2660
2814
  localStorage.removeItem('MSAL_LOGIN_PENDING');
2661
- return Promise.resolve(processMSALLogin(account, accessToken)).then(function () {});
2815
+ localStorage.removeItem('MSAL_ACCOUNT');
2816
+ localStorage.removeItem('MSAL_ACCESS_TOKEN');
2817
+ sessionStorage.removeItem('MSAL_LOGIN_PENDING');
2818
+ sessionStorage.removeItem('MSAL_ACCOUNT');
2819
+ sessionStorage.removeItem('MSAL_ACCESS_TOKEN');
2820
+ return Promise.resolve(processMSALLogin(account, _accessToken)).then(function () {});
2821
+ } else {
2822
+ console.warn('[MSAL] BlockLogin: Event received but missing account or accessToken');
2662
2823
  }
2663
2824
  }();
2664
2825
  return Promise.resolve(_temp2 && _temp2.then ? _temp2.then(function () {}) : void 0);
@@ -2666,28 +2827,57 @@ var BlockLogin = function BlockLogin(_ref) {
2666
2827
  return Promise.reject(e);
2667
2828
  }
2668
2829
  };
2830
+ window.addEventListener('msal-login-success', handleMSALLoginSuccess);
2831
+ console.log('[MSAL] BlockLogin: Event listener registered');
2669
2832
  var pendingLogin = localStorage.getItem('MSAL_LOGIN_PENDING');
2833
+ var accountStr = localStorage.getItem('MSAL_ACCOUNT');
2834
+ var accessToken = localStorage.getItem('MSAL_ACCESS_TOKEN');
2835
+ if (!pendingLogin || pendingLogin !== 'true') {
2836
+ console.log('[MSAL] BlockLogin: Not found in localStorage, checking sessionStorage...');
2837
+ pendingLogin = sessionStorage.getItem('MSAL_LOGIN_PENDING');
2838
+ accountStr = sessionStorage.getItem('MSAL_ACCOUNT');
2839
+ accessToken = sessionStorage.getItem('MSAL_ACCESS_TOKEN');
2840
+ if (pendingLogin === 'true' && accountStr && accessToken) {
2841
+ console.log('[MSAL] BlockLogin: Found in sessionStorage, copying to localStorage...');
2842
+ localStorage.setItem('MSAL_ACCOUNT', accountStr);
2843
+ localStorage.setItem('MSAL_ACCESS_TOKEN', accessToken);
2844
+ localStorage.setItem('MSAL_LOGIN_PENDING', pendingLogin);
2845
+ }
2846
+ }
2847
+ console.log('[MSAL] BlockLogin: Pending login check:', pendingLogin);
2670
2848
  if (pendingLogin === 'true') {
2671
- var accountStr = localStorage.getItem('MSAL_ACCOUNT');
2672
- var accessToken = localStorage.getItem('MSAL_ACCESS_TOKEN');
2849
+ console.log('[MSAL] BlockLogin: Found pending login', {
2850
+ hasAccount: !!accountStr,
2851
+ hasAccessToken: !!accessToken
2852
+ });
2673
2853
  if (accountStr && accessToken) {
2674
2854
  try {
2675
2855
  var account = JSON.parse(accountStr);
2856
+ console.log('[MSAL] BlockLogin: Parsed account:', account.username);
2676
2857
  localStorage.removeItem('MSAL_LOGIN_PENDING');
2677
2858
  localStorage.removeItem('MSAL_ACCOUNT');
2678
2859
  localStorage.removeItem('MSAL_ACCESS_TOKEN');
2860
+ sessionStorage.removeItem('MSAL_LOGIN_PENDING');
2861
+ sessionStorage.removeItem('MSAL_ACCOUNT');
2862
+ sessionStorage.removeItem('MSAL_ACCESS_TOKEN');
2863
+ console.log('[MSAL] BlockLogin: Calling processMSALLogin...');
2679
2864
  processMSALLogin(account, accessToken);
2680
2865
  } catch (error) {
2681
- console.error('[MSAL] Error parsing stored account:', error);
2866
+ console.error('[MSAL] BlockLogin: Error parsing stored account:', error);
2682
2867
  localStorage.removeItem('MSAL_LOGIN_PENDING');
2683
2868
  localStorage.removeItem('MSAL_ACCOUNT');
2684
2869
  localStorage.removeItem('MSAL_ACCESS_TOKEN');
2870
+ sessionStorage.removeItem('MSAL_LOGIN_PENDING');
2871
+ sessionStorage.removeItem('MSAL_ACCOUNT');
2872
+ sessionStorage.removeItem('MSAL_ACCESS_TOKEN');
2685
2873
  }
2874
+ } else {
2875
+ console.warn('[MSAL] BlockLogin: Pending login flag set but missing account or token');
2686
2876
  }
2687
2877
  }
2688
- window.addEventListener('msal-login-success', handleMSALLoginSuccess);
2689
2878
  return function () {
2690
2879
  window.removeEventListener('msal-login-success', handleMSALLoginSuccess);
2880
+ console.log('[MSAL] BlockLogin: Event listener removed');
2691
2881
  };
2692
2882
  }, []);
2693
2883
  var googleLogin = google.useGoogleLogin({