【问题标题】:Using MSAL (Microsoft Authentication Library) with REDUX将 MSAL(Microsoft 身份验证库)与 REDUX 一起使用
【发布时间】:2017-07-20 00:15:53
【问题描述】:

我正在尝试使用 REDUX 中的 MSAL 库进行身份验证,但遇到了一些问题。当我制作一个仅反应的应用程序并做同样的事情时,我成功获得了访问令牌,但尝试在 REDUX 中使用它,尝试获取访问令牌时总是超时。

function Auth() {
    var userAgentApplication = new Msal.UserAgentApplication(*my app id*, null, function (errorDes, token, error, tokenType) {
    // this callback is called after loginRedirect OR acquireTokenRedirect (not used for loginPopup/aquireTokenPopup)
    });

    return new Promise((resolve, reject) => { 
        console.log('inside the promise');
        userAgentApplication.loginPopup(["user.read"]).then((token) => {
            console.log("Successfully got id token");
            console.log("first token: ", token);
            console.log(userAgentApplication.getUser().name);
          userAgentApplication.acquireTokenSilent(["user.read"]).then((token) => {
            resolve(token);
        }, function(error) {
            reject(error);
        });
    }, function (error) {
        reject(error);
    });
});
}

这是我的代码,但我总是收到以下错误令牌更新操作因超时而失败:null 当我尝试在纯 HTML 或仅响应应用程序中执行此操作时,它可以完美运行。任何形式的帮助将不胜感激。

【问题讨论】:

    标签: reactjs redux msal


    【解决方案1】:

    查看是否添加“catch”以及条件是否有助于识别问题。

    function Auth() {
      return new Promise((resolve, reject) => { 
        const userAgentApplication = new Msal.UserAgentApplication(*my app id*, null, function (errorDes, token, error, tokenType) {
          // this callback is called after loginRedirect OR acquireTokenRedirect (not used for loginPopup/aquireTokenPopup)
        });
    
        console.log('inside the promise');
        userAgentApplication.loginPopup(["user.read"])
        .then((token) => {
          console.log("Successfully got id token");
          console.log("first token: ", token);
          console.log(userAgentApplication.getUser().name);
    
          if (userAgentApplication.getUser()) {
            userAgentApplication.acquireTokenSilent(["user.read"])
            .then((token) => {
              resolve(token);
            })
            .catch((error) => {
              reject(error);
            });
          } else {
            reject("User not logged in");
          }
        })
        .catch((error) => {
          reject(error);
        });
      });
    }
    

    【讨论】:

      猜你喜欢
      • 2021-08-03
      • 1970-01-01
      • 2019-12-15
      • 1970-01-01
      • 1970-01-01
      • 2022-08-08
      • 1970-01-01
      • 1970-01-01
      • 2021-11-15
      相关资源
      最近更新 更多