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



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

i using oauth2-server-laravel bundle angularjs client. have implemented it's password method works fine requests. when seek $http.post on secure link. gives next error 401.

{"status":401,"error":"unauthorized","error_message":"access token missing"} this happening post request done angularjs. (i tried sending access_token both post parameter , http header.) when using chrome rest app postman works fine! when remove oauth filter route works fine in angular. so might problem oauth2-server-laravel bundle or angularjs

i have added code filters.php back upwards 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' ]; homecoming 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'); homecoming $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" }; // doesn't work $http.post(linkshare.host+'/link',postlinkdata).success(function(mydata){ console.log(mydata); });

the way passing parameter along post info not correct. parameters should part of config object in case:

// post parameters var postlinkdata = { title: "hello", url : "http://hello.world" }; // additional parameters var config = { params: {access_token: "mz44zawffs9ylrpg08sn8ivlmi0xkcd9bcrl2tny"} }; $http.post(linkshare.host+'/link', postlinkdata, config).success(function(mydata){ console.log(mydata); });

see documentation $http.post.

angularjs laravel oauth cors

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -