首页 > 解决方案 > hVD(虚拟机)上的 Msal 库登录错误

问题描述

嗨,伙计们,我正在使用 MSAL 库进行 SSO 身份验证,它在本地计算机上完美运行,但是当我在同一台笔记本电脑上的 HVD(虚拟机)上尝试它时,即 HVD 具有不同的域
,我收到以下错误。

在此处输入图像描述

MSAL 版本 --> "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();
  }
}

我不知道我做错了什么,任何帮助将不胜感激。

谢谢

标签: angularazure-active-directorymsalmsal.js

解决方案


如果您使用的是第 3 方 IdP(如 ADFS 等),如果第 3 方 iDP 在域网络之外无法访问。这很可能发生。确保可以跨所有网络(域和非域网络)访问第 3 方 IdP


推荐阅读