title: What is Authentication Interceptor in angular
body: <p>I have an Angular template. In the app.js I have this config:</p>
  
  <pre><code>app.config(function ($routeProvider, $httpProvider) {
  $httpProvider.interceptors.push('AuthInterceptor');
  
  $routeProvider
  .when('/', { .....etc
  </code></pre>
  
  <p>The AuthInterceptor is this factory:</p>
  
  <pre><code>'use strict';
  
  app.factory('AuthInterceptor', function ($rootScope, $q, $window, $location) {
  return {
    request: function (config) {
      config.headers = config.headers || {};
      if ($window.localStorage.token) {
        config.headers.Authorization = 'Token ' + $window.localStorage.token;
      }
      return config;
    },
  
    responseError: function (response) {
      if (response.status === 401) {
        $window.localStorage.removeItem('token');
        $window.localStorage.removeItem('email');
        $location.path('/');
        return;
      }
      return $q.reject(response);
    }
  };
  });
  </code></pre>
  
  <p>What does it exactly do?</p>