Loading Okta config from external APIs giving error "Error: Okta config is not provided at Object.createOktaAuth [as useFactory]"

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

@Dipti did you get any movement on this? I am in the same boat. The OkaAuthConfigService seems to hold a reference to the instantiated Okta Auth instance but when I inject the OktaAuthConfigService and attempt to get the okta auth instance from the getConfig() call I am still getting an error. I assume we still need to use the OKTA_AUTH injection token when injecting okta Auth into components but its not super clear in the documentation when using the new injection strategies.

@alisaduncan I see that you mentioned in another related post that this is available and tutorial post is coming soon. Any update on that? The documentation on the github page for using APP_INITIALIZER is not working for me and I feel as if I am missing some information. Any help is appreciated thanks.

Everything is working fine for me when a valid Okta configuration is passed. The problem I have is when I want to make it optional.

Yes, you would OKTA_AUTH injector in your component constructor. Something like:
@Inject(OKTA_AUTH) public oktaAuth: OktaAuth

Hi there @tcmodus !

Thanks for reaching out. Unfortunately, I don’t have the post up yet, but I can take a look to make sure all is working as intended. I just returned from travels, so I’ll take a look as soon as possible.

To verify, what version of Angular are you using? And also to doubly make sure, are you using stand-alone or NgModule-based architecture?