[Fixed] Msal library login error on hVD(virtual machine)

Issue

Hi Guys I’m using MSAL library for SSO authentication which works flawlessly on the local machine ,But when I try it on a HVD(virtual machine)on the same laptop i.e. HVD has a different domain
I get this following error .

enter image description here

MSAL version –> "msal": "^1.4.5"

  profile;
  isIframe = false;
  loggedIn = false;
  private readonly _destroying$ = new Subject<void>();

  constructor(
    @Inject(MSAL_GUARD_CONFIG) private msalGuardConfig: MsalGuardConfiguration,
    private authService: MsalService,
    private msalBroadcastService: MsalBroadcastService,
    private http: HttpClient,
    private componentService: ComponentService
  ) { }

  ngOnInit(): void {
 
    this.authService.handleRedirectObservable().subscribe({
      next: (result: AuthenticationResult) => {
        this.getProfile();
      },
      error: (error) => console.log(error)
    });

    this.isIframe = window !== window.parent && !window.opener;
  }


  login() {
    if (this.authService.instance.getAllAccounts().length > 0) {
      console.log("already logged in");
      this.getProfile();  
    } else {
    if (this.msalGuardConfig.authRequest) {
      this.authService.loginRedirect({ ...this.msalGuardConfig.authRequest });
    } else {
      this.authService.loginRedirect();

    }
  }
  }

  getProfile() {
    this.http.get(GRAPH_ENDPOINT).subscribe(profile => {
      this.profile = profile;
      console.log(this.profile);
      this.componentService.setCorpIdFromProfile(profile);
    }, error => {
      console.log(error);
    });
  }
s
  logout() {
    this.authService.logout();
  }

  ngOnDestroy(): void {
    this._destroying$.next(null);
    this._destroying$.complete();
  }
}

I have no clue what I’m doing wrong any help would be appreciated .

Thank you

Solution

If you’re using the 3rd Party IdP (Like ADFS etc), if the 3rd party iDP is not accessible outside the domain network. This is likely to occur. Ensure the 3rd Party IdP is accessible across all the network (domain and non domain network)

Leave a Reply

(*) Required, Your email will not be published