possible to user per service interceptors?

30 views Asked by At

Is it possible to override my authInterceptor on a per service basis?

What I'm trying to accomplish:

I'm using a JWT for my own api, but occasionally I'm using Google Apis and need to reset my Authorization header to my google auth token rather than my local auth token. Here's what I have so far. It sets my authorization header sitewide using my own api token. So how do I override this if I were to make a GoogleService?

services.factory('authInterceptor', function ($rootScope, $q, $window, $log, localStorageService) {
return {
    request: function (config) {

        config.headers = config.headers || {};
        config.headers.Authorization = 'Bearer '+localStorageService.get('token');
        return config;
    },
    response: function (response) {
        return response || $q.when(response);
    }
};
});

services.config(function ($httpProvider) {
$httpProvider.interceptors.push('authInterceptor');
});
0

There are 0 answers