Ensures the user service returns the real error when the current user fails, ensures we add the standard header to all ajax requests so they can be detected
This commit is contained in:
@@ -6,6 +6,7 @@ angular.module('umbraco.interceptors', [])
|
||||
|
||||
$httpProvider.interceptors.push('securityInterceptor');
|
||||
$httpProvider.interceptors.push('debugRequestInterceptor');
|
||||
$httpProvider.interceptors.push('requiredHeadersInterceptor');
|
||||
$httpProvider.interceptors.push('doNotPostDollarVariablesOnPostRequestInterceptor');
|
||||
$httpProvider.interceptors.push('cultureRequestInterceptor');
|
||||
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Used to set required headers on all requests where necessary
|
||||
* @param {any} $q
|
||||
* @param {any} urlHelper
|
||||
*/
|
||||
function requiredHeadersInterceptor($q, urlHelper) {
|
||||
return {
|
||||
//dealing with requests:
|
||||
'request': function (config) {
|
||||
|
||||
// This is a standard header that should be sent for all ajax requests and is required for
|
||||
// how the server handles auth rejections, etc... see
|
||||
// https://github.com/aspnet/AspNetKatana/blob/e2b18ec84ceab7ffa29d80d89429c9988ab40144/src/Microsoft.Owin.Security.Cookies/Provider/DefaultBehavior.cs
|
||||
// https://brockallen.com/2013/10/27/using-cookie-authentication-middleware-with-web-api-and-401-response-codes/
|
||||
config.headers["X-Requested-With"] = "XMLHttpRequest";
|
||||
|
||||
return config;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
angular.module('umbraco.interceptors').factory('requiredHeadersInterceptor', requiredHeadersInterceptor);
|
||||
|
||||
|
||||
})();
|
||||
@@ -241,9 +241,9 @@ angular.module('umbraco.services')
|
||||
setCurrentUser(data);
|
||||
|
||||
deferred.resolve(currentUser);
|
||||
}, function () {
|
||||
}, function (err) {
|
||||
//it failed, so they are not logged in
|
||||
deferred.reject();
|
||||
deferred.reject(err);
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
@@ -266,9 +266,9 @@ angular.module('umbraco.services')
|
||||
setCurrentUser(data);
|
||||
|
||||
return $q.when(currentUser);
|
||||
}, function () {
|
||||
}, function (err) {
|
||||
//it failed, so they are not logged in
|
||||
return $q.reject(currentUser);
|
||||
return $q.reject(err);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user