Hi,
I am trying to load Okta config from external API. I want my application to go the Okta authentication route only when the config file is present. The logic is working correctly when the the config file passed via environment variable is correct (For eg configFileOkta: ‘assets/config/config.okta.json’). However, when I am passing ‘’ (configFileOkta: ‘’), I am getting below error:
ERROR Error: Okta config is not provided
at Object.createOktaAuth [as useFactory] (okta-okta-angular.js:310:19)
at Object.factory (core.mjs:8806:38)
at R3Injector.hydrate (core.mjs:8719:35)
at R3Injector.get (core.mjs:8607:33)
at ChainedInjector.get (core.mjs:13811:36)
at lookupTokenUsingModuleInjector (core.mjs:3293:39)
at getOrCreateInjectable (core.mjs:3338:12)
at Module.ɵɵdirectiveInject (core.mjs:10913:12)
at NodeInjectorFactory.HeaderComponent_Factory [as factory] (header.component.ts:133:21)
at getNodeInjectable (core.mjs:3523:44)
Is there any way to get around this?
In appModule, I have provider for Okta as below:
{
provide: APP_INITIALIZER,
useFactory: initializeOkta,
multi: true,
deps: [OktaAuthConfigService,ConfigInitService],
}
export function initializeOkta(
okta: OktaAuthConfigService,
configService: ConfigInitService
) {
console.log(“calling okta.initialize”);
return () =>
configService.getConfig()
.pipe(
filter(res => res !=null),
map((res: any) => ({
issuer: res.issuer,
clientId: res.clientId,
redirectUri: window.location.origin + ‘/login/callback’
})),
tap((authConfig: OktaAuthOptions) => {
const oktaAuth = new OktaAuth(authConfig);
const moduleConfig: OktaConfig = { oktaAuth };
okta.setConfig(moduleConfig);
}),
take(1)
);
}
Thanks