1

首先,当谈到 Nodejs/msal/azure b2c 时,我低于新手级别,我正在尝试理解流程。我从这里的示例开始:https : //azure.microsoft.com/en-us/resources/samples/active-directory-b2c-javascript-msal-singlepageapp/ 我正在使用 msal.js 和 azure ad b2c Node.js 应用程序。通过登录策略登录后,我将用户重定向到我有其他策略的不同页面。

//index.html

var clientApplication = new Msal.UserAgentApplication(applicationConfig.clientID, applicationConfig.authority, authCallback, { logger: logger, cacheLocation: 'localStorage' });
            function authCallback(errorDesc, token, error, tokenType) {
                if (token) {
                    logMessage(token + ":" + token);
                }
                else {
                    logMessage(error + ":" + errorDesc);
                }
            }

这是我在 index.html 中的 onclick 登录功能。'test(accessToken)' 方法重定向到后端节点 js 路由,我将 accesstoken 存储在会话变量中,并且该方法呈现到存储我的其他 b2c 策略的不同页面(test.ejs)。

function login() {

        clientApplication.loginPopup(applicationConfig.b2cScopes).then(function (idToken) {
            clientApplication.acquireTokenSilent(applicationConfig.b2cScopes).then(function (accessToken) {            
                test(accessToken);
            }, function (error) {
                clientApplication.acquireTokenPopup(applicationConfig.b2cScopes).then(function (accessToken) {
                    updateUI();
                }, function (error) {
                    logMessage("Error acquiring the popup:\n" + error);
                });
            })
        }, function (error) {
            logMessage("Error during login:\n" + error);
        });

    }

现在我的问题是如何在我的另一个视图(test.ejs)中检索 clientApplication Msal.UserAgentApplication 对象的当前状态以执行以下操作:

clientApplication.acquireTokenSilent(applicationConfig.b2cScopes).then(function (accessToken) {
                logMessage(accessToken);
            }
4

0 回答 0