简体   繁体   English

msal angular - 在路由上使用 MsalGuard 进行身份验证时持续重新加载

[英]msal angular - continuous reloading while authentication using MsalGuard on routing

I'm trying to implement msal-v1 in my angular application to authenticate my enterprise application.我正在尝试在我的 angular 应用程序中实施msal-v1以验证我的企业应用程序。

There are few routes in my application like below我的应用程序中有几条路线如下

const routes: Routes = [
  { path: '', component: HomeComponent, canActivate: [MsalGuard] },
  { path: 'profile', component: ProfileComponent, canActivate: [MsalGuard] },
  { path: 'search', component: SearchComponent, canActivate: [MsalGuard] }
];

and my MSAL config is like below我的 MSAL 配置如下所示

MsalModule.forRoot(
      {
        auth: {
          clientId: environment.clientId,
          authority: "https://login.microsoftonline.com/tenant.onmicrosoft.com/",
          validateAuthority: true,
          redirectUri: "https://example.com/",
          postLogoutRedirectUri:
            "https://example.com/",
          navigateToLoginRequestUrl: true,
        },
        cache: {
          cacheLocation: "localStorage",
          storeAuthStateInCookie: isIE, // set to true for IE 11
        },
        system: {
          logger: new Logger(loggerCallback, {
            level: LogLevel.Verbose,
            piiLoggingEnabled: true,
          }),
        }
      },
      {
        popUp: false,
        consentScopes: ["user.read", "openid", "profile"],
        unprotectedResources: ["https://www.microsoft.com/en-us/"],
        protectedResourceMap,
        extraQueryParameters: {},
      }
    )  

The issue I'm facing here is, when I try to run the domain with empty route , then authentication is working fine and then redirecting to home Component /page.我在这里面临的问题是,当我尝试使用empty route运行域时,身份验证工作正常,然后重定向到home Component /页面。 From then on, I was able to redirect to all pages with out any issues.从那时起,我能够毫无问题地重定向到所有页面。

But when I'm trying to directly open Profile/Search routes, after the authorize call, the url is entering a loop by redirecting first to https://example.com/#id_token=eyJ0eXAiOi.. .但是当我试图直接打开Profile/Search路由时,在授权调用之后,url 通过首先重定向到https://example.com/#id_token=eyJ0eXAiOi..进入loop and then to https://example.com/search#id_token=eyJ0eXAiOi.. .然后到https://example.com/search#id_token=eyJ0eXAiOi.. and then entering to https://example.com/#id_token=eyJ0eXAiOi.. .然后输入https://example.com/#id_token=eyJ0eXAiOi..。 again and so on.再次等等。

I have also observed a console issue saying clientautherror: login_in_progress: error during login call - login is already in progress.我还观察到一个控制台问题,上面写着clientautherror: login_in_progress: error during login call - login is already in progress.

can anyone let me know what I might be doing wrong?任何人都可以让我知道我可能做错了什么吗?

I have discussed the same issue in the github forum and have found a alternate solution by setting a new route without the MsalGuard but to the same HomeComponent .我在 github 论坛中讨论了相同的问题,并通过设置一条没有MsalGuard但指向相同HomeComponent的新路由找到了替代解决方案。

const routes: Routes = [
  {
    path: '',
    component: HomeComponent,
    canActivate: [
      MsalGuard
    ]
  },
  {
    path: 'auth-redirect',
    component: HomeComponent
  },
  {
    path: 'profile',
    component: ProfileComponent,
    canActivate: [
      MsalGuard
    ]
  }
];

full details here详细信息在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用@azure-msal-angular 进行 Microsoft AD 身份验证时出现 performanceMeasurement.startMeasurement 错误 - performanceMeasurement.startMeasurement error when using @azure-msal-angular for Microsoft AD authentication MSAL - 如何使用 Angular 13 兼容的 MSAL 库获取 ID 令牌 - MSAL - How to get ID token using Angular 13 compatible MSAL Library 我无法使用 MSAL angular 登录。请在下方查找问题详细信息 - I am not able to login using MSAL angular . Please find issue details below LoginRedirect with prompt='create' 在 Angular Msal 中不起作用 - LoginRedirect with prompt='create' not working in Angular Msal Api登录msal认证后调用 - Api call after login msal authentication Google Cloud App Engine 中的 Angular 7 路由不起作用 - Angular 7 Routing in Google Cloud App Engine not working firebase 路由上 golang 中的 google cloud function gen2 的身份验证问题 - Authentication problem with google cloud function gen2 in golang on firebase routing 访问 API 网关时缺少身份验证令牌? - Missing Authentication Token while accessing API Gateway? 带有 Azure AD (MSAL) 的赛普拉斯 - Cypress with Azure AD (MSAL) 使用 firebase.User 方法从 firebase angular 项目获取登录用户的用户名时出错 - Getting error while using firebase.User method to get username of logged in user from firebase angular project
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM