Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

142
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!