title: Angularjs $http.post gives 401 error response . Laravel with oauth2-server
body: <p>I am using <a href="https://github.com/lucadegasperi/oauth2-server-laravel" rel="nofollow">oauth2-server-laravel</a> package with <code>angularjs</code> as client. I have implemented it's password method which works fine for GET requests.
  When I try to do a <code>$http.post</code> on a secure link. It gives following error with 401.</p>
  
  <pre><code>{"status":401,"error":"unauthorized","error_message":"Access token is missing"}
  </code></pre>
  
  <ul>
  <li>This is happening only with <code>POST</code> request done with angularjs. (I tried sending access_token as both post parameter and Http header.)</li>
  <li>When using chrome REST app <code>postman</code> it works fine!</li>
  <li>When I remove <code>oauth</code> filter from <code>route</code> it works fine in angular. <strong>So this might be a problem with <a href="https://github.com/lucadegasperi/oauth2-server-laravel" rel="nofollow">oauth2-server-laravel</a> package or AngularJS</strong></li>
  </ul>
  
  <p>I have added this code to my <code>filters.php</code> to support CORS.</p>
  
  <pre><code>App::before(function($request)
  {
      //
  
      if($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
          $statusCode = 204;
  
          $headers = [
              'Access-Control-Allow-Origin'      =&gt; 'http://localhost:8100',
              'Access-Control-Allow-Methods'     =&gt; 'GET, POST, OPTIONS',
              'Access-Control-Allow-Headers'     =&gt; 'Origin, Content-Type, Accept, Authorization, X-Requested-With',
              'Access-Control-Allow-Credentials' =&gt; 'true'
          ];
  
          return Response::make(null, $statusCode, $headers);
      }
  
  }); 
  
  
  App::after(function($request, $response)
  {
      //
  
      $response-&gt;headers-&gt;set('Access-Control-Allow-Origin', 'http://localhost:8100');
      $response-&gt;headers-&gt;set('Access-Control-Allow-Methods', 'GET, POST, OPTIONS');
      $response-&gt;headers-&gt;set('Access-Control-Allow-Headers', 'Origin, Content-Type, Accept, Authorization, X-Requested-With');
      $response-&gt;headers-&gt;set('Access-Control-Allow-Credentials', 'true');
      return $response;
  
  });
  </code></pre>
  
  <p>JS code : </p>
  
  <pre><code>//this wprks 
  $http.get(linkshare.host+'/link?access_token=Mz44ZaWffS9YlrPG08SN8ivLMI0xkCd9bcRL2tny').success(function(data) {
      $scope.links = data.links ;
      localStorage.setItem("my-local-data", JSON.stringify(data));
  });
  
  var postLinkdata =  {
      "access_token"  : "Mz44ZaWffS9YlrPG08SN8ivLMI0xkCd9bcRL2tny",
      "title"         : "Hello",
      "url"           : "http://hello.world"
  };
  // this doesn't work 
  $http.post(linkshare.host+'/link',postLinkdata).success(function(mydata){
      console.log(mydata);
  });
  </code></pre>