我可以通过MSAL的msalObj.acquireTokenSilent()方法以静默方式获取id_token吗?

问题描述 投票:0回答:1

msalObj.acquireTokenSilent()设置触发器的各种方式有哪些,以便当存储在本地存储器中的id_token到期时被调用?我曾尝试通过setTimeout()调用该函数,但是随着页面刷新,setTimeout丢失了。有没有更有效的方法来实现上述逻辑?

javascript azure-active-directory single-page-application msal msal.js
1个回答
0
投票

我们总是以acquireTokenSilent开头从缓存中获取已登录用户的令牌。当acquireTokenSilent失败(令牌过期)时,我们将调用acquireTokenPopup

myMSALObj.acquireTokenSilent(requestObj).then(function (tokenResponse) {
         callMSGraph(graphConfig.graphMeEndpoint, tokenResponse.accessToken, graphAPICallback);
    }).catch(function (error) {
         console.log(error);
         // Upon acquireTokenSilent failure (due to consent or interaction or login required ONLY)
         // Call acquireTokenPopup(popup window)
         if (requiresInteraction(error.errorCode)) {
             myMSALObj.acquireTokenPopup(requestObj).then(function (tokenResponse) {
                 callMSGraph(graphConfig.graphMeEndpoint, tokenResponse.accessToken, graphAPICallback);
             }).catch(function (error) {
                 console.log(error);
             });
         }
    });
© www.soinside.com 2019 - 2024. All rights reserved.