현재 UI를 구성하기 위해 Django + Django Rest Framework (DRF)와 Angularjs를 사용하여 webapp를 작성하고 있습니다.Angularjs - Safari에 인증 헤더가 추가되지 않았습니다.
모든 요청은 DRF로 빌드되는 기본 토큰 인증을 사용하여 인증됩니다. 각 앵글에서 기본 인터셉터를 구현하여 로그인 후 세션 저장소에 저장되는 토큰을 각 요청에 추가했습니다. 이것은 Chrome에서 잘 작동합니다 (인증 헤더가 관리자가 사용하는 각 요청에 실제로 추가되었음을 알 수 있습니다). 그러나 사파리에서는 헤더가 일부 요청에 추가되지 않습니다. 나에게 Safari에서 두통입니다 제공하는 특정 자원의
app.factory('authInterceptor', ['$rootScope', '$q', '$window', function($rootScope, $q, $window){
return {
// This method adds the authentication token to each requests' header
request: function(config){
config.headers = config.headers || {};
// add authentication token in header
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){
// user not authenticated
}
return response || $q.when(response);
}
};
}]);
하나 :
모든첫째, 이것은 내가 사용하는 인터셉터입니다
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로 올바르게 푸시됩니다. 토큰이 sessionStorage의 Safari에서 사용 가능함을 확인했습니다. 인터셉터에서 콘솔에 토큰을 인쇄했습니다. 이 문제에 대한 내 머리를 얻을 수 없습니다.
누구나?
정확히 같은 문제가 있지만 백엔드로 자바를 사용한다고 생각합니다. (http://stackoverflow.com/questions/32018621/angularjs-headers-not-added-in-my-rest-using-safari – RicardoGonzales