-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated dependencies. Major change: update to angular v3. Needed to resolve breaking changes concerning interceptors. Also, the new vendorServices fuctionality does to work for the unit tests (since the unit tests use files from the /src dir). WIP: started reconfiguring karma so that tests are run on files in the /build dir (i.e. processed files!)
- Loading branch information
Showing
13 changed files
with
316 additions
and
336 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/** | ||
* @license HTTP Auth Interceptor Module for AngularJS | ||
* (c) 2012 Witold Szczerba | ||
* License: MIT | ||
* https://github.com/witoldsz/angular-http-auth/tree/gh-pages | ||
*/ | ||
angular.module('http-auth-interceptor', []) | ||
|
||
.provider('authService', function () { | ||
/** | ||
* Holds all the requests which failed due to 401 response, | ||
* so they can be re-requested in future, once login is completed. | ||
*/ | ||
var buffer = []; | ||
|
||
/** | ||
* Required by HTTP interceptor. | ||
* Function is attached to provider to be invisible for regular users of this service. | ||
*/ | ||
this.pushToBuffer = function (config, deferred) { | ||
buffer.push({ | ||
config: config, | ||
deferred: deferred | ||
}); | ||
}; | ||
|
||
this.$get = ['$rootScope', '$injector', function ($rootScope, $injector) { | ||
var $http; // initialized later because of circular dependency problem | ||
function retry(config, deferred) { | ||
$http = $http || $injector.get('$http'); | ||
$http(config).then(function (response) { | ||
deferred.resolve(response); | ||
}); | ||
} | ||
|
||
function retryAll() { | ||
for (var i = 0; i < buffer.length; ++i) { | ||
retry(buffer[i].config, buffer[i].deferred); | ||
} | ||
buffer = []; | ||
} | ||
|
||
return { | ||
loginConfirmed: function () { | ||
console.info("authService::event:auth-loginConfirmed"); | ||
$rootScope.$broadcast('event:auth-loginConfirmed'); | ||
|
||
retryAll(); | ||
} | ||
}; | ||
}]; | ||
}) | ||
/** | ||
* $http interceptor. | ||
* On 401 response - it stores the request and broadcasts 'event:angular-auth-loginRequired'. | ||
*/ | ||
.factory("authHttpInterceptor", | ||
["authService", "$rootScope", "$q", | ||
function (authServiceProvider, $rootScope, $q) { | ||
return { | ||
'responseError': function error(response) { | ||
if (response.status === 401) { | ||
var deferred = $q.defer(); | ||
authServiceProvider.pushToBuffer(response.config, deferred); | ||
|
||
console.info("authService::event:auth-loginRequired"); | ||
$rootScope.$broadcast('event:auth-loginRequired'); | ||
return deferred.promise; | ||
} | ||
// otherwise | ||
return $q.reject(response); | ||
} | ||
}; | ||
}]) | ||
|
||
|
||
.config(['$httpProvider', function ($httpProvider) { | ||
$httpProvider.interceptors.push("authHttpInterceptor"); | ||
}]); |
Oops, something went wrong.