![](/img/trans.png)
[英]Error fetching OAuth2 access token, message: 'invalid_request
[英]invalid_request in angularjs with Laravel + OAuth
我正在使用Laravel (BackEnd)
和AngularJS (Front End)
創建RESTful
API,我想實現OAuth
以保護我的Laravel API。
我已經在Laravel中安裝了OAuth
,但是當我從angularjs在服務器上調用請求時,它會給出invalid_request錯誤。 這是我的代碼:
Laravel Side:
Route::post('oauth/access_token', function() {
return Response::json(Authorizer::issueAccessToken());
});
角邊:
$http({
url: $url.siteUrl('oauth/access_token?grant_type=password&username=stafftest&password=password'),
method: "post",
headers: {'Content-Type': "application/x-www-form-urlencoded"},
}).then(function(response) {
console.log(response);
}, function(response) {
console.log(response);
});
我得到像這樣的錯誤:
{
"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."
}
什么想法有什么問題?
謝謝.... :)
終於有了解決方案,我剛剛在數據字段AngularJS
添加了$.param
AngularJS
:
$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);
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.