Q:

Angularjs $http.post gives 401 error response . Laravel with oauth2-server

I am using oauth2-server-laravel package with angularjs as client. I have implemented it's password method which works fine for GET requests.
When I try to do a $http.post on a secure link. It gives following error with 401.
{"status":401,"error":"unauthorized","error_message":"Access token is missing"}

This is happening only with POST request done with angularjs. (I tried sending access_token as both post parameter and Http header.)
When using chrome REST app postman it works fine!
When I remove oauth filter from route it works fine in angular. So this might be a problem with oauth2-server-laravel package or AngularJS

I have added this code to my filters.php to support CORS.
App::before(function($request)
{
    //

    if($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
        $statusCode = 204;

        $headers = [
            'Access-Control-Allow-Origin'      => 'http://localhost:8100',
            'Access-Control-Allow-Methods'     => 'GET, POST, OPTIONS',
            'Access-Control-Allow-Headers'     => 'Origin, Content-Type, Accept, Authorization, X-Requested-With',
            'Access-Control-Allow-Credentials' => 'true'
        ];

        return Response::make(null, $statusCode, $headers);
    }

}); 

App::after(function($request, $response)
{
    //

    $response->headers->set('Access-Control-Allow-Origin', 'http://localhost:8100');
    $response->headers->set('Access-Control-Allow-Methods', 'GET, POST, OPTIONS');
    $response->headers->set('Access-Control-Allow-Headers', 'Origin, Content-Type, Accept, Authorization, X-Requested-With');
    $response->headers->set('Access-Control-Allow-Credentials', 'true');
    return $response;

});

JS 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);
});

A:

The way you are passing GET parameter along with POST data is not correct. GET parameters should be a part of config object in this case:
// POST parameters
var postLinkdata =  {
    title: "Hello",
    url  : "http://hello.world"
};

// Additional GET parameters
var config = {
    params: {access_token: "Mz44ZaWffS9YlrPG08SN8ivLMI0xkCd9bcRL2tny"}
};

$http.post(linkshare.host+'/link', postLinkdata, config).success(function(mydata){
    console.log(mydata);
});

See documentation for $http.post.

