duanlongnao0028 2014-11-25 10:21
浏览 49
已采纳

带有Laravel + OAuth的angularjs中的invalid_request

I am creating RESTful API with Laravel (BackEnd) and AngularJS (Front End), I want to implement OAuth to secure my API of Laravel.

I've Installed a OAuth in my laravel but when i call a request on server from angularjs then it gives error of invalid_request. Here is my Code :

Laravel Side :

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

Angular Side :

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

I get Error like :

{
    "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."
}

What is the problem any ideas?

Thanks.... :)

  • 写回答

1条回答 默认 最新

  • dongqiao2077 2014-11-26 11:55
    关注

    Finally I got solution, I've just added $.param in data field 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);
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 esp8266控制共阳极wrgb灯板无法关闭所有led灯
  • ¥100 python读取速度问题
  • ¥15 stm32f407使用DMA问题
  • ¥15 您好 这个API接口该怎么弄 网站搭建好了 API也有 现在就不知道该怎么填写API 不知道怎么用
  • ¥88 用uniapp写一个多端的程序,用到高德地图,用高德的JSAPI吗?
  • ¥20 关于#c++#的问题:水果店管理系统
  • ¥30 dbLinq最新版linq sqlite
  • ¥20 对D盘进行分盘之前没有将visual studio2022卸载掉,现在该如何下载回来
  • ¥15 完成虚拟机环境配置,还有安装kettle
  • ¥15 2024年全国大学生数据分析大赛A题:直播带货与电商产品的大数据分析 问题5. 请设计一份优惠券的投放策略,需要考虑优惠券的数量、优惠券的金额、投放时间段和投放商品种类等因素。求具体的python代码