如何通过 MSAL.js 使用 LocalStorage

How To Use LocalStorage with MSAL.js

如何将 LocalStorage 与 MSAL.js 一起使用?

根据this,有一个属性,cacheLocation,我需要设置为'localStorage'。

以下仍在使用sessionStorage:

var clientApplication = new Msal.UserAgentApplication(applicationConfig.clientID, applicationConfig.authority, function (errorDesc, token, error, tokenType) {
        // Called after loginRedirect or acquireTokenPopup
    });
clientApplication.cacheLocation = 'localStorage';

文档似乎有点过时了,请参阅此 GitHub 问题:https://github.com/AzureAD/microsoft-authentication-library-for-js/issues/58。要在 msal.js 的最新版本中设置缓存位置,请使用以下模式:

var userAgentApplication = new Msal.UserAgentApplication(applicationConfig.clientID,
     null, authCallback, { cacheLocation: 'localStorage' }); // to set it to localStorage