Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/445.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用节点和节点REST客户端发出Oauth2 REST请求?_Javascript_Node.js_Oauth_Node Rest Client - Fatal编程技术网

Javascript 如何使用节点和节点REST客户端发出Oauth2 REST请求?

Javascript 如何使用节点和节点REST客户端发出Oauth2 REST请求?,javascript,node.js,oauth,node-rest-client,Javascript,Node.js,Oauth,Node Rest Client,我试图从文档(,)中复制示例POST请求。如何在节点中对该curl请求进行编码 $ curl -u user:password localhost:8080/oauth/token -d grant_type=client_credentials {"access_token":"c6b53866-b38a-41f9-878c-87bb280ca9d8","token_type":"bearer","expires_in":43199,"scope":"write"} 我有这个 var oau

我试图从文档(,)中复制示例POST请求。如何在节点中对该
curl
请求进行编码

$ curl -u user:password localhost:8080/oauth/token -d grant_type=client_credentials
{"access_token":"c6b53866-b38a-41f9-878c-87bb280ca9d8","token_type":"bearer","expires_in":43199,"scope":"write"}
我有这个

var oauth = {
    data: { grant_type: "client_credentials" },
    headers: { "Content-Type": "application/json" }
};
var options_auth = { user: "user", password: "password" };
var client = new Client(options_auth);

client.post("http://127.0.0.1:8080/oauth/token", oauth, function (data, response) {
    // parsed response body as js object
    console.log(data);
但这给了我一个错误

[2019-10-15T00:40:23.780Z] { error: 'invalid_request', error_description: 'Missing grant type' }

OAuth服务器是Spring Boot,这是值得的。

我必须更改headers值:

    headers: { "Content-Type": "application/x-www-form-urlencoded" }
现在它给了我一个访问令牌:

[2019-10-15T00:58:15.354Z] {                           
  access_token: 'c6b53866-b38a-41f9-878c-87bb280ca9d8',
  token_type: 'bearer',                                
  expires_in: 41873,                                   
  scope: 'write'                                       
}