Модуль Angular 6 и keycloak-angular: как загрузить URL-адрес keycloak с сервера

Я использую модуль keycloak-angular (v 4.0.0) в проекте Angular 6. Теперь я пытаюсь загрузить URL-адрес для использования Keycloak с моего сервера (поскольку он может отличаться в зависимости от APIKey). Итак, в функции инициализации приложения я попытался сделать что-то вроде этого:

export function initializer(keycloak: KeycloakService, http: HttpClient): () => Promise<any> {
  return () => new Promise<boolean>((resolve) => {
    const apiKey = 'myapikey;
    // TODO: make KeycloakBearerInterceptor not intercept the HTTP-Call
    // load configuration from server
    const promise = http.get<ApiConfiguration>(environment.apiHost + '/1.0/configuration?apiKey=' + apiKey).toPromise()
      .then((data: ApiConfiguration) => {

        const keycloakConfig = {
          url: data.idpConfig.authority,   <-- 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) => console.log(reason));
        return true;
      });

    return promise;
  });
}

Но KeycloakBearerInterceptor перехватывает http-вызов, потому что по умолчанию enableBearerInterceptor равно true. Конечно, keycloak-module еще не инициализирован и поэтому перехватчик не работает с

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)

Я также пытался фиктивно инициализировать модуль keycloak, но он всегда выполняет функцию загрузки, и ее также нельзя отключить.

Есть ли у кого-нибудь идеи, как этого добиться? Спасибо


person aubium77    schedule 26.08.2018    source источник


Ответы (1)


Оказалось, что у нас есть собственный KeycloakBearerInterceptor, который срабатывает и дает сбой. Так что это не имеет ничего общего с библиотекой keycloak-angular.

person aubium77    schedule 27.08.2018