2014-11-25 92 views
0

我正在创建RESTful API,使用Laravel (BackEnd)AngularJS (Front End),我想实现OAuth以保护我的Laravel API。使用Laravel + OAuth在angularjs中invalid_request

我已经在我的laravel中安装了OAuth,但是当我从angularjs调用服务器上的请求时,它给出invalid_request的错误。 这里是我的代码:

Laravel方:

Route::post('oauth/access_token', function() { 
    return Response::json(Authorizer::issueAccessToken()); 
}); 

角边:

​​

我得到这样的错误:

{ 
    "error":"invalid_request", 
    "error_description":"The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed. Check the 'grant_type' parameter." 
} 

什么问题是什么想法?

感谢.... :)

回答

1

最后我得到了解决,我只是在数据字段AngularJS添加$.param

$http({ 
    url: $url.siteUrl('oauth/access_token'), 
    method: "post", 
    data: $.param({client_id:"1",client_secret:"12345",grant_type : 'password', username : 'johndoe', password : 'A3ddj3w'}), 
    headers: {'Content-Type': "application/x-www-form-urlencoded"}, 
}).then(function(response) { 
    console.log(response); 
}, function(response) { 
    console.log(response); 
}); 
+0

即使我是有这个问题......我试过相同...但控制台告诉我$ url不是未定义的...所以我删除了完整的$ url.siteUrl(就像这个URL:'oauth/access_token')...然后我得到另一个错误告诉我$没有定义指向$后的数据:...我现在应该做什么...? – Vagabond 2015-01-08 14:18:23

+0

您是否在头部定义了jquery? – Arjun 2015-01-09 11:58:25

+0

另一件事是$ url.siteUrl是我的自定义函数,它不是由angularjs提供的功能。 – Arjun 2015-01-09 11:59:23