我正在尝试连接以从nodejs中的Box api获取令牌。我通过第一级授权并获得auth代码,我的回调网址被调用。但是,当我尝试获取令牌时,我收到错误。下面是我的回调代码,
app.get('/auth/box', function(req, res){
var client_id = oauthSecrets.box.clientId;
console.log('clientid:'+client_id)
var provider = 'box';
var redirect_uri = 'http://localhost:3000/auth/box/callback';
var boxAuthUrl = 'https://www.box.com/api/oauth2/authorize?response_type=code&client_id='
+ client_id + '&state=authenticated&redirect_uri='+ redirect_uri;
console.log('boxAuthUrl:'+boxAuthUrl);
res.redirect(boxAuthUrl);
});
var authCode = '';
var clientId = oauthSecrets.box.clientId;
var clientSecret = oauthSecrets.box.clientSecret;
app.get('/auth/:provider/callback', function(req, res){
console.log('box callback return');
authCode = res.req.query.code;
console.log('authCode:'+authCode);
var oauthPath = '/api/oauth2/token';
var data = ' -d ' +
'\'grant_type=authorization_code&code=' + authCode +
'&client_id=' + clientId +
'&client_secret=' + clientSecret + '\'';
oauthPath = oauthPath + data;
console.log('oauth path:' + oauthPath);
// the post options
var optionspost = {
host : 'https://www.box.com/',
path : oauthPath,
method : 'POST'
};
var reqPost = http.request(optionspost, function(res2) {
console.log("statusCode: ", res2.statusCode);
res2.on('data', function(d) {
console.info('POST result:\n');
process.stdout.write(d);
console.info('\n\nPOST completed');
});
});
reqPost.end();
reqPost.on('error', function(e) {
console.error('=====Error:'+e);
console.error('=====Error:'+e.stack);
});
});
我在这里reqPost.on('error', function(e)
收到套接字重置错误。
代码中的任何错误或建议请。
编辑:错误消息
=====Error:Error: read ECONNRESET
=====Error:Error: read ECONNRESET
at errnoException (net.js:901:11)
at TCP.onread (net.js:556:19)