question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

problem with allowedUrls and AOT

See original GitHub issue

I have a problem with allowedUrls in :

OAuthModule.forRoot({
            resourceServer: {
                allowedUrls: [varFromConf],
                sendAccessToken: true
            }
        })

I want to pass a variable to it because it come from configuration stuff but when it’s compile by AOT my variable is replaced by null and so authorization token is not sent later.

Is there any workaround for this problem ? I dont want to hard code here my allowed urls…

for the moment what I did is to iOAuthModuleConfig from may main app.component and then set resoureServer from there.

constructor(private moduleConfig: OAuthModuleConfig) {
  this.moduleConfig.resourceServer.allowedUrls = [(<any>window).ServerConfig.ApiBaseUrl];
}

But I don’t know if it’s a good thing

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:4
  • Comments:11 (2 by maintainers)

github_iconTop GitHub Comments

20reactions
jeroenheijmanscommented, Jun 21, 2018

I suggest doing this in app.module.ts:

import { OAuthModuleConfig, OAuthModule } from 'angular-oauth2-oidc';
import { authConfigFactory } from './auth-config-factory';

//...
    imports: [
      OAuthModule.forRoot(),
      // ...
    ],
    providers: [
      { provide: OAuthModuleConfig , useFactory: authConfigFactory, deps: [ConfigService] },
      // ...
    ]

// ...

and then this in auth-config-factory.ts:

// imports here

export function authConfigFactory(service: ConfigService): OAuthModuleConfig {
  return {
    resourceServer: {
      allowedUrls: [service.getVarFromConf()],
      sendAccessToken: true,
    }
  };
}

or something similar…

6reactions
dtiemstracommented, Feb 17, 2020

I faced the same problem and found a different solution. The problem with initializing your setting using APP_INITIALIZER is that loading the configuration is mostly async (using a promise) and the factory methods in your module are called before this promise is resolved.

You can however load the settings BEFORE bootstrapping the Module. Inside your App.module/other components you can access your settings without having to fear the settings are not loaded. I have created an example of how to accomplish this: github.com/dtiemstra/AngularConfigDemo

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular load external configuration before AppModule loads
Load configuration parameters (API server URL and Auth server URL) from an external endpoint (JSON), before the AppModule is loaded; Pass ...
Read more >
The Biggest Problem In “Tokyo Ghoul” And “Attack on Titan”
In Tokyo Ghoul, that's the ghouls, who look like humans, act like humans, and camouflage with human society, but have to eat humans...
Read more >
Everyone Loves Attack on Titan. So Why Does ...
A big, recurring controversy in the fandom is figuring out how to discuss or even deal with these issues at all. As a...
Read more >
Angular load external configuration before AppModule loads
In addition to @yurzui's answer, if you try this in AOT (e.g. ng build --prod ), you will get. ERROR in Error during...
Read more >
What exactly does allowedUrls setting mean in the ...
Issue. So, if my Angular app is running on localhost:4200 & keycloak server running on localhost:8080/auth, which URL values should I add in ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found