Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

143
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda