title: Yii RESTful authentication
body: <p>I am having trouble finding a method for authenticating API users in my application. I set out to initially build a system that users could access and authenticate through the web, but requirements have changed and I need to implement some additional actions that can be available in a RESTful manner using a POST API call.</p>
  
  <p>I have created a class that extends <code>CBehaviour</code> and forced a redirect to the login page for all unauthenticated users (<a href="http://www.yiiframework.com/forum/index.php/topic/23438-redirect-to-login-for-guest-users-in-every-controller/" rel="nofollow">found on the yii framework forum here</a>). Problem is that all API calls are forced through the same logic and any POST requests simply spit out the HTML to the login page.</p>
  
  <pre><code>class ApplicationBehavior extends CBehavior {
      private $_owner;
  
      public function events() {
          return array(
              'onBeginRequest' =&gt; 'forceGuestLogin',
          );
      }
  
      public function forceGuestLogin() {
          $owner = $this-&gt;getOwner();
          if ($owner-&gt;user-&gt;getIsGuest())
              $owner-&gt;catchAllRequest = array("site/login");
      }
  }
  </code></pre>
  
  <p>How would I go about separating the authentication of API users from the Web users?</p>