mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-07 05:31:22 +00:00
GUAC-1161: Reorganize authenticationInterceptor to match service pattern used elsewhere.
This commit is contained in:
@@ -20,28 +20,44 @@
|
|||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
angular.module('index').factory('authenticationInterceptor', ['$location', '$q',
|
angular.module('index').factory('authenticationInterceptor', ['$injector',
|
||||||
function authenticationInterceptor($location, $q) {
|
function authenticationInterceptor($injector) {
|
||||||
|
|
||||||
return {
|
|
||||||
|
|
||||||
// Redirect users to login if authorization fails
|
// Required services
|
||||||
responseError: function handleErrorResponse(rejection) {
|
var $location = $injector.get('$location');
|
||||||
|
var $q = $injector.get('$q');
|
||||||
|
|
||||||
// Only redirect failed authentication requests
|
var service = {};
|
||||||
if ((rejection.status === 401 || rejection.status === 403)
|
|
||||||
&& rejection.config.url === 'api/tokens') {
|
|
||||||
|
|
||||||
// Only redirect if not already on login page
|
/**
|
||||||
if ($location.path() !== '/login/')
|
* Redirect users to login if authorization fails. This is called
|
||||||
$location.path('/login/');
|
* automatically when this service is registered as an interceptor, as
|
||||||
|
* documented at:
|
||||||
|
*
|
||||||
|
* https://docs.angularjs.org/api/ng/service/$http#interceptors
|
||||||
|
*
|
||||||
|
* @param {HttpPromise} rejection
|
||||||
|
* The promise associated with the HTTP request that failed.
|
||||||
|
*
|
||||||
|
* @returns {Promise}
|
||||||
|
* A rejected promise containing the originally-rejected HttpPromise.
|
||||||
|
*/
|
||||||
|
service.responseError = function responseError(rejection) {
|
||||||
|
|
||||||
}
|
// Only redirect failed authentication requests
|
||||||
|
if ((rejection.status === 401 || rejection.status === 403)
|
||||||
|
&& rejection.config.url === 'api/tokens') {
|
||||||
|
|
||||||
return $q.reject(rejection);
|
// Only redirect if not already on login page
|
||||||
|
if ($location.path() !== '/login/')
|
||||||
|
$location.path('/login/');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $q.reject(rejection);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
return service;
|
||||||
|
|
||||||
}]);
|
}]);
|
||||||
|
Reference in New Issue
Block a user