title: CakePHP 2.0 Basic Authentication always gives 302 redirect instead of 401 unauthorized
body: <p>I have basic authentication set up in a simple CakePHP 2.0 application. I first set up the application to use regular form authentication, then I added the following line to the <code>beforeFilter()</code> of my AppController.php to enable basic http authentication:</p>
  
  <p><code>$this-&gt;Auth-&gt;authenticate = array('Basic');</code></p>
  
  <p>Here's the full AppController:</p>
  
  <pre><code>&lt;?php
  class AppController extends Controller {
  
      public $components = array(
              "Session",
              "Auth" =&gt; array(
                  'loginRedirect' =&gt; array('controller'=&gt;'users','action'=&gt;'index'),
                  'logoutRedirect' =&gt; array('controller'=&gt;'users','action'=&gt;'index'),
                  'authError' =&gt; "You are not authorized to view this page.",
                  'authorize' =&gt; array('Controller'),
          )
      );
  
      public function isAuthorized($user) {
          return true;
      }
  
      public function beforeFilter() {
          parent::beforeFilter();
          $this-&gt;Auth-&gt;allow('index','view');
          $this-&gt;set('logged_in', $this-&gt;Auth-&gt;loggedIn());
          $this-&gt;set('current_user',$this-&gt;Auth-&gt;user());
          $this-&gt;Auth-&gt;authenticate = array('Basic');
      }
  }
  ?&gt;
  </code></pre>
  
  <p>Ideally I'd like one specific controller (a controller which will expose an API for use with a mobile device) out of the entire application to use only Basic HTTP authentication, and the rest of the controllers to behave like a normal web application.</p>
  
  <p>Currently if I pass incorrect credentials to the controller I get an HTTP 302 response, when I'd really like a HTTP 401 to be passed back. How can I do this?</p>
  
  <p>*edited for typo</p>