Skip to content

User is required to re-login after browser restart despite using LocalStorage cache #8440

@prrami

Description

@prrami

Core Library

MSAL.js (@azure/msal-browser)

Core Library Version

^5.1.0

Wrapper Library

MSAL Angular (@azure/msal-angular)

Wrapper Library Version

^5.0.0

Public or Confidential Client?

Public

Description

I am using the MSAL Angular standalone sample application and have configured the cache location to LocalStorage.

However, even after a successful login, when I completely close the browser and relaunch it, the application prompts the user to log in again.

Based on my understanding, using BrowserCacheLocation.LocalStorage should persist the authentication state across browser sessions, and the user should not be required to log in again.

Error Message

Even after a successful login, when I completely close the browser and relaunch it, the application prompts the user to log in again.

MSAL Logs

No response

Network Trace (Preferrably Fiddler)

  • Sent
  • Pending

MSAL Configuration

auth: {
      clientId: environment.msalConfig.auth.clientId,
      authority: environment.msalConfig.auth.authority,
      redirectUri: 'http://localhost:4200',
      postLogoutRedirectUri: '/',
    },
    cache: {
      cacheLocation: BrowserCacheLocation.LocalStorage,
    },
    system: {
      allowPlatformBroker: false, // Disables WAM Broker
      loggerOptions: {
        loggerCallback,
        logLevel: LogLevel.Info,
        piiLoggingEnabled: false,
      },
    },

Relevant Code Snippets

export function MSALInstanceFactory(): IPublicClientApplication {
  return new PublicClientApplication({
    auth: {
      clientId: environment.msalConfig.auth.clientId,
      authority: environment.msalConfig.auth.authority,
      redirectUri: 'http://localhost:4200',
      postLogoutRedirectUri: '/',
    },
    cache: {
      cacheLocation: BrowserCacheLocation.LocalStorage,
    },
    system: {
      allowPlatformBroker: false, // Disables WAM Broker
      loggerOptions: {
        loggerCallback,
        logLevel: LogLevel.Info,
        piiLoggingEnabled: false,
      },
    },
  });
}

Reproduction Steps

To reproduce the issue, clone angular standalone sample :
https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/dev/samples/msal-angular-samples/angular-standalone-sample

I am using the same sample without any change. Just tried cacheLocation : BrowserCacheLocation.LocalStorage & BrowserCacheLocation.SessionStorage.

Expected Behavior

If cacheLocation : BrowserCacheLocation.LocalStorage is used in config then app should not ask user to re-login when they completely close the browser and relaunch it

Identity Provider

Entra ID (formerly Azure AD) / MSA

Browsers Affected (Select all that apply)

Chrome, Firefox, Edge

Regression

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug-unconfirmedA reported bug that needs to be investigated and confirmedmsal-angularRelated to @azure/msal-angular packagemsal-browserRelated to msal-browser packagepublic-clientIssues regarding PublicClientApplicationsquestionCustomer is asking for a clarification, use case or information.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions