title: Angularjs - Authorization header not added in Safari
body: <p>I'm currently building a webapp using Django + Django Rest Framework (DRF) in the back and Angularjs to construct the UI. </p>
  
  <p>All requests are authenticated using the basic token authentication that is build into DRF. I implemented a basic interceptor in Angular to add the token, which is stored in session storage after login, to each request. This works fine in Google Chrome (I can see that the Authorization header is actually added to each request using the inspector) and Firefox. However in Safari the header is not added to some requests.</p>
  
  <p>First of all, this is the interceptor I use:</p>
  
  <pre><code>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);
          }
      };
  }]);
  </code></pre>
  
  <p>One of the specific resources that gives me a headache in Safari is:</p>
  
  <pre><code>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'}
              }
          );
  }]);
  </code></pre>
  
  <p>If have tried adding withCredentials to the getByUserId method but no luck.</p>
  
  <p>My interceptor is properly pushed to the $httpService. I have verified that the token was available in Safari in the sessionStorage. I have printed the token to the console from the interceptor. Can't get my head around this issue. </p>
  
  <p>Anyone?</p>