INVALID_REQUEST在Laravel + OAuth的angularjs [英] invalid_request in angularjs with Laravel + OAuth

查看:309
本文介绍了INVALID_REQUEST在Laravel + OAuth的angularjs的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建 REST风格的 API与 Laravel(后端) AngularJS(前端),我想实施的OAuth 来保护我的Laravel的API。

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

我在我的laravel装了的OAuth 但是当我呼吁从angularjs服务器发出请求,然后它给INVALID_REQUEST的错误。
这里是我的code:

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侧:

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

我得到这样的错误:

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?

谢谢....:)

推荐答案

最后我得到的解决方案,我刚刚加入 $。参数数据字段 AngularJS

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

这篇关于INVALID_REQUEST在Laravel + OAuth的angularjs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆