How can I resolve the AADSTS900561 for Angular 9 app with MSAL v2

35 Views Asked by At

I am getting this error that is generated when I try to run my application, the compilation works correctly and this is the error that I get Failed to load resource: the server responded with a status of 400 ().This is an Angular 9 app, I recently added MSAL v2 as Authenticator. I added a MSALInstanceMethod with tenantid and clientid and my environment variables. How can I resolve this issue ?

appmodule.ts

export function MSALInstanceFactory() : IPublicClientApplication{

  const windowRef = new WindowRef();
  const env: IEnvConstants = (windowRef.nativeWindow)['ENV'];

  return new PublicClientApplication({
    auth: {
      clientId: env.msAdalAngularConfig.clientId,
      authority: `https://login.microsoftonline.com/${env.msAdalAngularConfig.tenant}`,
      redirectUri: window.location.origin,
    },
    cache: {
      cacheLocation: 'localStorage',
      storeAuthStateInCookie: true,
    },
    system: {
      loggerOptions: {
        loggerCallback(logLevel: any, message: any) {
          console.log(message);
        },
        piiLoggingEnabled: false,
      },
    },
  });
  @NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    BrowserAnimationsModule,
    AppRoutingModule,
    CoreModule,
    MsalModule.forRoot(
      MSALInstanceFactory(),
      {
        interactionType: 'popup',
        authRequest: {
          scopes: [], 
        },
      } as MsalGuardConfiguration,
      {
        interactionType: 'redirect',
      } as MsalInterceptorConfiguration
    ),
    //MsAdalAngular6Module.forRoot(getAdalConfig),
    SharedModule,
  ],
  providers: [
    //AuthenticationGuard,
    MsalGuard, 
    Title, 
    ThemeService,
    {
      provide: MSAL_INSTANCE,
      useFactory: MSALInstanceFactory
    },
    {
      provide: MSAL_GUARD_CONFIG,
      useFactory:() =>({
        interactionType: 'popup',
        authrequest:{
          scopes : [],
        },
      }as MsalGuardConfiguration),
    },
    MsalService,
    {
      provide: HTTP_INTERCEPTORS,
      useClass: MsalInterceptor,
      multi:true,
    },
    {
      provide : MSAL_INTERCEPTOR_CONFIG,
      useFactory: () =>({
        interactionType: 'redirect'
      }as MsalInterceptorConfiguration),
    },
  ],
  bootstrap: [AppComponent]
})
export class AppModule { }
0

There are 0 best solutions below