【发布时间】:2015-09-20 14:01:44
【问题描述】:
我在 Restify 上构建了一个简单的 node.js 后端,具有 OAuth2 授权(restify-oauth2 插件)。
我在请求令牌时遇到问题。当我使用 REST 客户端调用 POST 方法时,一切正常,我得到 access_token 和 token_type。
当我尝试在 Angular 中制作的前端应用程序中执行相同的操作时,就会出现问题。
这是我的代码:
var req = {
method: 'POST',
url: 'http://localhost:8080/token',
headers: headers,
data: {},
params: {grant_type: "client_credentials"}
};
$http(req).success(function(data, status, headers, config){
console.log('success');
}).error(function(data, status, headers, config){
console.log('error');
});
如您所见,提供了grant_type 参数。但服务器仍然响应:
{"error":"invalid_request","error_description":"Must specify grant_type field."}
这里是 devtools 截图:
我需要如何更改我的请求才能使其生效?
【问题讨论】:
标签: angularjs node.js oauth-2.0 restify