Keycloak Error Unknown Provider

I use Keycloak.js to interact with Keycloak and get below the error

Uncaught Error: [$injector:unpr] Unknown provider: AuthProvider <- Auth <- authInterceptor <- $http <- $templateRequest <- $compile

Using the code:

module.factory('authInterceptor', ['$q', 'Auth', function($q, Auth) {
  return {
    request: function (config) {
      var deferred = $q.defer();
      if (Auth.authz.token) {
        Auth.authz.updateToken(5).success(function() {
          config.headers = config.headers || {};
          config.headers.Authorization = 'Bearer ' + Auth.authz.token;

          deferred.resolve(config);
        }).error(function() {
          deferred.reject('Failed to refresh token');
        });
      }
      return deferred.promise;
    }
  };
}]);

module.config(['$httpProvider', function($httpProvider) {
  $httpProvider.responseInterceptors.push('errorInterceptor');
  $httpProvider.interceptors.push('authInterceptor');
}]);

Is there a reason why this is happening?

I also include keycloak.js in my index.html, which is inserted with Bower

I also have an Auth factory instance inside the house:

angular.element(document).ready(function($http) {
  var keycloakAuth = new Keycloak('keycloak.json');
  auth.loggedIn = false;

  keycloakAuth.init().success(function () {
    auth.loggedIn = true;
    auth.authz = keycloakAuth;
    auth.logoutUrl = keycloakAuth.authServerUrl + "/realms/demo/tokens/logout?redirect_uri=http://localhost:3000";
    module.factory('Auth', function () {
      return auth;
    });
  }).error(function () {
    window.location.reload();
  });
});
+4
source share
2 answers

the problem is that you are creating an instance of "Auth" on dom ready, but the dependecy injector is trying to enter before dom is ready (simplified).

The question is, why is it ready for dom?

here are two examples:

http://jsbin.com/lulin/1/edit (with readiness definition not working, same error)

http://jsbin.com/wajeho/2/edit ( , )


EDIT:

- : http://jsbin.com/xusiva/1/edit?html,js,console

factory domready, domready .

+1

, , keycloak angular 1.2, , , 1.3. keycloak angular angular 1.2, , 1.3, . , , , angular 1.3, , responseInterceptors angular 1.3

0

All Articles