title: Angular 6 and keycloak-angular module: How to load the keycloak url from a server
body: <p>I'm using the keycloak-angular module (v 4.0.0) in an Angular 6 project.
  Now I'm trying to load the Url to the Keycloak to use, from my server (since it can be different depending on the apiKey).
  So, in the app initializer function I've tried doing something like this:</p>
  
  <pre><code>export function initializer(keycloak: KeycloakService, http: HttpClient): () =&gt; Promise&lt;any&gt; {
    return () =&gt; new Promise&lt;boolean&gt;((resolve) =&gt; {
      const apiKey = 'myapikey;
      // TODO: make KeycloakBearerInterceptor not intercept the HTTP-Call
      // load configuration from server
      const promise = http.get&lt;ApiConfiguration&gt;(environment.apiHost + '/1.0/configuration?apiKey=' + apiKey).toPromise()
        .then((data: ApiConfiguration) =&gt; {
  
          const keycloakConfig = {
            url: data.idpConfig.authority,   &lt;-- This comes from the server
            realm: 'mediakey',
            clientId: 'mediakey'
          };
          keycloak.init({
            config: {
              url: data.idpConfig.authority,
              realm: 'mediakey',
              clientId: 'mediakey'
            },
            loadUserProfileAtStartUp: true,
            initOptions: {
              onLoad: 'check-sso',
              // onLoad: 'login-required',
              checkLoginIframe: false,
              flow: 'implicit'
            },
            enableBearerInterceptor: false,
            bearerExcludedUrls: [
              '/assets',
              '/1.0/configuration'
            ],
          }).catch((reason) =&gt; console.log(reason));
          return true;
        });
  
      return promise;
    });
  }
  </code></pre>
  
  <p>But the KeycloakBearerInterceptor intercepts the http-call because the default of <code>enableBearerInterceptor</code> is <code>true</code>. Of course, the keycloak-module is not initialized yet and therefore the interceptor fails with</p>
  
  <pre><code>ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'authenticated' of undefined
  TypeError: Cannot read property 'authenticated' of undefined
      at KeycloakBearerInterceptor.push../shared/core/rest/keycloak-bearer-interceptor.ts.KeycloakBearerInterceptor.intercept (keycloak-bearer-interceptor.ts:42)
  </code></pre>
  
  <p>I have also tried to dummy-initialize the keycloak-module but it always performs the onload-function and that can also not be disabled.</p>
  
  <p>Has anyone any ideas how to achieve this? 
  Thanks</p>