标签: msal-angular

错误:选择器“app-redirect”与任何元素都不匹配,我正在尝试升级到 MSAL v2 并获取刷新令牌

[控制台错误

\n

\r\n
\r\n
import { BrowserModule } from \'@angular/platform-browser\';\nimport { NgModule } from \'@angular/core\';\nimport { SharedModule } from \'./shared/shared.module\'\n\nimport { AppRoutingModule } from \'./app-routing.module\';\nimport { AppComponent } from \'./app.component\';\nimport { HttpClientModule, HTTP_INTERCEPTORS } from \'@angular/common/http\';\nimport { BrowserAnimationsModule } from \'@angular/platform-browser/animations\';\n\nimport { MatSidenavModule } from \'@angular/material/sidenav\';\nimport { HeaderComponent } from \'./header/header.component\';\nimport { MatProgressBarModule } from \'@angular/material/progress-bar\';\nimport { MatProgressSpinnerModule } from \'@angular/material/progress-spinner\';\nimport {MatExpansionModule} from \'@angular/material/expansion\';\n\nimport { HTTPRequestInterceptorProviders } from \'src/app/helpers/http-interceptor\';\nimport { MatSnackBarModule } from \'@angular/material/snack-bar\';\nimport { ServiceWorkerModule } from \'@angular/service-worker\';\nimport { …
Run Code Online (Sandbox Code Playgroud)

angular msal-angular

13
推荐指数
1
解决办法
1万
查看次数

Ionic 和 MSAL 身份验证

我有一个 Ionic 应用程序需要在 Azure 中进行身份验证,因此我按照本教程安装了 MSAL: https: //learn.microsoft.com/en-us/graph/tutorials/angular

它的工作原理就像“离子服务”的魅力,但当我在设备中运行它时,当我尝试登录 Azure 时它会崩溃。我认为这是因为 MSAL 显示的弹出窗口在 Ionic 中不允许登录。

所以我的第一次尝试是将loginPopup() 调用更改为loginRedirect()。所以我删除了这段代码:

async signIn(): Promise<void> {
  const result = await this.msalService
    .loginPopup(OAuthSettings)
    .toPromise()
    .catch((reason) => {
      this.alertsService.addError('Login failed',
        JSON.stringify(reason, null, 2));
    });

  if (result) {
    this.msalService.instance.setActiveAccount(result.account);
    this.authenticated = true;
    this.user = await this.getUser();
  }
}
Run Code Online (Sandbox Code Playgroud)

我添加了这个新的(基于https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-browser/docs/errors.md):

async signIn(): Promise<void> {
  await this.msalService.instance.handleRedirectPromise();

  const accounts = this.msalService.instance.getAllAccounts();
  if (accounts.length === 0) {
    // No user signed in
    this.msalService.instance.loginRedirect();
  }
}
Run Code Online (Sandbox Code Playgroud)

但这样,用户信息不会保存,因为我没有“结果”来处理或调用 setActiveAccount(result)。即使在“离子服务”中它也不起作用,所以我放弃了这种方法。

第二种方法是在寻找可能的解决方案两天后,在 InAppBrowser …

azure-active-directory ionic-framework azure-ad-msal ionic-native msal-angular

7
推荐指数
2
解决办法
6907
查看次数

本地主机的 Msal Angular HTTP 拦截器未附加令牌

我正在尝试调用本地主机 API 并在标头上附加不记名令牌。它应该由 msal-angular 自动完成。现在,我已将 localhost API 路由添加到 protectedResourceMap,但标头中没有不记名令牌。尝试添加 jsonplaceholder 和 graph.microsoft 以对其进行 HTTP post 调用,并且可以正常工作。唯一的问题是当我尝试对 localhost API 进行 HTTP 调用时。

我正在使用:

@azure/msal-browser@2.12.0
@azure/msal-angular@2.0.0-beta.0
Run Code Online (Sandbox Code Playgroud)

我在 app.module.ts 中使用了工厂提供程序作为拦截器。

export function MSALInterceptorConfigFactory(): MsalInterceptorConfiguration {
  const protectedResourceMap = new Map<string, Array<string>>();
   protectedResourceMap.set('https://graph.microsoft.com/v1.0/me', [
     'user.read',
   ]);

  protectedResourceMap.set('http://localhost:5000/api/add', [
    'api://custom api consent'
  ]);

   protectedResourceMap.set('https://jsonplaceholder.typicode.com/', [
     'api://custom api consent'
   ]);

  return {
    interactionType: InteractionType.Redirect,
    protectedResourceMap,
  };
}
Run Code Online (Sandbox Code Playgroud)

它也在 app.module.ts 中注册

    providers: [
        {
          provide: HTTP_INTERCEPTORS,
          useClass: MsalInterceptor,
          multi: true,
        },
        {
          provide: MSAL_INSTANCE,
          useFactory: MSALInstanceFactory,
        }, …
Run Code Online (Sandbox Code Playgroud)

angular-http-interceptors angular msal-angular

6
推荐指数
1
解决办法
1290
查看次数

模块中的 Angular APP_INITIALIZER 无法正常工作

我有 auth 模块,它在应用程序初始化程序之前导入并设置 msal 配置。我使用 APP_INITIALIZER 阻止应用程序的初始化并获取 MSAL-ANGULAR 的配置。该问题仅存在于 Firefox 中。该应用程序在 Chrome、Egde、Safari 上运行得非常好,但在 Firefox 上却不行。在与 Firefox 不同的所有其他浏览器上,APP_INITIALIZER 会阻止启动,直到加载 config.json。我注意到 MSALInstanceFactory 在初始化器工厂函数之前被调用。

我在 auth.module 中使用的代码

export function initializerFactory(env: ConfigService, configUrl: string): any {
// APP_INITIALIZER, angular doesnt starts application untill it completes loading config.json
  const promise = env.init(configUrl).then(val => {});
  return () => promise;
}

export function loggerCallback(logLevel: LogLevel, message: string): void {
   console.log(message);
}

export function MSALInstanceFactory(configService: ConfigService, constant: SecurityConstants): IPublicClientApplication {
   return new PublicClientApplication({
      auth: {
         clientId: configService.getSettings('clientId'),
         redirectUri: …
Run Code Online (Sandbox Code Playgroud)

azure-ad-msal angular msal-angular

6
推荐指数
1
解决办法
6880
查看次数

BrowserAuthError:interaction_in_progress - 无法修复,无论找到什么解决方案

我正在为我现在工作的公司的应用程序实施安全性。我在用着@azure/msal-angular@2.0.2@azure/msal-browser@2.16.1我按照此处找到的示例进行操作 ,并使其适用于第一个应用程序。我继续为下一个应用程序实现它,它基本上是相同的,只是与不同的 api 通信,但复杂性是相同的。可能做错了什么之后,我不断收到错误:

core.js:6157 ERROR Error: Uncaught (in promise): BrowserAuthError: interaction_in_progress: Interaction is currently in progress. Please ensure that this interaction has been completed before calling an interactive API.  For more visit: aka.ms/msaljs/browser-errors.
BrowserAuthError: interaction_in_progress: Interaction is currently in progress. Please ensure that this interaction has been completed before calling an interactive API.  For more visit: aka.ms/msaljs/browser-errors.
Run Code Online (Sandbox Code Playgroud)

我发现其他几篇文章说要清除缓存、存储等...但都不起作用。它所做的只是提示我再次登录,只是用相同的条目填充 sessionStorage,其中包含msal.442edcf7-9e0c-469b-93fb-daa1839724bd.interaction.status interaction_in_progress. 据我所知,我已经尝试了我发现的一切。AzureAD 本身的解决方案也不起作用。

我对此很陌生,所以我可能错过了一些简单的事情,如果是这样,我很抱歉。

我的代码可以在下面找到。

角度版本

11.0.2

应用程序模块.ts

import { …
Run Code Online (Sandbox Code Playgroud)

javascript azure azure-ad-msal angular msal-angular

6
推荐指数
1
解决办法
1万
查看次数

Angular MSAL (v2) 通过重定向登录,在获取令牌之前重定向 3 次或更多次

我有一个 Angular 应用程序 ( v11.2.0 ),它使用 MSAL 进行身份验证。我最近升级到该库的 v2(@azure/msal-angular - ^2.1.1、@azure/msal-browser - ^2.22.0),并且由于 MSAL 更改而进行了一些重构。除了对用户进行身份验证并获取身份验证响应时之外,它的大部分工作方式与以前一样:该过程在成功获取身份验证响应之前循环大约 3 次,每次都会明显刷新应用程序。我看到的大致流程如下:

  • 循环1
  • 导航至应用程序
  • 用户未经过身份验证
  • 处理重定向启动
  • 处理重定向承诺调用但没有正在进行的交互,返回 null
  • 处理重定向结束
  • 登录开始
  • 收到空认证结果
  • 循环2
  • 导航至应用程序
  • 用户未经过身份验证
  • 处理重定向启动
  • 循环3
  • 导航至应用程序
  • 用户未经过身份验证
  • 处理重定向启动
  • 信息 - 获取令牌调用中
  • 登录成功
  • 处理重定向结束
  • 获取令牌启动
  • 收到认证结果

身份验证在我的 app.component.ts 中启动和处理:

ngOnInit() {
   this.msalBroadcastService.inProgress$
      .pipe(
         filter((status: InteractionStatus) => status === InteractionStatus.None)
      )
      .subscribe(async () => {
         if (!this.authenticated) {
            await this.logIn();
         }
      })

   this.msalService.handleRedirectObservable().subscribe({
      next: (result: AuthenticationResult) => {
         if (!this.msalService.instance.getActiveAccount() &&             
            this.msalService.instance.getAllAccounts().length > 0) …
Run Code Online (Sandbox Code Playgroud)

azure-ad-msal angular msal-angular

6
推荐指数
2
解决办法
1万
查看次数

注销时绕过帐户选择屏幕@azure/msal-Angular V2

我正在使用@azure/msal-Angular版本 2 和Angular版本 13。这种情况是,当用户登录应用程序时,如果用户没有访问权限,则需要对用户进行授权,需要从应用程序中注销用户。这将通过调用 msalService.logoutRedirect() 在后台发生。调用注销功能时,将显示 Microsoft 帐户选择屏幕以注销而不是自动注销。有没有办法跳过帐户选择屏幕以退出。

azure-active-directory angular msal-angular msal-react

4
推荐指数
1
解决办法
5011
查看次数