AzureAD / azure-activedirectory-library-for-js

The code for ADAL.js and ADAL Angular has been moved to the MSAL.js repo. Please open any issues or PRs at the link below.
https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/dev/maintenance/adal-angular
Apache License 2.0
627 stars 372 forks source link

Infinite loop when unauthorized user tries to access page (authorization via adal-angular) #909

Closed donamj closed 3 years ago

donamj commented 4 years ago

I have a web based dashboard in react that authenticates user with adal-angular. Authorized users can access the page without any issue, but when a user is unauthorized, they get into an infinite loop with login page.

This was my initial code:


AuthContext.handleWindowCallback();

if ((window === window.parent) && window === window.top && !AuthContext.isCallback(window.location.hash)) {

  if (!AuthContext.getCachedToken(adalConfig.clientId) || !AuthContext.getCachedUser()) {
    AuthContext.login();
    }
  } 
  else 
  {
    AuthContext.acquireToken(adalConfig.endpoints.xyz, (message, token, msg) =>{
      if (token) {
        ReactDOM.render(
          //rendering code
        );
      }
    });
  }

After moving 'AuthContext.handleWindowCallback();' inside the first if condition, the user doesn't get in to infinite loop anymore. But the error page is not displayed as expected. They just get a blank page, but the url has the message that user is not authenticated.

How can I get a working error page when the user is not authenticated? Is there a way to access the error message programmatically?

jasonnutter commented 3 years ago

Closing, as I assume this has been resolved, and we highly recommend moving to MSAL.

If you have further questions, please open new issue at the MSAL.js repo: https://github.com/AzureAD/microsoft-authentication-library-for-js/issues