Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

144
Vistas
Keycloak object store in AngularJS

I'm importing the keycloak lib into angularjs, and after execute with success 'init method' the "service.keycloak" object is updated with properties that i wanted to use (as example: token). When calling my service in another controller the object "service.keycloak" is not loaded with properties like in init method . How can I do this?

My service factory:

(function TBayKeycloak(angular) {
"use strict";

var app = angular.module('TBayKeycloak',[]);

app.factory('KeycloakService', ['$window',
    function KeycloakService($window,) {

        var service = {};

        service.init = function init() {

            service.keycloak = new Keycloak({
                          url: 'http://localhost:8200/auth',
                          realm: 'master',
                          clientId: 'bpms-dev'
                       });

            service.keycloak.init({
                onLoad: 'login-required'
            }).then(function (auth){
                 if(auth){
                    //Here my object "service.keycloak" load properties with success
                    $window.location = window.location.origin + '/main.html';
                 }else{
                    console.log("authentication failed");
                 }
            }).catch(function(error) {
                 console.log('failed to initialize');
            });
        }

        service.getKeycloakInstance = function getKeycloakInstance(){
            //But here the object never loaded properties 
            return service.keycloak;
        }

       
        service.getToken = function getToken(){

            if(service.keycloak){
                return service.keycloak.token;
            }
        }


        return service;
    }]);


})(angular);

And Controller with call method from service:

app.controller('TitleCtrl', ['$scope', '$rootScope', '$location', 'CoreRes','KeycloakService',
    function ($scope, $rootScope, $location, CoreRes, KeycloakService) {
        //Here returns the object incomplete
        var keycloak = KeycloakService.getKeycloakInstance();
    }
]);
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda