Navigating to Null in Internet Explorer 11 (in certain versions) following a successful login using AAD 2 Authentication on Angular 2

Experiencing a Redirect Issue in Internet Explorer 11 (in certain versions) Following Successful Authentication with AAD 2 in Angular 2.

Functioning as Expected in Chrome and Other Browsers.

When accessing the home page at http://localhost:1234, it should redirect to the AAD 2 authentication login page. After logging in successfully, it should redirect back to the same home page i.e. http://localhost:1234. However, it is incorrectly redirecting to http://localhost:1234/null. This issue seems to only occur on Internet Explorer 11, while other browsers are functioning properly.

If you have any insight or suggestions on how to resolve this issue, your assistance would be greatly appreciated.

import { Inject, Injectable } from '@angular/core';
import { Http } from '@angular/http';
import { Observable } from 'rxjs/Rx';
import { UserAgentApplication } from 'msalx';
import { Router } from '@angular/router';
import { AppConfig } from '../app.config';

@Injectable()
export class LoginService 
{
  private config: Object = null;
  private Token: any;
  public getConfig() 
  {
    return this.config;
  }
  public getToken() 
  {
    return this.Token;
  }

  public clientID = this.con.getClientID();
  public graphAPIScopes = [this.con.getClientID()];
  //["https://graph.microsoft.com/user.read"];
  public redirectUri = location.origin

 constructor(private router: Router, private con: AppConfig) {
 }

 public clientApplication = new UserAgentApplication
 (
    this.clientID, null,(errorDesc, token, error, tokenType) => {
      // Called after loginRedirect or acquireTokenPopup
      if (tokenType == "id_token") {this.callTokenApi();
      localStorage.setItem('User', 
        JSON.stringify(this.clientApplication.getUser()));
        this.logMessage("User logged-in");
      } else {
        this.logMessage("Error during login:\n" + error);
      }
  });

  state = {
    isLoggedIn: false,
    message: ""
  }

 logMessage(message: string) {
 }

 loginRedirect(sessionTimedOut: boolean) {
   if (sessionTimedOut) {
     this.clearUserInfoAndRedirectToLoginPage();
   }

   var GetState = this.clientApplication.isCallback(window.location.hash);
   if (!GetState) {
     if (!this.clientApplication.getUser()) {
       this.clearUserInfoAndRedirectToLoginPage();
     }
   }
}

clearUserInfoAndRedirectToLoginPage() {
  localStorage.setItem('User', null);
  localStorage.setItem('Token', null);
  this.clientApplication.loginRedirect(this.graphAPIScopes);
}

logout() {
  this.clientApplication.logout();
}

loginPopup() {
  this.clientApplication.loginPopup
  (this.graphAPIScopes).then ((idToken) => {
     this.clientApplication.acquireTokenSilent(this.graphAPIScopes).
     then ((accessToken) => {
       var userName = this.clientApplication.getUser().name;
       this.logMessage("User '" + userName + "' logged-in");
     }, 
     (error) => {this.clientApplication.
       acquireTokenPopup(this.graphAPIScopes).
         then((accessToken) => {
           var userName = this.clientApplication.getUser().name;
           this.logMessage("User '" + userName + "' logged-in");
         }, (error) => {
           this.logMessage("Error acquiring the popup:\n" + error);
         });
       })
     }, (error) => {
      this.logMessage("Error during login:\n" + error);
   });
 }
 callTokenApi() {
    this.clientApplication.
    acquireTokenSilent(this.graphAPIScopes).then   ((accessToken) => {
        localStorage.setItem('Token', accessToken);
        window.location.reload();
    }, (error) => {
    })
  }
  callApiWithAccessToken(accessToken: string) {
    accessToken;
  }
}

Answer №1

It appears that the issue you are experiencing is related to Internet Explorer running in a protected mode, causing complications with Msal.js compatibility.

To resolve this issue and be able to run your application locally, it is necessary to disable Protected Mode. Follow these steps:

  1. Access Internet Explorer Settings by clicking on the gear icon
  2. Navigate to Internet Options | Security, select the Internet zone, and deselect "Enable Protected Mode (requires restarting Internet Explorer)". Despite the warning about decreased computer protection, proceed with acknowledgment

    https://i.sstatic.net/1To0m.png

  3. Restart Internet Explorer

  4. Now you can run and debug your application without issues
  5. After you have finished, restore Internet Explorer security settings to default by going to IE Settings | Internet Options | Security | Reset all zones

Note from Microsoft (paraphrased):

If you deploy your application in a production environment (such as Azure Web apps), it should function properly as long as the user accepts popups. Our testing was conducted using Internet Explorer 11.


For a more comprehensive explanation, please refer to this MSAL GitHub page

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for activating automatic building of packages when utilizing pnpm install?

Our unique project is utilizing a combination of pnpm, workspace, and typescript in adherence to the monorepo standard. Upon cloning the repository, we execute a pnpm install command to download dependencies and establish links between local packages. De ...

How to manage trailing slashes in Angular2urlpatterns

My problem involves trailing slashes being removed by Angular2. I've configured my dotnet core application to include them, but they disappear once the JavaScript is loaded. Can Angular2 preserve trailing slashes? (My client insists on it, so please ...

Validation of Angular 5 forms for detecting duplicate words

I need help with a basic form that has one input. My requirement is to validate that the user does not input an existing word. If the user does enter an existing word, I would like to display a message below the input field saying "This word already exis ...

Utilizing various settings using `.env` files in NodeJs

As I work on building a backend in nodejs, one of the key considerations is how to incorporate an environment configuration into the project. I am envisioning a structure where there is a /config folder housing my envparser.ts (still brainstorming a catchi ...

Combining Angular with X3D to create a seamless integration, showcasing a minimalist representation of a box

I am brand new to web development, and I am feeling completely overwhelmed. Recently, I decided to follow the Angular tutorial by downloading the Angular Quickstart from this link: https://github.com/angular/quickstart. My goal was to add a simple x3d ele ...

Encountering a compilation error while trying to utilize a union type in a function parameter within an

As stated on https://www.typescriptlang.org/docs/handbook/declaration-files/do-s-and-don-ts.html, it is recommended to utilize multiple types for a parameter in a function (refer to the union part) /* OK */ interface Moment { utcOffset(): number; ...

What are the best practices for implementing MapLabel in an Angular project?

I need help displaying text on top of multiple polygons on a map. I've heard that Map Label can help with this, but I'm having trouble implementing it and can't find any NPM resources. Here is the Stack Blitz URL for reference: https://stac ...

Experiencing compatibility issues with NextAuth and Prisma on Netlify when using NextJS 14

While the website is functioning correctly on development and production modes, I am encountering issues when testing it on my local machine. After deploying to Netlify, the website fails to work as expected. [There are errors being displayed in the conso ...

Interacting with hyperlinks within a changing table using Selenium in C#

TABLE ISSUES I am facing a challenge with my table as I need to click on the "Review Vacancy" link but I do not know how to accomplish this task. It would be greatly appreciated if someone could provide me with some code that I can review and understand. ...

The Identity Column's maximum value for Int32 boundaries

As I work on creating a website, I have been considering the use of Identity Column to store IDs in some of my tables. Currently, I have classes with IDs decorated with Int32 to hold values retrieved from the database. My concern is that as the site grows ...

Bootstrap: Arrange multiple images horizontally within a row

I am trying to design a list item for a game that includes a background, an iconholder with an icon, a title, description, and up to three resources. I have been experimenting with Bootstrap and attempted using a container-fluid with an inner row but the i ...

Instructions for filtering a JSON array based on a specific property and retrieving all corresponding details in a systematic manner

Looking to filter a JSON array in stages. Take this example: [ { "env": "ENG", "details": [ { "Id": 3, "Name": "TestA", ...

The Web API controller is able to successfully download a CSV file, however, it is facing compatibility issues

I have set up a basic web api controller that can be accessed through a URL to download a .csv file. Now, I am attempting to implement some jQuery so that when a button is clicked, the file will be downloaded. However, I seem to be missing a crucial elemen ...

Contrasting C# arrays with C++ arrays and the role of the garbage collector

As a C++ programmer delving into C#, I am facing a concern regarding array declaration. In C#, one must use the New operator to declare an array, but won't this trigger the involvement of the garbage collector? For instance, if I have a function that ...

Dealing with name conflicts in Typescript when using multiple interface inheritance

Is it possible to securely implement two interfaces in Typescript that both have a member of the same name? Can this be achieved? For example: interface IFace1 { name: string; } interface IFace2 { name: string; } class SomeClass implements IFace ...

Encountered an error while trying to access the 'touched' property of undefined within Angular6 reactive forms

When attempting to validate my page, I encountered an error stating 'Cannot read property 'touched' of undefined'. Can someone please assist me with this code? Also, feel free to correct any mistakes you may find. Here is the HTML code ...

Could not generate project graph for Nx (directories listed below do not have a specified name for their projects)

Currently, I'm in the process of setting up a monorepo for a project that utilizes Angular and NestJS as its tech stack. I used the following command to kickstart the repository: npx create-nx-workspace@latest university_archive --preset=angular In a ...

I am experiencing difficulties with TypeORM connecting to my Postgres database

Currently, I am utilizing Express, Postgres, and TypeORM for a small-scale website development project. However, I am encountering challenges when it comes to establishing a connection between TypeORM and my Postgres database. index.ts ( async ()=>{ ...

Additional details for every term in the rich text box- Connection betwixt rich text box and SQL database

I'm working with a richtextbox in my project where the text is generated by combining words from a specific table. The table contains columns for 'word', 'translate' and 'id'. What I want to achieve is that when a user h ...

Error: getMessage function is undefined

Currently, I am in the process of creating a messaging feature that is reminiscent of Facebook. To achieve this, I am utilizing ajax with jQuery along with an ASMX web service to deliver HTML content to the client. One issue I have encountered is that my l ...