I am currently creating a webapp using the Django + Django Rest Framework (DRF) at the back and Angularjs to create a user interface.
All requests are authenticated using basic token authentication, which is built into DRF. I applied a basic interceptor in Angular to add a token, which is stored in the session store after login, for each request. This works fine in Google Chrome (I see that the authorization header is actually added to each request with the inspector) and Firefox. However, in Safari, the header is not added to some queries.
First of all, this is the interceptor that I use:
app.factory('authInterceptor', ['$rootScope', '$q', '$window', function($rootScope, $q, $window){
return {
request: function(config){
config.headers = config.headers || {};
try {
var token = $window.sessionStorage.token;
} catch(err){
token = undefined;
}
if(token !== undefined){
config.headers.Authorization = 'Token ' + token;
}
return config;
},
response: function(response){
if(response.status === 401){
}
return response || $q.when(response);
}
};
}]);
One specific resource that gives me a headache in Safari:
app.factory('Coach', ['$resource', '$rootScope',
function($resource, $rootScope){
return $resource(
$rootScope.api_url + 'api/coaches/:coachId/?format=json',
{
coachId: '@id'
}
,
{
getByUserId: {method:'GET', url: $rootScope.api_url + 'api/coaches', isArray:false},
update: {method:'PUT'}
}
);
}]);
withCredentials getByUserId, .
$httpService. , Safari sessionStorage. . .
-?