首页 > 解决方案 > 在 Azure 上托管 AD b2c 的 aurelia 应用程序,重定向回登录 Edge 和 Firefox

问题描述

我有一个使用 Msal JavaScript 库通过 Azure B2C 进行身份验证的 Aurelia 应用程序。
它托管在 Azure 应用服务上,在 Chrome 中运行良好,但在 Edge 和 Firefox 中,当应用启动时,我被重定向回 Azure B2C 登录屏幕。

这是我的 main.ts:

aurelia.start().then((a) => {
  let auth: Auth = a
    .container
    .get(Auth);

  setTimeout(() => {
    auth
      .isAuthenticated()
      .then(() => {
        a.setRoot();
        return;
      })
      .catch((e) => {
        auth.login();
      });
  }, 2000);

这是 isAuthenticated 方法:

isAuthenticated() {
  return new Promise((resolve, reject) => {
    let cachedUser = this
    .clientApplication
    .getUser();

  if (cachedUser == null) {
    this.authenticated = false;
    return reject();
  }

  let token = this._getTokentInternal();
  if (token) {
    this.authenticated = true;
    return resolve();
  } else {

    return reject();
  }
 });
}

当我使用 Aurelia cli 在 Localhost 上运行时,这工作正常,所有三个浏览器都可以工作,但是当我发布到 azure 时,即使 azure 登录成功,Edge 和 Firefox 也会不断从 isAuthenticated 方法收到拒绝的承诺响应,这会强制重定向到登录。
有没有其他人遇到过这个问题?
谁能指出我正确的方向来解决这个问题?

标签: firefoxaureliamicrosoft-edgeazure-ad-b2cmsal

解决方案


似乎我的登录方法清除了 window.location.hash,我删除了该行,它现在似乎正在工作


推荐阅读