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();
});
});
source
share