Unable to initialize keycloak in angular with Promise with dynamic conf

Discussão em 'Angular' iniciado por batmaniac, Maio 14, 2025.

  1. batmaniac

    batmaniac Guest

    I would like to call a webservice before initializing keycloak frontend component from keycloak-angular library to make keycloakconf dynamic. The backendService.keycloakConfig() webservice returned the correct value but the isInitialized variable is always false.

    I think mixing the Promise and the Observable is messing with the initialization.

    Here is the code :

    import {KeycloakService} from 'keycloak-angular';

    import {BackendService} from "./service/backend.service";

    export function initializer(keycloak: KeycloakService, backendService: BackendService): () => Promise<any> {

    return (): Promise<any> => {
    return new Promise<void>(async (resolve, reject) => {
    backendService.keycloakConfig()
    .toPromise()
    .then(
    keycloakConfig => {
    try {
    keycloak.init({
    config: keycloakConfig,
    enableBearerInterceptor: true,
    loadUserProfileAtStartUp: false,
    initOptions: {
    checkLoginIframe: false
    },
    bearerExcludedUrls: ['/assets']
    }).then((isInitialize) => {
    console.log("Initialized keycloak", isInitialize)
    }).catch(reason => {console.log(reason)})
    resolve();
    } catch (error) {
    console.log("error", error)
    reject(error);
    }
    })
    });
    };
    }

    Continue reading...

Compartilhe esta Página