Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

localStorage as cache location leads to error in chrome #7496

Open
2 tasks
soallenspach opened this issue Jan 8, 2025 · 2 comments
Open
2 tasks

localStorage as cache location leads to error in chrome #7496

soallenspach opened this issue Jan 8, 2025 · 2 comments
Labels
b2c Related to Azure B2C library-specific issues bug-unconfirmed A reported bug that needs to be investigated and confirmed msal-browser Related to msal-browser package msal-react Related to @azure/msal-react Needs: Attention 👋 Awaiting response from the MSAL.js team public-client Issues regarding PublicClientApplications question Customer is asking for a clarification, use case or information.

Comments

@soallenspach
Copy link

soallenspach commented Jan 8, 2025

Core Library

MSAL.js (@azure/msal-browser)

Core Library Version

3.27.0

Wrapper Library

MSAL React (@azure/msal-react)

Wrapper Library Version

2.0.12

Public or Confidential Client?

Public

Description

I want the login state to be shared between tabs. At the moment I use sessionStorage as the cacheLocation. When I changed that to localStorage the login would not work anymore. The page is just blank and I get these errors in the console:

Screenshot 2025-01-06 at 18 24 10

I could only observe this issue in chrome, while other browsers work just fine.

Error Message

No response

MSAL Logs

No response

Network Trace (Preferrably Fiddler)

  • Sent
  • Pending

MSAL Configuration

{
    auth: {
        clientId: '1d15d630-8c8e-49f6-b4b1-a56e985366b8',
        authority: b2cPolicies.authorities.signUpSignIn.authority,
        knownAuthorities: [b2cPolicies.authorityDomain],
        redirectUri: window.location.origin,
        postLogoutRedirectUri: '/',
        navigateToLoginRequestUrl: true,
    },
    cache: {
        cacheLocation: 'localStorage',
        storeAuthStateInCookie: true,
    },
}

Relevant Code Snippets

Full config:

import { Configuration, LogLevel, PublicClientApplication } from '@azure/msal-browser';

const b2cPolicies = {
    authorities: {
        signUpSignIn: {
            authority: 'https://somedomain.b2clogin.com/somedomain.onmicrosoft.com/B2C_1A_SUSI',
        },
    },
    authorityDomain: 'https://somedomain.b2clogin.com',
};

export const msalConfig: Configuration = {
    auth: {
        clientId: '1d15d630-8c8e-49f6-b4b1-a56e985366b8',
        authority: b2cPolicies.authorities.signUpSignIn.authority,
        knownAuthorities: [b2cPolicies.authorityDomain],
        redirectUri: window.location.origin,
        postLogoutRedirectUri: '/',
        navigateToLoginRequestUrl: true,
    },
    cache: {
        cacheLocation: 'localStorage',
        storeAuthStateInCookie: true,
    },
    system: {
        loggerOptions: {
            logLevel: LogLevel.Error,
            loggerCallback: (level, message, containsPii) => {
                if (containsPii) {
                    return void 0;
                }

                switch (level) {
                    case LogLevel.Error:
                        return console.error(message);
                    case LogLevel.Info:
                        return console.info(message);
                    case LogLevel.Verbose:
                        return console.debug(message);
                    case LogLevel.Warning:
                        return console.warn(message);
                    default:
                        return console.log(message);
                }
            },
        },
    },
};

export const loginRequest = {
    scopes: {
        read: ['https://somedomain.onmicrosoft.com/web-api/WebApi.Read'],
        write: ['https://somedomain.onmicrosoft.com/web-api/WebApi.Write'],
        readWrite: [
            'https://somedomain.onmicrosoft.com/web-api/WebApi.Read',
            'https://somedomain.onmicrosoft.com/web-api/WebApi.Write',
        ],
    },
};

export const msalClientConfiguration = new PublicClientApplication(msalConfig);

Config consumer:

const MainContent: FC = () => {
    return (
        <MsalProvider instance={msalClientConfiguration}>
            <PortalRouterProvider />
        </MsalProvider>
    );
};

Reproduction Steps

  1. Apply the above configuration
  2. Change the urls and tokens in the configuration to working ones
  3. Login to the app

The app should then throw the errors shown in the above image. The user is not logged in, because not all the tokens were set in localStorage.

Expected Behavior

The user should be logged with the tokens stored in localStorage.

Identity Provider

Azure B2C Basic Policy

Browsers Affected (Select all that apply)

Chrome

Regression

No response

@soallenspach soallenspach added bug-unconfirmed A reported bug that needs to be investigated and confirmed question Customer is asking for a clarification, use case or information. labels Jan 8, 2025
@microsoft-github-policy-service microsoft-github-policy-service bot added the Needs: Attention 👋 Awaiting response from the MSAL.js team label Jan 8, 2025
@github-actions github-actions bot added b2c Related to Azure B2C library-specific issues msal-browser Related to msal-browser package msal-react Related to @azure/msal-react public-client Issues regarding PublicClientApplications labels Jan 8, 2025
@sameerag
Copy link
Member

Looks like a cache corruption issue. Have you cleared the cache and tried?

@microsoft-github-policy-service microsoft-github-policy-service bot added Needs: Author Feedback Awaiting response from issue author and removed Needs: Attention 👋 Awaiting response from the MSAL.js team labels Jan 13, 2025
@soallenspach
Copy link
Author

I did delete browser data, cleared local-, sessionStorage and cookies. The issue persists. My colleagues can reproduce the issue invariably.

@microsoft-github-policy-service microsoft-github-policy-service bot added Needs: Attention 👋 Awaiting response from the MSAL.js team and removed Needs: Author Feedback Awaiting response from issue author labels Jan 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
b2c Related to Azure B2C library-specific issues bug-unconfirmed A reported bug that needs to be investigated and confirmed msal-browser Related to msal-browser package msal-react Related to @azure/msal-react Needs: Attention 👋 Awaiting response from the MSAL.js team public-client Issues regarding PublicClientApplications question Customer is asking for a clarification, use case or information.
Projects
None yet
Development

No branches or pull requests

2 participants