Skip to content

Instantly share code, notes, and snippets.

@tkh44
Created February 10, 2015 15:06
Show Gist options
  • Save tkh44/c4a593560a738a02073d to your computer and use it in GitHub Desktop.
Save tkh44/c4a593560a738a02073d to your computer and use it in GitHub Desktop.
class HttpAuthService {
constructor($q, $injector) {
super($q);
angular.extend(this, {$q, $injector});
}
request(config) {
//console.log(config);
return config;
}
requestError(rejection) {
//console.log(rejection);
return this.$q.reject(rejection);
}
response(config) {
var UserService = this.$injector.get('UserService');
if (this.isApiRequest(config.url)) {
if (this.UserService.isAuthorized()) {
// This is just a prototype UserService is a fiction of my imagination
}
}
return config;
}
responseError(rejection) {
//console.log(rejection);
return this.$q.reject(rejection);
}
isApiRequest(url) {
return url.search('/external/api') > -1;
}
static httpAuthFactory($q, $injector) {
return new HttpAuthService($q, $injector);
}
}
HttpAuthService.httpAuthFactory.$inject = ['$q', '$injector'];
angular.module('mailApp').config(($provide, $httpProvider) => {
$provide.factory('authorizeInterceptor', HttpAuthService.httpAuthFactory);
$httpProvider.interceptors.push('authorizeInterceptor');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment