2

早上好,我正在使用 MSAL JS 对使用 REACT 开发的 PWA 应用程序中的用户进行身份验证。有时登录效果很好,将用户重定向到应用程序的主页。其他时候登录弹出窗口打开,用户插入他们的登录,但登录过程失败并出现以下错误:

BrowserAuthError: hash_empty_error: Hash value cannot be processed because it is empty. 
Please verify that your redirectUri is not clearing the hash. 
Given Url: https://siteinspection-dev.azurewebsites.net/login
    at t [as constructor] (https://siteinspection-dev.azurewebsites.net/static/js/6.21bce126.chunk.js:2:163177)
    at new t (https://siteinspection-dev.azurewebsites.net/static/js/6.21bce126.chunk.js:2:266493)
    at Function.t.createEmptyHashError (https://siteinspection-dev.azurewebsites.net/static/js/6.21bce126.chunk.js:2:266991)
    at https://siteinspection-dev.azurewebsites.net/static/js/6.21bce126.chunk.js:2:304999

这是 MSAL 的配置:

    export const MSAL_CONFIG: Configuration = {
      auth: {
        clientId: AzureActiveDirectoryAppClientId,
        authority: `https://login.microsoftonline.com/${AzureTenantId}`,
        knownAuthorities: [],
        redirectUri: window.location.origin
      },
      cache: {
        cacheLocation: "sessionStorage",
        storeAuthStateInCookie: true,
      },
      system: {
        loggerOptions: {
          loggerCallback: (level, message, containsPii) => {
            if (containsPii) {
              return;
            }
            switch (level) {
              case LogLevel.Error:
                console.error(message);
                return;
              case LogLevel.Info:
                console.info(message);   // when fails this message appears: "[Thu, 15 Apr 2021 07:06:24 GMT] :  : @azure/msal-browser@2.13.0 : Info - Emitting event: msal:loginFailure"
                return;
              case LogLevel.Verbose:
                console.debug(message);
                return;
              case LogLevel.Warning:
                console.warn(message);
                return;
            }
          },
        },
      },
    };

这是实现的登录方法:

private myMSALObj: PublicClientApplication = new PublicClientApplication(
    MSAL_CONFIG
  );

this.loginRequest = {
      scopes: [],
      prompt: "select_account",
      redirectUri: BaseUrl
    };

this.myMSALObj
        .loginPopup(this.loginRequest)
        .then((resp: AuthenticationResult) => {
          console.log(resp);
        })
        .catch((err) => {
          console.log(err);   // here the error showed before
        });

登录错误后,使用浏览器数据清理刷新页面允许用户正确登录。我不明白是什么导致了这个问题,任何人都可以帮助我吗?谢谢。

4

1 回答 1

1

解决了将重定向 url 更改为相同的登录 url - 没有更多问题。

于 2021-04-30T13:58:56.947 回答