In my angularjs application, I am communicating with a server server that requires basic authentication of access through an HTTP header. I implemented a client-side authentication mechanism as described here .
angular.module('myAuthModule')
.config(['$httpProvider', '$stateProvider',
function ($httpProvider, $stateProvider) {
$httpProvider.interceptors.push('securityInterceptor');
}])
.factory('securityInterceptor', ['$location', '$window', '$q',
function ($location, $window, $q) {
return {
request: function (config) {
config.headers = config.headers || {};
if ($window.sessionStorage.token) {
config.headers['Auth-Key'] = $window.sessionStorage.token;
}
return config;
},
response: function (response) {
if (response.status === 401 || response.status === 403) {
$location.path('/login');
}
return response || $q.when(response);
}
};
}
]);
So far, it's so good that handling xhr requests in an angular application works as expected.
, PDF-. /Document/Pdf/:id, application/pdf ContentDisposition: attachment, . , xhr, ngHref , , , $window.open('/Document/Pdf/13'), 401 Unauthorized .
?