import { APP_INITIALIZER, NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { RouterModule } from '@angular/router'; import { AuthModule, EventTypes, LogLevel, OidcConfigService, PublicEventsService } from 'angular-auth-oidc-client'; import { filter } from 'rxjs/operators'; import { AppComponent } from './app.component'; import { HomeComponent } from './home/home.component'; import { UnauthorizedComponent } from './unauthorized/unauthorized.component'; export function configureAuth(oidcConfigService: OidcConfigService) { return () => oidcConfigService.withConfig({ stsServer: 'https://offeringsolutions-sts.azurewebsites.net', redirectUrl: window.location.origin, postLogoutRedirectUri: window.location.origin, clientId: 'angularImplicitClient', scope: 'openid profile email', responseType: 'id_token token', silentRenewUrl: `${window.location.origin}/silent-renew.html`, startCheckSession: true, silentRenew: true, logLevel: LogLevel.Debug, }); } @NgModule({ declarations: [AppComponent, HomeComponent, UnauthorizedComponent], imports: [ BrowserModule, RouterModule.forRoot([ { path: '', redirectTo: 'home', pathMatch: 'full' }, { path: 'home', component: HomeComponent }, { path: 'forbidden', component: UnauthorizedComponent }, { path: 'unauthorized', component: UnauthorizedComponent }, ]), AuthModule.forRoot(), ], providers: [ OidcConfigService, { provide: APP_INITIALIZER, useFactory: configureAuth, deps: [OidcConfigService], multi: true, }, ], bootstrap: [AppComponent], }) export class AppModule { constructor(private readonly eventService: PublicEventsService) { this.eventService .registerForEvents() .pipe(filter((notification) => notification.type === EventTypes.ConfigLoaded)) .subscribe((config) => console.log('ConfigLoaded', config)); } }