microsoft-authentication-library-for-js: The token request could not be fetched from the cache correctly. Error Detail: TypeError: Cannot read property 'replace' of null

Please follow the issue template below. Failure to do so will result in a delay in answering your question.

Library

  • msal@1.x.x or @azure/msal@1.x.x
  • @azure/msal-browser@2.6.1
  • @azure/msal-node@1.x.x
  • @azure/msal-react@1.x.x
  • @azure/msal-angular@0.x.x
  • @azure/msal-angular@1.x.x
  • @azure/msal-angular@2.x.x
  • @azure/msal-angularjs@1.x.x

Important: Please fill in your exact version number above, e.g. msal@1.1.3.

Framework

React

Description

Seeing some logs in our application showing the error The token request could not be fetched from the cache correctly. Error Detail: TypeError: Cannot read property ‘replace’ of null errorCode: token_request_cache_error

If it gives a clue, a user that faced this error was also facing error: AADSTS501481: The Code_Verifier does not match the code_challenge supplied in the authorization request. Could the two be related?

Error Message

The token request could not be fetched from the cache correctly. Error Detail: TypeError: Cannot read property ‘replace’ of null

Security

  • Is this issue security related?

Regression

  • Did this behavior work before? Version: Not sure…

MSAL Configuration

    const browser = Bowser.getParser(window.navigator.userAgent);
    const isIEOrOldEdge =
      browser.satisfies({ edge: "<79" }) || browser.getBrowserName().toLowerCase() === "internet explorer";
    const publicClientApp = new PublicClientApplication({
      auth: {
        clientId: this.clientId,
        authority: this.authority,
        redirectUri: this.loginRedirectUri,
        postLogoutRedirectUri: this.postLogoutRedirectUri
      },
      cache: {
        cacheLocation: "localStorage",
        storeAuthStateInCookie: isIEOrOldEdge // https://github.com/AzureAD/microsoft-authentication-library-for-js/issues/1188#issuecomment-634281307
      },
      system: {
        tokenRenewalOffsetSeconds: 60,
        iframeHashTimeout: 30000, // iframe is used to refresh the refresh_token as it has a 24h lifetime
        loggerOptions: {
          loggerCallback: MsalAuthContext.msalLoggerCallback,
          piiLoggingEnabled: false,
          logLevel: LogLevel.Verbose
        }
      }
    });
    const handleRedirectPromise = publicClientApp
      .handleRedirectPromise()
      .then(response => {
        this.account = response ? response.account : this.getAccount();
        if (!this.account) {
          CoreLogger.trackEvent(TelemetryEventName.Core_MSALAuthContext_login);
          return this.publicClientApp.loginRedirect({
            scopes: this.scopes,
            authority: this.authority,
            extraQueryParameters: this.safeRolloutQueryParams,
            redirectStartPage: returnUrl
          });
        } else {
          this.setTenantId(this.account.tenantId);
        }
        return undefined;
      })
      .catch(error => {
        if (error instanceof AuthError) {
          this.trackError(error);
        }
        this.loginToTenantRedirect(MsalAuthContext.defaultTenantId);
      });
    return { publicClientApp, handleRedirectPromise };

Reproduction steps

// Provide relevant code snippets here.
// For Azure B2C issues, please include your policies.

Expected behavior

No TypeError

Browsers/Environment

  • Chrome
  • Firefox
  • Edge
  • Safari
  • IE
  • Other (Please add browser name here)

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 16 (7 by maintainers)

Most upvoted comments

@hectormmg thanks for following up, we have upgraded our msal-browser version from 2.6.1 to 2.11.0. As of right now, we do not see any instances of “token_request_cache_error” for users running v2.11.0. So far it looks good! I’ll let you know if I do see the error again in v2.11.0 Cheers!

@thoo1 Since I have not been able to reproduce this I can’t say for sure but we recently made some improvements to how the temporary cache works during a request which may solve this issue. We plan to release 2.10.1 next week, I’d give that a shot and if it’s still happening reach out to me on Teams and we can try to debug.

@thoo1 In this case it’s specifically complaining about the codeVerifier being either wrong or missing. Which is likely also due to the fact that you seem to be having issues getting the cached request. I believe all of these issues share the same root cause.