import { OAuthService, OAuthStorage } from 'angular-oauth2-oidc'; import { ItemTypeService } from '../services/itemtype.service'; import { AppConfig } from "./app.config"; import { IAuthconfigFactory } from './authconfigFactory'; import { Injector } from '@angular/core'; export function appConfigFactory(_injector:Injector, appConfig: AppConfig, oauthService: OAuthService, authconfigFactory:IAuthconfigFactory,authStorage:OAuthStorage,itemtypeService:ItemTypeService): () => Promise { return (): Promise => { return new Promise((resolve,reject) => { appConfig.load().then(() => { itemtypeService.load(appConfig); oauthService.configure(authconfigFactory.getAuthConfig(appConfig)); oauthService.setStorage(authStorage); oauthService.setupAutomaticSilentRefresh(); }).then(() => oauthService.loadDiscoveryDocument() ).then(() => resolve()).catch((error) => { console.log(error); reject(); }); }); } }