title: KEYCLOAK - Refresh/update token not working
body: <p>I have single page application that is built using <code>Angularjs</code> and integrated with <code>Keycloak</code> for <strong><em>authentication and authorization</em></strong>.</p>
  
  <p>I am able to login into my application, get loggedin user roles etc. goes The moment refresh token call, it always returns in my else case, and user logout of the application. Though the token valid time is set very high.</p>
  
  <p>I need to update the token, if user has opened the app. In case of failure or expire token i need to logout the user. <code>if (refreshed)</code> always returns false.</p>
  
  <p>Below is the piece of code i am using.</p>
  
  <pre><code>var __env = {};
  
          Object.assign(__env, window.__env);
  
          var keycloakConfig = {
              "url" : __env.keycloakUrl,
              "realm" : __env.keycloakRealm,
              "clientId" : __env.keycloakClientId,
              "credentials" : {
              "secret" : __env.keycloakSecret
              }
          };
  var keycloak = Keycloak(keycloakConfig);
          keycloak.init({
              onLoad : 'login-required'
          }).success(function(authenticated) {
                   if(authenticated){                  
                          keycloak.loadUserInfo().success(function(userInfo) {
                          bootstrapAngular(keycloak, userInfo, roles);
                      });
              }
          });
  
  function bootstrapAngular(keycloak, userInfo, roles) {
          angular.module('myApp').run(
                  function($rootScope, $http, $interval, $cookies) {
                      var updateTokenInterval = $interval(function() {
                          // refresh token if it's valid for less then 15 minutes
                      keycloak.updateToken(15).success(
                                  function(refreshed) {
                                      if (refreshed) {
                                          $cookies.put('X-Authorization-Token',
                                                  keycloak.token);
                                      }else{
                                          $rootScope.logoutApp();
                                      }
                                  });
                      }, 600000);
                      updateTokenInterval;
                      $cookies.put('X-Authorization-Token', keycloak.token);
  
                      $rootScope.logoutApp = function() {
                          $cookies.remove('X-Authorization-Token');
                          $interval.cancel(updateTokenInterval);
                          keycloak.logout();
                      };
      }
  }
  </code></pre>